You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ed...@apache.org on 2013/02/21 20:15:16 UTC
[32/45] squash changes into one giant patch
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreProvider.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreProvider.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreProvider.java
new file mode 100644
index 0000000..d29c482
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreProvider.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.engine.subsystem.api.storage;
+
+import java.util.Map;
+
+
+public interface DataStoreProvider {
+ public DataStoreLifeCycle getLifeCycle();
+ public String getName();
+ public String getUuid();
+ public long getId();
+ public boolean configure(Map<String, Object> params);
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreProviderManager.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreProviderManager.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreProviderManager.java
new file mode 100644
index 0000000..9499813
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreProviderManager.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.engine.subsystem.api.storage;
+
+import java.util.List;
+
+import com.cloud.utils.component.Manager;
+
+public interface DataStoreProviderManager extends Manager {
+ public DataStoreProvider getDataStoreProviderByUuid(String uuid);
+ public DataStoreProvider getDataStoreProviderById(long id);
+ public DataStoreProvider getDataStoreProvider(String name);
+ public DataStoreProvider getDefaultPrimaryDataStoreProvider();
+ public List<DataStoreProvider> getDataStoreProviders();
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreStatus.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreStatus.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreStatus.java
new file mode 100644
index 0000000..2388795
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/DataStoreStatus.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.engine.subsystem.api.storage;
+
+public enum DataStoreStatus {
+ Initial, Initialized, Creating, Attaching, Up, PrepareForMaintenance, ErrorInMaintenance, CancelMaintenance, Maintenance, Removed;
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/HypervisorHostListener.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/HypervisorHostListener.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/HypervisorHostListener.java
new file mode 100644
index 0000000..3ac1759
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/HypervisorHostListener.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.engine.subsystem.api.storage;
+
+public interface HypervisorHostListener {
+ boolean hostConnect(long hostId, long poolId);
+ boolean hostDisconnected(long hostId, long poolId);
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ImageDataFactory.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ImageDataFactory.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ImageDataFactory.java
new file mode 100644
index 0000000..f0d6988
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ImageDataFactory.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.engine.subsystem.api.storage;
+
+
+public interface ImageDataFactory {
+ TemplateInfo getTemplate(long templateId, DataStore store);
+ TemplateInfo getTemplate(DataObject obj, DataStore store);
+ TemplateInfo getTemplate(long templateId);
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ImageService.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ImageService.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ImageService.java
new file mode 100644
index 0000000..119f3b1
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ImageService.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.engine.subsystem.api.storage;
+
+import org.apache.cloudstack.framework.async.AsyncCallFuture;
+
+public interface ImageService {
+ AsyncCallFuture<CommandResult> createTemplateAsync(TemplateInfo template, DataStore store);
+ AsyncCallFuture<CommandResult> createTemplateFromSnapshotAsync(SnapshotInfo snapshot, TemplateInfo template, DataStore store);
+ AsyncCallFuture<CommandResult> createTemplateFromVolumeAsync(VolumeInfo volume, TemplateInfo template, DataStore store);
+ AsyncCallFuture<CommandResult> deleteTemplateAsync(TemplateInfo template);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ObjectInDataStoreStateMachine.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ObjectInDataStoreStateMachine.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ObjectInDataStoreStateMachine.java
new file mode 100644
index 0000000..af9974e
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/ObjectInDataStoreStateMachine.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.engine.subsystem.api.storage;
+
+import com.cloud.utils.fsm.StateObject;
+
+public interface ObjectInDataStoreStateMachine extends StateObject<ObjectInDataStoreStateMachine.State> {
+ enum State {
+ Allocated("The initial state"),
+ Creating2("This is only used with createOnlyRequested event"),
+ Creating("The object is being creating on data store"),
+ Created("The object is created"),
+ Ready("Template downloading is complished"),
+ Copying("The object is being coping"),
+ Destroying("Template is destroying"),
+ Destroyed("Template is destroyed"),
+ Failed("Failed to download template");
+ String _description;
+
+ private State(String description) {
+ _description = description;
+ }
+
+ public String getDescription() {
+ return _description;
+ }
+ }
+
+ enum Event {
+ CreateRequested,
+ CreateOnlyRequested,
+ DestroyRequested,
+ OperationSuccessed,
+ OperationFailed,
+ CopyingRequested,
+ ExpungeRequested
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreInfo.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreInfo.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreInfo.java
index ec87cb5..3497f7a 100644
--- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreInfo.java
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreInfo.java
@@ -19,21 +19,19 @@
package org.apache.cloudstack.engine.subsystem.api.storage;
-import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity;
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.DiskFormat;
+
import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.storage.Storage.StoragePoolType;
+import com.cloud.storage.StoragePool;
-public interface PrimaryDataStoreInfo {
+public interface PrimaryDataStoreInfo extends StoragePool {
public boolean isHypervisorSupported(HypervisorType hypervisor);
public boolean isLocalStorageSupported();
public boolean isVolumeDiskTypeSupported(DiskFormat diskType);
- public long getCapacity();
- public long getAvailableCapacity();
- public long getId();
public String getUuid();
- public DataCenterResourceEntity.State getManagedState();
- public String getName();
- public String getType();
+
+ public StoragePoolType getPoolType();
public PrimaryDataStoreLifeCycle getLifeCycle();
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotDataFactory.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotDataFactory.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotDataFactory.java
new file mode 100644
index 0000000..1ff3ff2
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotDataFactory.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.engine.subsystem.api.storage;
+
+
+public interface SnapshotDataFactory {
+ public SnapshotInfo getSnapshot(long snapshotId, DataStore store);
+ public SnapshotInfo getSnapshot(DataObject obj, DataStore store);
+ public SnapshotInfo getSnapshot(long snapshotId);
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotInfo.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotInfo.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotInfo.java
new file mode 100644
index 0000000..30cf182
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/SnapshotInfo.java
@@ -0,0 +1,24 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.engine.subsystem.api.storage;
+
+
+public interface SnapshotInfo extends DataObject {
+ public SnapshotInfo getParent();
+ public SnapshotInfo getChild();
+ public VolumeInfo getBaseVolume();
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateEvent.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateEvent.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateEvent.java
new file mode 100644
index 0000000..c677166
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateEvent.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.engine.subsystem.api.storage;
+
+public enum TemplateEvent {
+ CreateRequested,
+ OperationFailed,
+ OperationSucceeded,
+ DestroyRequested;
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateInfo.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateInfo.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateInfo.java
new file mode 100644
index 0000000..8e03503
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateInfo.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.engine.subsystem.api.storage;
+
+public interface TemplateInfo extends DataObject {
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateState.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateState.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateState.java
new file mode 100644
index 0000000..ef24880
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/TemplateState.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.engine.subsystem.api.storage;
+
+public enum TemplateState {
+ Allocated,
+ Creating,
+ Destroying,
+ Destroyed,
+ Ready;
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeDataFactory.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeDataFactory.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeDataFactory.java
new file mode 100644
index 0000000..1518fd2
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeDataFactory.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.engine.subsystem.api.storage;
+
+
+public interface VolumeDataFactory {
+ VolumeInfo getVolume(long volumeId, DataStore store);
+ VolumeInfo getVolume(DataObject volume, DataStore store);
+ VolumeInfo getVolume(long volumeId);
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeInfo.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeInfo.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeInfo.java
index bedb9e7..f2a3d5e 100644
--- a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeInfo.java
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeInfo.java
@@ -18,6 +18,10 @@
*/
package org.apache.cloudstack.engine.subsystem.api.storage;
-public interface VolumeInfo extends DataObject {
+import com.cloud.storage.Volume;
+
+public interface VolumeInfo extends DataObject, Volume {
public boolean isAttachedVM();
+ public void addPayload(Object data);
+ public Object getpayload();
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java
new file mode 100644
index 0000000..58258eb
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/VolumeService.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.engine.subsystem.api.storage;
+
+import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
+import org.apache.cloudstack.framework.async.AsyncCallFuture;
+
+import com.cloud.exception.ConcurrentOperationException;
+
+
+public interface VolumeService {
+
+ public class VolumeApiResult extends CommandResult {
+ private final VolumeInfo volume;
+ public VolumeApiResult(VolumeInfo volume) {
+ this.volume = volume;
+ }
+
+ public VolumeInfo getVolume() {
+ return this.volume;
+ }
+ }
+
+ /**
+ * Creates the volume based on the given criteria
+ *
+ * @param cmd
+ *
+ * @return the volume object
+ */
+ AsyncCallFuture<VolumeApiResult> createVolumeAsync(VolumeInfo volume, DataStore store);
+
+ /**
+ * Delete volume
+ *
+ * @param volumeId
+ * @return
+ * @throws ConcurrentOperationException
+ */
+ AsyncCallFuture<VolumeApiResult> expungeVolumeAsync(VolumeInfo volume);
+
+ /**
+ *
+ */
+ boolean cloneVolume(long volumeId, long baseVolId);
+
+ /**
+ *
+ */
+ AsyncCallFuture<VolumeApiResult> createVolumeFromSnapshot(VolumeInfo volume, DataStore store, SnapshotInfo snapshot);
+
+
+ VolumeEntity getVolumeEntity(long volumeId);
+
+ AsyncCallFuture<VolumeApiResult> createVolumeFromTemplateAsync(VolumeInfo volume, long dataStoreId, TemplateInfo template);
+ AsyncCallFuture<VolumeApiResult> copyVolume(VolumeInfo srcVolume, DataStore destStore);
+
+ boolean destroyVolume(long volumeId) throws ConcurrentOperationException;
+
+ AsyncCallFuture<VolumeApiResult> registerVolume(VolumeInfo volume, DataStore store);
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/api/src/org/apache/cloudstack/storage/datastore/db/DataStoreProviderDao.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/DataStoreProviderDao.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/DataStoreProviderDao.java
new file mode 100644
index 0000000..dca83ce
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/DataStoreProviderDao.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.storage.datastore.db;
+
+import com.cloud.utils.db.GenericDao;
+
+public interface DataStoreProviderDao extends GenericDao<DataStoreProviderVO, Long> {
+ public DataStoreProviderVO findByName(String name);
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/api/src/org/apache/cloudstack/storage/datastore/db/DataStoreProviderDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/DataStoreProviderDaoImpl.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/DataStoreProviderDaoImpl.java
new file mode 100644
index 0000000..ccb6b48
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/DataStoreProviderDaoImpl.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.storage.datastore.db;
+
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchCriteria2;
+import com.cloud.utils.db.SearchCriteriaService;
+import com.cloud.utils.db.SearchCriteria.Op;
+
+@Component
+class DataStoreProviderDaoImpl extends GenericDaoBase<DataStoreProviderVO, Long> implements DataStoreProviderDao {
+
+ @Override
+ public DataStoreProviderVO findByName(String name) {
+ SearchCriteriaService<DataStoreProviderVO, DataStoreProviderVO> sc = SearchCriteria2.create(DataStoreProviderVO.class);
+ sc.addAnd(sc.getEntity().getName(), Op.EQ, name);
+ return sc.find();
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/api/src/org/apache/cloudstack/storage/datastore/db/DataStoreProviderVO.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/DataStoreProviderVO.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/DataStoreProviderVO.java
new file mode 100644
index 0000000..dcdafdd
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/DataStoreProviderVO.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.storage.datastore.db;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.TableGenerator;
+
+@Entity
+@Table(name = "data_store_provider")
+public class DataStoreProviderVO {
+ @Id
+ @TableGenerator(name = "data_store_provider_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "data_store_provider_seq", allocationSize = 1)
+ @Column(name = "id", updatable = false, nullable = false)
+ private long id;
+
+ @Column(name = "name", nullable = false)
+ private String name;
+
+ @Column(name = "uuid", nullable = false)
+ private String uuid;
+
+ public long getId() {
+ return id;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setUuid(String uuid) {
+ this.uuid = uuid;
+ }
+
+ public String getUuid() {
+ return this.uuid;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java
new file mode 100644
index 0000000..1530ced
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDao.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.storage.datastore.db;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreStatus;
+
+import com.cloud.utils.db.GenericDao;
+
+public interface PrimaryDataStoreDao extends GenericDao<StoragePoolVO, Long> {
+
+ /**
+ * @param datacenterId
+ * -- the id of the datacenter (availability zone)
+ */
+ List<StoragePoolVO> listByDataCenterId(long datacenterId);
+
+ /**
+ * @param datacenterId
+ * -- the id of the datacenter (availability zone)
+ */
+ List<StoragePoolVO> listBy(long datacenterId, long podId, Long clusterId);
+
+ /**
+ * Set capacity of storage pool in bytes
+ *
+ * @param id
+ * pool id.
+ * @param capacity
+ * capacity in bytes
+ */
+ void updateCapacity(long id, long capacity);
+
+ /**
+ * Set available bytes of storage pool in bytes
+ *
+ * @param id
+ * pool id.
+ * @param available
+ * available capacity in bytes
+ */
+ void updateAvailable(long id, long available);
+
+ StoragePoolVO persist(StoragePoolVO pool, Map<String, String> details);
+
+ /**
+ * Find pool by name.
+ *
+ * @param name
+ * name of pool.
+ * @return the single StoragePoolVO
+ */
+ List<StoragePoolVO> findPoolByName(String name);
+
+ /**
+ * Find pools by the pod that matches the details.
+ *
+ * @param podId
+ * pod id to find the pools in.
+ * @param details
+ * details to match. All must match for the pool to be returned.
+ * @return List of StoragePoolVO
+ */
+ List<StoragePoolVO> findPoolsByDetails(long dcId, long podId, Long clusterId, Map<String, String> details);
+
+ List<StoragePoolVO> findPoolsByTags(long dcId, long podId, Long clusterId, String[] tags, Boolean shared);
+
+ /**
+ * Find pool by UUID.
+ *
+ * @param uuid
+ * uuid of pool.
+ * @return the single StoragePoolVO
+ */
+ StoragePoolVO findPoolByUUID(String uuid);
+
+ List<StoragePoolVO> listByStorageHost(String hostFqdnOrIp);
+
+ StoragePoolVO findPoolByHostPath(long dcId, Long podId, String host, String path, String uuid);
+
+ List<StoragePoolVO> listPoolByHostPath(String host, String path);
+
+ void updateDetails(long poolId, Map<String, String> details);
+
+ Map<String, String> getDetails(long poolId);
+
+ List<String> searchForStoragePoolDetails(long poolId, String value);
+
+ List<StoragePoolVO> findIfDuplicatePoolsExistByUUID(String uuid);
+
+ List<StoragePoolVO> listByStatus(DataStoreStatus status);
+
+ long countPoolsByStatus(DataStoreStatus... statuses);
+
+ List<StoragePoolVO> listByStatusInZone(long dcId, DataStoreStatus status);
+
+ List<StoragePoolVO> listPoolsByCluster(long clusterId);
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java
new file mode 100644
index 0000000..023b42b
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDaoImpl.java
@@ -0,0 +1,360 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cloudstack.storage.datastore.db;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.inject.Inject;
+import javax.naming.ConfigurationException;
+
+import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreStatus;
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.DB;
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.GenericSearchBuilder;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.SearchCriteria.Func;
+import com.cloud.utils.db.SearchCriteria.Op;
+import com.cloud.utils.db.Transaction;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+@Component
+public class PrimaryDataStoreDaoImpl extends GenericDaoBase<StoragePoolVO, Long> implements PrimaryDataStoreDao {
+ protected final SearchBuilder<StoragePoolVO> AllFieldSearch;
+ protected final SearchBuilder<StoragePoolVO> DcPodSearch;
+ protected final SearchBuilder<StoragePoolVO> DcPodAnyClusterSearch;
+ protected final SearchBuilder<StoragePoolVO> DeleteLvmSearch;
+ protected final GenericSearchBuilder<StoragePoolVO, Long> StatusCountSearch;
+
+ @Inject protected PrimaryDataStoreDetailsDao _detailsDao;
+
+ private final String DetailsSqlPrefix = "SELECT storage_pool.* from storage_pool LEFT JOIN storage_pool_details ON storage_pool.id = storage_pool_details.pool_id WHERE storage_pool.removed is null and storage_pool.data_center_id = ? and (storage_pool.pod_id = ? or storage_pool.pod_id is null) and (";
+ private final String DetailsSqlSuffix = ") GROUP BY storage_pool_details.pool_id HAVING COUNT(storage_pool_details.name) >= ?";
+ private final String FindPoolTagDetails = "SELECT storage_pool_details.name FROM storage_pool_details WHERE pool_id = ? and value = ?";
+
+ public PrimaryDataStoreDaoImpl() {
+ AllFieldSearch = createSearchBuilder();
+ AllFieldSearch.and("name", AllFieldSearch.entity().getName(), SearchCriteria.Op.EQ);
+ AllFieldSearch.and("uuid", AllFieldSearch.entity().getUuid(), SearchCriteria.Op.EQ);
+ AllFieldSearch.and("datacenterId", AllFieldSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+ AllFieldSearch.and("hostAddress", AllFieldSearch.entity().getHostAddress(), SearchCriteria.Op.EQ);
+ AllFieldSearch.and("status", AllFieldSearch.entity().getStatus(), SearchCriteria.Op.EQ);
+ AllFieldSearch.and("path", AllFieldSearch.entity().getPath(), SearchCriteria.Op.EQ);
+ AllFieldSearch.and("podId", AllFieldSearch.entity().getPodId(), Op.EQ);
+ AllFieldSearch.and("clusterId", AllFieldSearch.entity().getClusterId(), Op.EQ);
+ AllFieldSearch.done();
+
+ DcPodSearch = createSearchBuilder();
+ DcPodSearch.and("datacenterId", DcPodSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+ DcPodSearch.and().op("nullpod", DcPodSearch.entity().getPodId(), SearchCriteria.Op.NULL);
+ DcPodSearch.or("podId", DcPodSearch.entity().getPodId(), SearchCriteria.Op.EQ);
+ DcPodSearch.cp();
+ DcPodSearch.and().op("nullcluster", DcPodSearch.entity().getClusterId(), SearchCriteria.Op.NULL);
+ DcPodSearch.or("cluster", DcPodSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
+ DcPodSearch.cp();
+ DcPodSearch.done();
+
+ DcPodAnyClusterSearch = createSearchBuilder();
+ DcPodAnyClusterSearch.and("datacenterId", DcPodAnyClusterSearch.entity().getDataCenterId(), SearchCriteria.Op.EQ);
+ DcPodAnyClusterSearch.and().op("nullpod", DcPodAnyClusterSearch.entity().getPodId(), SearchCriteria.Op.NULL);
+ DcPodAnyClusterSearch.or("podId", DcPodAnyClusterSearch.entity().getPodId(), SearchCriteria.Op.EQ);
+ DcPodAnyClusterSearch.cp();
+ DcPodAnyClusterSearch.done();
+
+ DeleteLvmSearch = createSearchBuilder();
+ DeleteLvmSearch.and("ids", DeleteLvmSearch.entity().getId(), SearchCriteria.Op.IN);
+ DeleteLvmSearch.and().op("LVM", DeleteLvmSearch.entity().getPoolType(), SearchCriteria.Op.EQ);
+ DeleteLvmSearch.or("Filesystem", DeleteLvmSearch.entity().getPoolType(), SearchCriteria.Op.EQ);
+ DeleteLvmSearch.cp();
+ DeleteLvmSearch.done();
+
+ StatusCountSearch = createSearchBuilder(Long.class);
+ StatusCountSearch.and("status", StatusCountSearch.entity().getStatus(), SearchCriteria.Op.IN);
+ StatusCountSearch.select(null, Func.COUNT, null);
+ StatusCountSearch.done();
+ }
+
+ @Override
+ public List<StoragePoolVO> findPoolByName(String name) {
+ SearchCriteria<StoragePoolVO> sc = AllFieldSearch.create();
+ sc.setParameters("name", name);
+ return listIncludingRemovedBy(sc);
+ }
+
+ @Override
+ public StoragePoolVO findPoolByUUID(String uuid) {
+ SearchCriteria<StoragePoolVO> sc = AllFieldSearch.create();
+ sc.setParameters("uuid", uuid);
+ return findOneIncludingRemovedBy(sc);
+ }
+
+ @Override
+ public List<StoragePoolVO> findIfDuplicatePoolsExistByUUID(String uuid) {
+ SearchCriteria<StoragePoolVO> sc = AllFieldSearch.create();
+ sc.setParameters("uuid", uuid);
+ return listBy(sc);
+ }
+
+ @Override
+ public List<StoragePoolVO> listByDataCenterId(long datacenterId) {
+ SearchCriteria<StoragePoolVO> sc = AllFieldSearch.create();
+ sc.setParameters("datacenterId", datacenterId);
+ return listBy(sc);
+ }
+
+ @Override
+ public void updateAvailable(long id, long available) {
+ StoragePoolVO pool = createForUpdate(id);
+ pool.setAvailableBytes(available);
+ update(id, pool);
+ }
+
+ @Override
+ public void updateCapacity(long id, long capacity) {
+ StoragePoolVO pool = createForUpdate(id);
+ pool.setCapacityBytes(capacity);
+ update(id, pool);
+
+ }
+
+ @Override
+ public List<StoragePoolVO> listByStorageHost(String hostFqdnOrIp) {
+ SearchCriteria<StoragePoolVO> sc = AllFieldSearch.create();
+ sc.setParameters("hostAddress", hostFqdnOrIp);
+ return listIncludingRemovedBy(sc);
+ }
+
+ @Override
+ public List<StoragePoolVO> listByStatus(DataStoreStatus status) {
+ SearchCriteria<StoragePoolVO> sc = AllFieldSearch.create();
+ sc.setParameters("status", status);
+ return listBy(sc);
+ }
+
+ @Override
+ public List<StoragePoolVO> listByStatusInZone(long dcId, DataStoreStatus status) {
+ SearchCriteria<StoragePoolVO> sc = AllFieldSearch.create();
+ sc.setParameters("status", status);
+ sc.setParameters("datacenterId", dcId);
+ return listBy(sc);
+ }
+
+ @Override
+ public StoragePoolVO findPoolByHostPath(long datacenterId, Long podId, String host, String path, String uuid) {
+ SearchCriteria<StoragePoolVO> sc = AllFieldSearch.create();
+ sc.setParameters("hostAddress", host);
+ sc.setParameters("path", path);
+ sc.setParameters("datacenterId", datacenterId);
+ sc.setParameters("podId", podId);
+ sc.setParameters("uuid", uuid);
+
+ return findOneBy(sc);
+ }
+
+ @Override
+ public List<StoragePoolVO> listBy(long datacenterId, long podId, Long clusterId) {
+ if (clusterId != null) {
+ SearchCriteria<StoragePoolVO> sc = DcPodSearch.create();
+ sc.setParameters("datacenterId", datacenterId);
+ sc.setParameters("podId", podId);
+
+ sc.setParameters("cluster", clusterId);
+ return listBy(sc);
+ } else {
+ SearchCriteria<StoragePoolVO> sc = DcPodAnyClusterSearch.create();
+ sc.setParameters("datacenterId", datacenterId);
+ sc.setParameters("podId", podId);
+ return listBy(sc);
+ }
+ }
+
+ @Override
+ public List<StoragePoolVO> listPoolByHostPath(String host, String path) {
+ SearchCriteria<StoragePoolVO> sc = AllFieldSearch.create();
+ sc.setParameters("hostAddress", host);
+ sc.setParameters("path", path);
+
+ return listBy(sc);
+ }
+
+ public StoragePoolVO listById(Integer id) {
+ SearchCriteria<StoragePoolVO> sc = AllFieldSearch.create();
+ sc.setParameters("id", id);
+
+ return findOneIncludingRemovedBy(sc);
+ }
+
+ @Override
+ @DB
+ public StoragePoolVO persist(StoragePoolVO pool, Map<String, String> details) {
+ Transaction txn = Transaction.currentTxn();
+ txn.start();
+ pool = super.persist(pool);
+ if (details != null) {
+ for (Map.Entry<String, String> detail : details.entrySet()) {
+ PrimaryDataStoreDetailVO vo = new PrimaryDataStoreDetailVO(pool.getId(), detail.getKey(), detail.getValue());
+ _detailsDao.persist(vo);
+ }
+ }
+ txn.commit();
+ return pool;
+ }
+
+ @DB
+ @Override
+ public List<StoragePoolVO> findPoolsByDetails(long dcId, long podId, Long clusterId, Map<String, String> details) {
+ StringBuilder sql = new StringBuilder(DetailsSqlPrefix);
+ if (clusterId != null) {
+ sql.append("storage_pool.cluster_id = ? OR storage_pool.cluster_id IS NULL) AND (");
+ }
+ for (Map.Entry<String, String> detail : details.entrySet()) {
+ sql.append("((storage_pool_details.name='").append(detail.getKey()).append("') AND (storage_pool_details.value='").append(detail.getValue()).append("')) OR ");
+ }
+ sql.delete(sql.length() - 4, sql.length());
+ sql.append(DetailsSqlSuffix);
+ Transaction txn = Transaction.currentTxn();
+ PreparedStatement pstmt = null;
+ try {
+ pstmt = txn.prepareAutoCloseStatement(sql.toString());
+ int i = 1;
+ pstmt.setLong(i++, dcId);
+ pstmt.setLong(i++, podId);
+ if (clusterId != null) {
+ pstmt.setLong(i++, clusterId);
+ }
+ pstmt.setInt(i++, details.size());
+ ResultSet rs = pstmt.executeQuery();
+ List<StoragePoolVO> pools = new ArrayList<StoragePoolVO>();
+ while (rs.next()) {
+ pools.add(toEntityBean(rs, false));
+ }
+ return pools;
+ } catch (SQLException e) {
+ throw new CloudRuntimeException("Unable to execute " + pstmt, e);
+ }
+ }
+
+ protected Map<String, String> tagsToDetails(String[] tags) {
+ Map<String, String> details = new HashMap<String, String>(tags.length);
+ for (String tag : tags) {
+ details.put(tag, "true");
+ }
+ return details;
+ }
+
+ @Override
+ public List<StoragePoolVO> findPoolsByTags(long dcId, long podId, Long clusterId, String[] tags, Boolean shared) {
+ List<StoragePoolVO> storagePools = null;
+ if (tags == null || tags.length == 0) {
+ storagePools = listBy(dcId, podId, clusterId);
+ } else {
+ Map<String, String> details = tagsToDetails(tags);
+ storagePools = findPoolsByDetails(dcId, podId, clusterId, details);
+ }
+
+ if (shared == null) {
+ return storagePools;
+ } else {
+ List<StoragePoolVO> filteredStoragePools = new ArrayList<StoragePoolVO>(storagePools);
+ for (StoragePoolVO pool : storagePools) {
+ /*
+ * if (shared != pool.isShared()) {
+ * filteredStoragePools.remove(pool); }
+ */
+ }
+
+ return filteredStoragePools;
+ }
+ }
+
+ @Override
+ @DB
+ public List<String> searchForStoragePoolDetails(long poolId, String value) {
+
+ StringBuilder sql = new StringBuilder(FindPoolTagDetails);
+
+ Transaction txn = Transaction.currentTxn();
+ PreparedStatement pstmt = null;
+ try {
+ pstmt = txn.prepareAutoCloseStatement(sql.toString());
+ pstmt.setLong(1, poolId);
+ pstmt.setString(2, value);
+
+ ResultSet rs = pstmt.executeQuery();
+ List<String> tags = new ArrayList<String>();
+
+ while (rs.next()) {
+ tags.add(rs.getString("name"));
+ }
+ return tags;
+ } catch (SQLException e) {
+ throw new CloudRuntimeException("Unable to execute " + pstmt.toString(), e);
+ }
+
+ }
+
+ @Override
+ public void updateDetails(long poolId, Map<String, String> details) {
+ if (details != null) {
+ _detailsDao.update(poolId, details);
+ }
+ }
+
+ @Override
+ public Map<String, String> getDetails(long poolId) {
+ return _detailsDao.getDetails(poolId);
+ }
+
+ @Override
+ public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+ super.configure(name, params);
+ _detailsDao.configure("DetailsDao", params);
+ return true;
+ }
+
+ @Override
+ public long countPoolsByStatus(DataStoreStatus... statuses) {
+ SearchCriteria<Long> sc = StatusCountSearch.create();
+
+ sc.setParameters("status", (Object[]) statuses);
+
+ List<Long> rs = customSearchIncludingRemoved(sc, null);
+ if (rs.size() == 0) {
+ return 0;
+ }
+
+ return rs.get(0);
+ }
+
+ @Override
+ public List<StoragePoolVO> listPoolsByCluster(long clusterId) {
+ SearchCriteria<StoragePoolVO> sc = AllFieldSearch.create();
+ sc.setParameters("clusterId", clusterId);
+
+ return listBy(sc);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDetailVO.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDetailVO.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDetailVO.java
new file mode 100644
index 0000000..d1f802d
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDetailVO.java
@@ -0,0 +1,79 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.storage.datastore.db;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="storage_pool_details")
+public class PrimaryDataStoreDetailVO {
+ @Id
+ @GeneratedValue(strategy=GenerationType.IDENTITY)
+ @Column(name="id")
+ long id;
+
+ @Column(name="pool_id")
+ long poolId;
+
+ @Column(name="name")
+ String name;
+
+ @Column(name="value")
+ String value;
+
+ public PrimaryDataStoreDetailVO(long poolId, String name, String value) {
+ this.poolId = poolId;
+ this.name = name;
+ this.value = value;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public long getPoolId() {
+ return poolId;
+ }
+
+ public void setPoolId(long poolId) {
+ this.poolId = poolId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ protected PrimaryDataStoreDetailVO() {
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDetailsDao.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDetailsDao.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDetailsDao.java
new file mode 100644
index 0000000..c2b109a
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDetailsDao.java
@@ -0,0 +1,27 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.storage.datastore.db;
+
+import java.util.Map;
+
+import com.cloud.utils.db.GenericDao;
+
+public interface PrimaryDataStoreDetailsDao extends GenericDao<PrimaryDataStoreDetailVO, Long> {
+
+ void update(long poolId, Map<String, String> details);
+ Map<String, String> getDetails(long poolId);
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDetailsDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDetailsDaoImpl.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDetailsDaoImpl.java
new file mode 100644
index 0000000..59c488c
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/PrimaryDataStoreDetailsDaoImpl.java
@@ -0,0 +1,71 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.storage.datastore.db;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.springframework.stereotype.Component;
+
+import com.cloud.utils.db.GenericDaoBase;
+import com.cloud.utils.db.SearchBuilder;
+import com.cloud.utils.db.SearchCriteria;
+import com.cloud.utils.db.Transaction;
+
+@Component
+public class PrimaryDataStoreDetailsDaoImpl extends GenericDaoBase<PrimaryDataStoreDetailVO, Long> implements PrimaryDataStoreDetailsDao {
+
+ protected final SearchBuilder<PrimaryDataStoreDetailVO> PoolSearch = null;
+
+ protected PrimaryDataStoreDetailsDaoImpl() {
+ /*
+ super();
+ PoolSearch = createSearchBuilder();
+ PoolSearch.and("pool", PoolSearch.entity().getPoolId(), SearchCriteria.Op.EQ);
+ PoolSearch.done();
+ */
+ }
+
+ @Override
+ public void update(long poolId, Map<String, String> details) {
+ Transaction txn = Transaction.currentTxn();
+ SearchCriteria<PrimaryDataStoreDetailVO> sc = PoolSearch.create();
+ sc.setParameters("pool", poolId);
+
+ txn.start();
+ expunge(sc);
+ for (Map.Entry<String, String> entry : details.entrySet()) {
+ PrimaryDataStoreDetailVO detail = new PrimaryDataStoreDetailVO(poolId, entry.getKey(), entry.getValue());
+ persist(detail);
+ }
+ txn.commit();
+ }
+
+ @Override
+ public Map<String, String> getDetails(long poolId) {
+ SearchCriteria<PrimaryDataStoreDetailVO> sc = PoolSearch.create();
+ sc.setParameters("pool", poolId);
+
+ List<PrimaryDataStoreDetailVO> details = listBy(sc);
+ Map<String, String> detailsMap = new HashMap<String, String>();
+ for (PrimaryDataStoreDetailVO detail : details) {
+ detailsMap.put(detail.getName(), detail.getValue());
+ }
+
+ return detailsMap;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/api/src/org/apache/cloudstack/storage/datastore/db/StoragePoolVO.java
----------------------------------------------------------------------
diff --git a/engine/api/src/org/apache/cloudstack/storage/datastore/db/StoragePoolVO.java b/engine/api/src/org/apache/cloudstack/storage/datastore/db/StoragePoolVO.java
new file mode 100644
index 0000000..1782f16
--- /dev/null
+++ b/engine/api/src/org/apache/cloudstack/storage/datastore/db/StoragePoolVO.java
@@ -0,0 +1,304 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.storage.datastore.db;
+
+import java.util.Date;
+import java.util.UUID;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.Id;
+import javax.persistence.Table;
+import javax.persistence.TableGenerator;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+import org.apache.cloudstack.engine.subsystem.api.storage.ScopeType;
+
+import com.cloud.storage.Storage.StoragePoolType;
+import com.cloud.storage.StoragePoolStatus;
+import com.cloud.utils.db.GenericDao;
+
+@Entity
+@Table(name="storage_pool")
+public class StoragePoolVO {
+ @Id
+ @TableGenerator(name = "storage_pool_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "storage_pool_seq", allocationSize = 1)
+ @Column(name = "id", updatable = false, nullable = false)
+ private long id;
+
+ @Column(name = "name", updatable = false, nullable = false, length = 255)
+ private String name = null;
+
+ @Column(name = "uuid", length = 255)
+ private String uuid = null;
+
+ @Column(name = "pool_type", updatable = false, nullable = false, length = 32)
+ @Enumerated(value = EnumType.STRING)
+ private StoragePoolType poolType;
+
+ @Column(name = GenericDao.CREATED_COLUMN)
+ Date created;
+
+ @Column(name = GenericDao.REMOVED_COLUMN)
+ private Date removed;
+
+ @Column(name = "update_time", updatable = true)
+ @Temporal(value = TemporalType.TIMESTAMP)
+ private Date updateTime;
+
+ @Column(name = "data_center_id", updatable = true, nullable = false)
+ private long dataCenterId;
+
+ @Column(name = "pod_id", updatable = true)
+ private Long podId;
+
+ @Column(name = "available_bytes", updatable = true, nullable = true)
+ private long availableBytes;
+
+ @Column(name = "capacity_bytes", updatable = true, nullable = true)
+ private long capacityBytes;
+
+ @Column(name = "status", updatable = true, nullable = false)
+ @Enumerated(value = EnumType.STRING)
+ private StoragePoolStatus status;
+
+ @Column(name = "storage_provider_id", updatable = true, nullable = false)
+ private Long storageProviderId;
+
+ @Column(name = "host_address")
+ private String hostAddress;
+
+ @Column(name = "path")
+ private String path;
+
+ @Column(name = "port")
+ private int port;
+
+ @Column(name = "user_info")
+ private String userInfo;
+
+ @Column(name = "cluster_id")
+ private Long clusterId;
+
+ @Column(name = "scope")
+ @Enumerated(value = EnumType.STRING)
+ private ScopeType scope;
+
+ public long getId() {
+ return id;
+ }
+
+ public StoragePoolStatus getStatus() {
+ return status;
+ }
+
+ public StoragePoolVO() {
+ this.status = StoragePoolStatus.Initial;
+ }
+
+ public StoragePoolVO(long poolId, String name, String uuid, StoragePoolType type,
+ long dataCenterId, Long podId, long availableBytes, long capacityBytes, String hostAddress, int port, String hostPath) {
+ this.name = name;
+ this.id = poolId;
+ this.uuid = uuid;
+ this.poolType = type;
+ this.dataCenterId = dataCenterId;
+ this.availableBytes = availableBytes;
+ this.capacityBytes = capacityBytes;
+ this.hostAddress = hostAddress;
+ this.path = hostPath;
+ this.port = port;
+ this.podId = podId;
+ this.setStatus(StoragePoolStatus.Initial);
+ }
+
+ public StoragePoolVO(StoragePoolVO that) {
+ this(that.id, that.name, that.uuid, that.poolType, that.dataCenterId, that.podId, that.availableBytes, that.capacityBytes, that.hostAddress, that.port, that.path);
+ }
+
+ public StoragePoolVO(StoragePoolType type, String hostAddress, int port, String path) {
+ this.poolType = type;
+ this.hostAddress = hostAddress;
+ this.port = port;
+ this.path = path;
+ this.setStatus(StoragePoolStatus.Initial);
+ this.uuid = UUID.randomUUID().toString();
+ }
+
+
+ public String getName() {
+ return name;
+ }
+
+ public String getUuid() {
+ return uuid;
+ }
+
+ public StoragePoolType getPoolType() {
+ return poolType;
+ }
+
+ public void setPoolType(StoragePoolType protocol) {
+ this.poolType = protocol;
+ }
+
+ public Date getCreated() {
+ return created;
+ }
+
+ public Date getRemoved() {
+ return removed;
+ }
+
+ public Date getUpdateTime() {
+ return updateTime;
+ }
+
+ public long getDataCenterId() {
+ return dataCenterId;
+ }
+
+ public long getAvailableBytes() {
+ return availableBytes;
+ }
+
+ public Long getStorageProviderId() {
+ return storageProviderId;
+ }
+
+ public void setStorageProviderId(Long provider) {
+ storageProviderId = provider;
+ }
+
+ public long getCapacityBytes() {
+ return capacityBytes;
+ }
+
+ public void setAvailableBytes(long available) {
+ availableBytes = available;
+ }
+
+ public void setCapacityBytes(long capacity) {
+ capacityBytes = capacity;
+ }
+
+ public Long getClusterId() {
+ return clusterId;
+ }
+
+ public void setClusterId(Long clusterId) {
+ this.clusterId = clusterId;
+ }
+
+ public String getHostAddress() {
+ return hostAddress;
+ }
+
+ public void setHostAddress(String host) {
+ this.hostAddress = host;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public String getUserInfo() {
+ return userInfo;
+ }
+
+ public void setStatus(StoragePoolStatus status) {
+ this.status = status;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public void setDataCenterId(long dcId) {
+ this.dataCenterId = dcId;
+ }
+
+ public void setPodId(Long podId) {
+ this.podId = podId;
+ }
+
+ public void setUuid(String uuid) {
+ this.uuid = uuid;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public void setUserInfo(String userInfo) {
+ this.userInfo = userInfo;
+ }
+
+ public int getPort() {
+ return port;
+ }
+
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ public Long getPodId() {
+ return podId;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setScope(ScopeType scope) {
+ this.scope = scope;
+ }
+
+ public ScopeType getScope() {
+ return this.scope;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof StoragePoolVO) || obj == null) {
+ return false;
+ }
+ StoragePoolVO that = (StoragePoolVO) obj;
+ return this.id == that.id;
+ }
+
+ @Override
+ public int hashCode() {
+ return new Long(id).hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return new StringBuilder("Pool[").append(id).append("|").append(poolType).append("]").toString();
+ }
+
+ public boolean isShared() {
+ return this.scope == ScopeType.HOST ? false : true;
+ }
+
+ public boolean isLocal() {
+ return !isShared();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java
index b91a2ca..ee08cf3 100644
--- a/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java
+++ b/engine/orchestration/src/org/apache/cloudstack/engine/cloud/entity/api/VMEntityManagerImpl.java
@@ -20,7 +20,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.UUID;
import javax.inject.Inject;
@@ -28,6 +27,7 @@ import org.apache.cloudstack.engine.cloud.entity.api.db.VMEntityVO;
import org.apache.cloudstack.engine.cloud.entity.api.db.VMReservationVO;
import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMEntityDao;
import org.apache.cloudstack.engine.cloud.entity.api.db.dao.VMReservationDao;
+import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
import org.springframework.stereotype.Component;
import com.cloud.dc.DataCenter;
@@ -45,22 +45,18 @@ import com.cloud.exception.ResourceUnavailableException;
import com.cloud.network.dao.NetworkDao;
import com.cloud.org.Cluster;
import com.cloud.service.dao.ServiceOfferingDao;
-import com.cloud.storage.StoragePoolVO;
+import com.cloud.storage.StoragePool;
import com.cloud.storage.Volume;
import com.cloud.storage.VolumeVO;
import com.cloud.storage.dao.DiskOfferingDao;
import com.cloud.storage.dao.StoragePoolDao;
import com.cloud.storage.dao.VMTemplateDao;
import com.cloud.storage.dao.VolumeDao;
-import com.cloud.user.Account;
-import com.cloud.user.User;
import com.cloud.user.dao.AccountDao;
import com.cloud.user.dao.UserDao;
import com.cloud.utils.component.ComponentContext;
-import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.vm.VMInstanceVO;
import com.cloud.vm.VirtualMachineManager;
-import com.cloud.vm.VirtualMachineProfile;
import com.cloud.vm.VirtualMachineProfileImpl;
import com.cloud.vm.dao.VMInstanceDao;
@@ -104,6 +100,8 @@ public class VMEntityManagerImpl implements VMEntityManager {
@Inject
protected StoragePoolDao _storagePoolDao;
+ @Inject
+ DataStoreManager dataStoreMgr;
@Override
public VMEntityVO loadVirtualMachine(String vmId) {
@@ -134,7 +132,8 @@ public class VMEntityManagerImpl implements VMEntityManager {
List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vm.getId());
if(!vols.isEmpty()){
VolumeVO vol = vols.get(0);
- StoragePoolVO pool = _storagePoolDao.findById(vol.getPoolId());
+ StoragePool pool = (StoragePool)this.dataStoreMgr.getPrimaryDataStore(vol.getPoolId());
+
if (!pool.isInMaintenance()) {
long rootVolDcId = pool.getDataCenterId();
Long rootVolPodId = pool.getPodId();
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/storage/backup/src/org/apache/cloudstack/storage/backup/BackupService.java
----------------------------------------------------------------------
diff --git a/engine/storage/backup/src/org/apache/cloudstack/storage/backup/BackupService.java b/engine/storage/backup/src/org/apache/cloudstack/storage/backup/BackupService.java
index e4cb0c7..67924d2 100644
--- a/engine/storage/backup/src/org/apache/cloudstack/storage/backup/BackupService.java
+++ b/engine/storage/backup/src/org/apache/cloudstack/storage/backup/BackupService.java
@@ -18,7 +18,7 @@
*/
package org.apache.cloudstack.storage.backup;
-import org.apache.cloudstack.storage.snapshot.SnapshotInfo;
+import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
public interface BackupService {
public boolean backupSnapshot(SnapshotInfo snapshot, long backupStoreId);
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/storage/image/src/org/apache/cloudstack/storage/image/ImageDataFactoryImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/ImageDataFactoryImpl.java b/engine/storage/image/src/org/apache/cloudstack/storage/image/ImageDataFactoryImpl.java
index b6a45b5..616e478 100644
--- a/engine/storage/image/src/org/apache/cloudstack/storage/image/ImageDataFactoryImpl.java
+++ b/engine/storage/image/src/org/apache/cloudstack/storage/image/ImageDataFactoryImpl.java
@@ -20,38 +20,74 @@ package org.apache.cloudstack.storage.image;
import javax.inject.Inject;
+import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
+import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectInStore;
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectType;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
-import org.apache.cloudstack.storage.datastore.DataStoreManager;
+import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
+import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreRole;
+import org.apache.cloudstack.engine.subsystem.api.storage.ImageDataFactory;
+import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
-import org.apache.cloudstack.storage.db.ObjectInDataStoreVO;
-import org.apache.cloudstack.storage.image.db.ImageDataDao;
-import org.apache.cloudstack.storage.image.db.ImageDataVO;
import org.apache.cloudstack.storage.image.store.TemplateObject;
+import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
+import com.cloud.storage.VMTemplateStoragePoolVO;
+import com.cloud.storage.VMTemplateVO;
+import com.cloud.storage.dao.VMTemplateDao;
+import com.cloud.storage.dao.VMTemplatePoolDao;
+
@Component
public class ImageDataFactoryImpl implements ImageDataFactory {
+ private static final Logger s_logger = Logger
+ .getLogger(ImageDataFactoryImpl.class);
@Inject
- ImageDataDao imageDataDao;
+ VMTemplateDao imageDataDao;
@Inject
ObjectInDataStoreManager objMap;
@Inject
DataStoreManager storeMgr;
+ @Inject
+ VMTemplatePoolDao templatePoolDao;
@Override
public TemplateInfo getTemplate(long templateId, DataStore store) {
- ImageDataVO templ = imageDataDao.findById(templateId);
+ VMTemplateVO templ = imageDataDao.findById(templateId);
if (store == null) {
TemplateObject tmpl = TemplateObject.getTemplate(templ, null);
return tmpl;
}
- ObjectInDataStoreVO obj = objMap.findObject(templateId, DataObjectType.TEMPLATE, store.getId(), store.getRole());
- if (obj == null) {
- TemplateObject tmpl = TemplateObject.getTemplate(templ, null);
- return tmpl;
+ boolean found = false;
+ if (store.getRole() == DataStoreRole.Primary) {
+ VMTemplateStoragePoolVO templatePoolVO = templatePoolDao.findByPoolTemplate(store.getId(), templateId);
+ if (templatePoolVO != null) {
+ found = true;
+ }
+ } else {
+ DataObjectInStore obj = objMap.findObject(templ.getUuid(), DataObjectType.TEMPLATE, store.getUuid(), store.getRole());
+ if (obj != null) {
+ found = true;
+ }
+ }
+
+ if (!found) {
+ s_logger.debug("template " + templateId + " is not in store:" + store.getId() + ", type:" + store.getRole());
}
TemplateObject tmpl = TemplateObject.getTemplate(templ, store);
return tmpl;
}
+ @Override
+ public TemplateInfo getTemplate(long templateId) {
+ VMTemplateVO templ = imageDataDao.findById(templateId);
+ if (templ.getImageDataStoreId() == null) {
+ return this.getTemplate(templateId, null);
+ }
+ DataStore store = this.storeMgr.getDataStore(templ.getImageDataStoreId(), DataStoreRole.Image);
+ return this.getTemplate(templateId, store);
+ }
+ @Override
+ public TemplateInfo getTemplate(DataObject obj, DataStore store) {
+ return this.getTemplate(obj.getId(), store);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/storage/image/src/org/apache/cloudstack/storage/image/ImageServiceImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/ImageServiceImpl.java b/engine/storage/image/src/org/apache/cloudstack/storage/image/ImageServiceImpl.java
index 82d0d71..5898b1b 100644
--- a/engine/storage/image/src/org/apache/cloudstack/storage/image/ImageServiceImpl.java
+++ b/engine/storage/image/src/org/apache/cloudstack/storage/image/ImageServiceImpl.java
@@ -22,15 +22,21 @@ import javax.inject.Inject;
import org.apache.cloudstack.engine.subsystem.api.storage.CommandResult;
import org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult;
+import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
+import org.apache.cloudstack.engine.subsystem.api.storage.ImageService;
+import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
+import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
+import org.apache.cloudstack.engine.subsystem.api.storage.TemplateEvent;
+import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
+import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
import org.apache.cloudstack.framework.async.AsyncCallFuture;
import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
import org.apache.cloudstack.framework.async.AsyncRpcConext;
+import org.apache.cloudstack.storage.datastore.DataObjectManager;
import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
-import org.apache.cloudstack.storage.db.ObjectInDataStoreVO;
import org.apache.cloudstack.storage.image.store.TemplateObject;
-import org.apache.cloudstack.storage.volume.ObjectInDataStoreStateMachine.Event;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
@@ -41,21 +47,25 @@ public class ImageServiceImpl implements ImageService {
private static final Logger s_logger = Logger.getLogger(ImageServiceImpl.class);
@Inject
ObjectInDataStoreManager objectInDataStoreMgr;
+ @Inject
+ DataObjectManager dataObjectMgr;
class CreateTemplateContext<T> extends AsyncRpcConext<T> {
final TemplateInfo srcTemplate;
- final TemplateInfo templateOnStore;
+ final DataStore store;
final AsyncCallFuture<CommandResult> future;
- final ObjectInDataStoreVO obj;
+ final DataObject templateOnStore;
+
public CreateTemplateContext(AsyncCompletionCallback<T> callback, TemplateInfo srcTemplate,
- TemplateInfo templateOnStore,
AsyncCallFuture<CommandResult> future,
- ObjectInDataStoreVO obj) {
+ DataStore store,
+ DataObject templateOnStore
+ ) {
super(callback);
this.srcTemplate = srcTemplate;
- this.templateOnStore = templateOnStore;
this.future = future;
- this.obj = obj;
+ this.store = store;
+ this.templateOnStore = templateOnStore;
}
}
@@ -74,31 +84,15 @@ public class ImageServiceImpl implements ImageService {
return future;
}
- ObjectInDataStoreVO obj = objectInDataStoreMgr.findObject(template.getId(), template.getType(), store.getId(), store.getRole());
- TemplateInfo templateOnStore = null;
- if (obj == null) {
- templateOnStore = (TemplateInfo)objectInDataStoreMgr.create(template, store);
- obj = objectInDataStoreMgr.findObject(template.getId(), template.getType(), store.getId(), store.getRole());
- } else {
- CommandResult result = new CommandResult();
- result.setResult("duplicate template on the storage");
- future.complete(result);
- return future;
- }
+ DataObject templateOnStore = store.create(template);
+ templateOnStore.processEvent(ObjectInDataStoreStateMachine.Event.CreateOnlyRequested);
- try {
- objectInDataStoreMgr.update(obj, Event.CreateOnlyRequested);
- } catch (NoTransitionException e) {
- s_logger.debug("failed to transit", e);
- CommandResult result = new CommandResult();
- result.setResult(e.toString());
- future.complete(result);
- return future;
- }
CreateTemplateContext<CommandResult> context = new CreateTemplateContext<CommandResult>(null,
- template, templateOnStore,
+ template,
future,
- obj);
+ store,
+ templateOnStore
+ );
AsyncCallbackDispatcher<ImageServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().createTemplateCallback(null, null))
.setContext(context);
@@ -108,42 +102,25 @@ public class ImageServiceImpl implements ImageService {
protected Void createTemplateCallback(AsyncCallbackDispatcher<ImageServiceImpl, CreateCmdResult> callback,
CreateTemplateContext<CreateCmdResult> context) {
-
- TemplateInfo templateOnStore = context.templateOnStore;
TemplateObject template = (TemplateObject)context.srcTemplate;
AsyncCallFuture<CommandResult> future = context.future;
CommandResult result = new CommandResult();
-
+ DataObject templateOnStore = context.templateOnStore;
CreateCmdResult callbackResult = callback.getResult();
if (callbackResult.isFailed()) {
try {
- objectInDataStoreMgr.update(templateOnStore, Event.OperationFailed);
+ templateOnStore.processEvent(ObjectInDataStoreStateMachine.Event.OperationFailed);
+ template.stateTransit(TemplateEvent.OperationFailed);
} catch (NoTransitionException e) {
- s_logger.debug("failed to transit state", e);
+ s_logger.debug("Failed to update template state", e);
}
result.setResult(callbackResult.getResult());
future.complete(result);
return null;
}
- ObjectInDataStoreVO obj = objectInDataStoreMgr.findObject(templateOnStore.getId(), templateOnStore.getType(), templateOnStore.getDataStore().getId(), templateOnStore.getDataStore().getRole());
- obj.setInstallPath(callbackResult.getPath());
-
- if (callbackResult.getSize() != null) {
- obj.setSize(callbackResult.getSize());
- }
try {
- objectInDataStoreMgr.update(obj, Event.OperationSuccessed);
- } catch (NoTransitionException e) {
- s_logger.debug("Failed to transit state", e);
- result.setResult(e.toString());
- future.complete(result);
- return null;
- }
-
- template.setImageStoreId(templateOnStore.getDataStore().getId());
- template.setSize(callbackResult.getSize());
- try {
+ templateOnStore.processEvent(ObjectInDataStoreStateMachine.Event.OperationSuccessed);
template.stateTransit(TemplateEvent.OperationSucceeded);
} catch (NoTransitionException e) {
s_logger.debug("Failed to transit state", e);
@@ -162,4 +139,18 @@ public class ImageServiceImpl implements ImageService {
// TODO Auto-generated method stub
return null;
}
+
+ @Override
+ public AsyncCallFuture<CommandResult> createTemplateFromSnapshotAsync(
+ SnapshotInfo snapshot, TemplateInfo template, DataStore store) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public AsyncCallFuture<CommandResult> createTemplateFromVolumeAsync(
+ VolumeInfo volume, TemplateInfo template, DataStore store) {
+ // TODO Auto-generated method stub
+ return null;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/00df9727/engine/storage/image/src/org/apache/cloudstack/storage/image/downloader/ImageDownloader.java
----------------------------------------------------------------------
diff --git a/engine/storage/image/src/org/apache/cloudstack/storage/image/downloader/ImageDownloader.java b/engine/storage/image/src/org/apache/cloudstack/storage/image/downloader/ImageDownloader.java
index adb247a..af572d4 100644
--- a/engine/storage/image/src/org/apache/cloudstack/storage/image/downloader/ImageDownloader.java
+++ b/engine/storage/image/src/org/apache/cloudstack/storage/image/downloader/ImageDownloader.java
@@ -18,7 +18,7 @@
*/
package org.apache.cloudstack.storage.image.downloader;
-import org.apache.cloudstack.storage.image.TemplateInfo;
+import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
public interface ImageDownloader {
public void downloadImage(TemplateInfo template);