You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ah...@apache.org on 2012/11/05 18:23:42 UTC
[9/18] Added engine
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriver.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriver.java b/engine/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriver.java
new file mode 100644
index 0000000..1a45bd9
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriver.java
@@ -0,0 +1,28 @@
+/*
+ * 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.image.driver;
+
+import org.apache.cloudstack.storage.image.Template;
+
+public interface ImageDataStoreDriver {
+ boolean registerTemplate(Template template);
+ String grantAccess(long templateId, long endPointId);
+ boolean revokeAccess(long templateId, long endPointId);
+ boolean deleteTemplate(Template template);
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriverImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriverImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriverImpl.java
new file mode 100644
index 0000000..a88e669
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/driver/ImageDataStoreDriverImpl.java
@@ -0,0 +1,51 @@
+/*
+ * 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.image.driver;
+
+import org.apache.cloudstack.storage.image.Template;
+
+public class ImageDataStoreDriverImpl implements ImageDataStoreDriver {
+
+ @Override
+ public boolean registerTemplate(Template template) {
+ //TODO: check the availability of template
+ return true;
+ }
+
+ @Override
+ public String grantAccess(long templateId, long endPointId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean revokeAccess(long templateId, long endPointId) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean deleteTemplate(Template template) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/image/format/BAREMETAL.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/format/BAREMETAL.java b/engine/storage/src/org/apache/cloudstack/storage/image/format/BAREMETAL.java
new file mode 100644
index 0000000..c3de2f1
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/format/BAREMETAL.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.storage.image.format;
+
+import org.apache.cloudstack.storage.BaseType;
+import org.springframework.stereotype.Component;
+
+@Component
+public class BAREMETAL extends BaseType implements ImageFormat {
+ private final String type = "BAREMETAL";
+ @Override
+ public String toString() {
+ return type;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/image/format/ISO.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/format/ISO.java b/engine/storage/src/org/apache/cloudstack/storage/image/format/ISO.java
new file mode 100644
index 0000000..f27d16b
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/format/ISO.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.storage.image.format;
+
+import org.apache.cloudstack.storage.BaseType;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ISO extends BaseType implements ImageFormat {
+ private final String type = "ISO";
+ @Override
+ public String toString() {
+ return type;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/image/format/ImageFormat.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/format/ImageFormat.java b/engine/storage/src/org/apache/cloudstack/storage/image/format/ImageFormat.java
new file mode 100644
index 0000000..f02694a
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/format/ImageFormat.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.storage.image.format;
+
+public interface ImageFormat {
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/image/format/ImageFormatHelper.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/format/ImageFormatHelper.java b/engine/storage/src/org/apache/cloudstack/storage/image/format/ImageFormatHelper.java
new file mode 100644
index 0000000..6ecb9b0
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/format/ImageFormatHelper.java
@@ -0,0 +1,44 @@
+/*
+ * 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.image.format;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.springframework.stereotype.Component;
+
+@Component
+public class ImageFormatHelper {
+ private static List<ImageFormat> formats;
+ private static final ImageFormat defaultFormat = new Unknown();
+ @Inject
+ public void setFormats(List<ImageFormat> formats) {
+ ImageFormatHelper.formats = formats;
+ }
+
+ public static ImageFormat getFormat(String format) {
+ for(ImageFormat fm : formats) {
+ if (fm.equals(format)) {
+ return fm;
+ }
+ }
+ return ImageFormatHelper.defaultFormat;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/image/format/OVA.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/format/OVA.java b/engine/storage/src/org/apache/cloudstack/storage/image/format/OVA.java
new file mode 100644
index 0000000..46f77a0
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/format/OVA.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.storage.image.format;
+
+import org.apache.cloudstack.storage.BaseType;
+import org.springframework.stereotype.Component;
+
+@Component
+public class OVA extends BaseType implements ImageFormat {
+ private final String type = "OVA";
+ @Override
+ public String toString() {
+ return type;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/image/format/QCOW2.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/format/QCOW2.java b/engine/storage/src/org/apache/cloudstack/storage/image/format/QCOW2.java
new file mode 100644
index 0000000..9e13ebb
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/format/QCOW2.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.storage.image.format;
+
+import org.apache.cloudstack.storage.BaseType;
+import org.springframework.stereotype.Component;
+
+@Component("imageformat_qcow2")
+public class QCOW2 extends BaseType implements ImageFormat {
+ private final String type = "QCOW2";
+ @Override
+ public String toString() {
+ return type;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/image/format/Unknown.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/format/Unknown.java b/engine/storage/src/org/apache/cloudstack/storage/image/format/Unknown.java
new file mode 100644
index 0000000..341be64
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/format/Unknown.java
@@ -0,0 +1,32 @@
+/*
+ * 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.image.format;
+
+import org.apache.cloudstack.storage.BaseType;
+import org.springframework.stereotype.Component;
+
+@Component
+public class Unknown extends BaseType implements ImageFormat {
+ private final String type = "Unknown";
+
+ @Override
+ public String toString() {
+ return type;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/image/format/VHD.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/format/VHD.java b/engine/storage/src/org/apache/cloudstack/storage/image/format/VHD.java
new file mode 100644
index 0000000..4a02e5f
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/format/VHD.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.storage.image.format;
+
+import org.apache.cloudstack.storage.BaseType;
+
+public class VHD extends BaseType implements ImageFormat {
+ private final String type = "VHD";
+ @Override
+ public String toString() {
+ return type;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/image/manager/ImageDataStoreManager.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/manager/ImageDataStoreManager.java b/engine/storage/src/org/apache/cloudstack/storage/image/manager/ImageDataStoreManager.java
new file mode 100644
index 0000000..878e394
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/manager/ImageDataStoreManager.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.image.manager;
+
+import org.apache.cloudstack.storage.image.store.ImageDataStore;
+
+public interface ImageDataStoreManager {
+ ImageDataStore getImageDataStore(long dataStoreId);
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/image/manager/ImageDataStoreManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/manager/ImageDataStoreManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/manager/ImageDataStoreManagerImpl.java
new file mode 100644
index 0000000..3b09fcb
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/manager/ImageDataStoreManagerImpl.java
@@ -0,0 +1,41 @@
+/*
+ * 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.image.manager;
+
+import javax.inject.Inject;
+
+import org.apache.cloudstack.storage.datastore.db.DataStoreVO;
+import org.apache.cloudstack.storage.image.db.ImageDaoStoreDao;
+import org.apache.cloudstack.storage.image.db.ImageDataDao;
+import org.apache.cloudstack.storage.image.db.ImageDataStoreVO;
+import org.apache.cloudstack.storage.image.store.ImageDataStore;
+
+public class ImageDataStoreManagerImpl implements ImageDataStoreManager {
+ @Inject
+ ImageDaoStoreDao dataStoreDao;
+ @Inject
+ ImageDataDao imageDataDao;
+ @Override
+ public ImageDataStore getImageDataStore(long dataStoreId) {
+ ImageDataStoreVO dataStore = dataStoreDao.findById(dataStoreId);
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProvider.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProvider.java b/engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProvider.java
new file mode 100644
index 0000000..42933f4
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProvider.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.image.provider;
+
+import org.apache.cloudstack.storage.image.store.ImageDataStore;
+
+public interface ImageDataStoreProvider {
+ ImageDataStore getImageDataStore(long imageStoreId);
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManager.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManager.java b/engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManager.java
new file mode 100644
index 0000000..1f9c956
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManager.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.storage.image.provider;
+
+public interface ImageDataStoreProviderManager {
+ public ImageDataStoreProvider getProvider(long providerId);
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManagerImpl.java
new file mode 100644
index 0000000..0325311
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/provider/ImageDataStoreProviderManagerImpl.java
@@ -0,0 +1,37 @@
+/*
+ * 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.image.provider;
+
+import javax.inject.Inject;
+
+import org.apache.cloudstack.storage.image.db.ImageDataStoreProviderDao;
+
+
+public class ImageDataStoreProviderManagerImpl implements ImageDataStoreProviderManager {
+
+ @Inject
+ ImageDataStoreProviderDao providerDao;
+ @Override
+ public ImageDataStoreProvider getProvider(long providerId) {
+
+ return null;
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStore.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStore.java b/engine/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStore.java
new file mode 100644
index 0000000..60d1e84
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStore.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.storage.image.store;
+
+import org.apache.cloudstack.storage.image.Template;
+import org.apache.cloudstack.storage.image.downloader.ImageDownloader;
+
+public interface ImageDataStore {
+ Template registerTemplate(long templateId);
+ String grantAccess(long templateId, long endPointId);
+ boolean revokeAccess(long templateId, long endPointId);
+ boolean deleteTemplate(long templateId);
+ boolean needDownloadToCacheStorage();
+ ImageDownloader getImageDownloader();
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStoreImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStoreImpl.java b/engine/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStoreImpl.java
new file mode 100644
index 0000000..925e152
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/store/ImageDataStoreImpl.java
@@ -0,0 +1,83 @@
+/*
+ * 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.image.store;
+
+import javax.inject.Inject;
+
+import org.apache.cloudstack.storage.image.Template;
+import org.apache.cloudstack.storage.image.db.ImageDataDao;
+import org.apache.cloudstack.storage.image.db.ImageDataVO;
+import org.apache.cloudstack.storage.image.downloader.ImageDownloader;
+import org.apache.cloudstack.storage.image.driver.ImageDataStoreDriver;
+
+public class ImageDataStoreImpl implements ImageDataStore {
+ @Inject
+ ImageDataDao imageDao;
+ ImageDataStoreDriver driver;
+ ImageDownloader downloader;
+ boolean needDownloadToCacheStorage = false;
+
+
+ public ImageDataStoreImpl(ImageDataStoreDriver driver, boolean needDownloadToCacheStorage, ImageDownloader downloader) {
+ this.driver = driver;
+ this.needDownloadToCacheStorage = needDownloadToCacheStorage;
+ this.downloader = downloader;
+ }
+
+ @Override
+ public Template registerTemplate(long templateId) {
+ ImageDataVO idv = imageDao.findById(templateId);
+ Template template = new Template(this, idv);
+ if (driver.registerTemplate(template)) {
+ return template;
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public String grantAccess(long templateId, long endPointId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public boolean revokeAccess(long templateId, long endPointId) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean deleteTemplate(long templateId) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public boolean needDownloadToCacheStorage() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public ImageDownloader getImageDownloader() {
+ return this.downloader;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/lifecycle/DefaultNfsSecondaryLifeCycle.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/lifecycle/DefaultNfsSecondaryLifeCycle.java b/engine/storage/src/org/apache/cloudstack/storage/lifecycle/DefaultNfsSecondaryLifeCycle.java
new file mode 100644
index 0000000..d31935e
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/lifecycle/DefaultNfsSecondaryLifeCycle.java
@@ -0,0 +1,54 @@
+/*
+ * 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.lifecycle;
+
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreLifeCycle;
+
+public class DefaultNfsSecondaryLifeCycle implements DataStoreLifeCycle {
+ protected DataStore _ds;
+ public DefaultNfsSecondaryLifeCycle(DataStore ds) {
+ _ds = ds;
+ }
+ public void add() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void delete() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void enable() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void disable() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void processEvent(DataStoreEvent event, Object... objs) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/lifecycle/DefaultPrimaryDataStoreLifeCycle.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/lifecycle/DefaultPrimaryDataStoreLifeCycle.java b/engine/storage/src/org/apache/cloudstack/storage/lifecycle/DefaultPrimaryDataStoreLifeCycle.java
new file mode 100644
index 0000000..dbf8589
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/lifecycle/DefaultPrimaryDataStoreLifeCycle.java
@@ -0,0 +1,123 @@
+package org.apache.cloudstack.storage.lifecycle;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreDriver;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreEndPoint;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreEndPointSelector;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreLifeCycle;
+import org.apache.log4j.Logger;
+
+import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.CreateStoragePoolCommand;
+import com.cloud.agent.api.ModifyStoragePoolAnswer;
+import com.cloud.agent.api.ModifyStoragePoolCommand;
+import com.cloud.alert.AlertManager;
+import com.cloud.exception.StorageUnavailableException;
+import com.cloud.host.HostVO;
+import com.cloud.storage.StoragePoolHostVO;
+import com.cloud.storage.StoragePoolVO;
+import com.cloud.storage.Storage.StoragePoolType;
+import com.cloud.storage.dao.StoragePoolDao;
+import com.cloud.storage.dao.StoragePoolHostDao;
+import com.cloud.utils.component.Inject;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+public class DefaultPrimaryDataStoreLifeCycle implements DataStoreLifeCycle {
+ private static final Logger s_logger = Logger.getLogger(DataStoreLifeCycle.class);
+ private DataStore _ds;
+ @Inject
+ StoragePoolDao _storagePoolDao;
+ @Inject
+ StoragePoolHostDao _poolHostDao;
+ public DefaultPrimaryDataStoreLifeCycle(DataStore ds) {
+ this._ds = ds;
+ }
+
+
+ protected boolean createStoragePool(DataStoreEndPoint ep, StoragePoolVO pool) {
+ DataStoreDriver dsDriver = _ds.getDataStoreDriver();
+ CreateStoragePoolCommand cmd = new CreateStoragePoolCommand(true, pool);
+ final Answer answer = dsDriver.sendMessage(ep, cmd);
+ if (answer != null && answer.getResult()) {
+ return true;
+ } else {
+ throw new CloudRuntimeException(answer.getDetails());
+ }
+ }
+
+ protected void connectHostToSharedPool(DataStoreEndPoint ep, StoragePoolVO pool) throws StorageUnavailableException {
+ DataStoreDriver dsDriver = _ds.getDataStoreDriver();
+ long hostId = ep.getHostId();
+ ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(true, pool);
+ final Answer answer = dsDriver.sendMessage(ep, cmd);
+
+ if (answer == null) {
+ throw new StorageUnavailableException("Unable to get an answer to the modify storage pool command", pool.getId());
+ }
+
+ if (!answer.getResult()) {
+ throw new StorageUnavailableException("Unable establish connection from storage head to storage pool " + pool.getId() + " due to " + answer.getDetails(), pool.getId());
+ }
+
+ assert (answer instanceof ModifyStoragePoolAnswer) : "Well, now why won't you actually return the ModifyStoragePoolAnswer when it's ModifyStoragePoolCommand? Pool=" + pool.getId();
+ ModifyStoragePoolAnswer mspAnswer = (ModifyStoragePoolAnswer) answer;
+
+ StoragePoolHostVO poolHost = _poolHostDao.findByPoolHost(pool.getId(), hostId);
+ if (poolHost == null) {
+ poolHost = new StoragePoolHostVO(pool.getId(), hostId, mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", "/"));
+ _poolHostDao.persist(poolHost);
+ } else {
+ poolHost.setLocalPath(mspAnswer.getPoolInfo().getLocalPath().replaceAll("//", "/"));
+ }
+ pool.setAvailableBytes(mspAnswer.getPoolInfo().getAvailableBytes());
+ pool.setCapacityBytes(mspAnswer.getPoolInfo().getCapacityBytes());
+ _storagePoolDao.update(pool.getId(), pool);
+ }
+
+ public void add() {
+ DataStoreEndPointSelector dseps = _ds.getEndPointSelector();
+ List<DataStoreEndPoint> dsep = dseps.getEndPoints(null);
+ boolean success = false;
+ StoragePoolVO spool = _storagePoolDao.findById(_ds.getId());
+ for (DataStoreEndPoint ep : dsep) {
+ success = createStoragePool(ep, spool);
+ if (success) {
+ break;
+ }
+ }
+
+ List<DataStoreEndPoint> poolHosts = new ArrayList<DataStoreEndPoint>();
+ for (DataStoreEndPoint ep : dsep) {
+ try {
+ connectHostToSharedPool(ep, spool);
+ poolHosts.add(ep);
+ } catch (Exception e) {
+ s_logger.debug("Failed to add storage on this ep: " + ep.getHostId());
+ }
+ }
+ }
+
+ public void delete() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void enable() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void disable() {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void processEvent(DataStoreEvent event, Object... objs) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/manager/BackupStorageManager.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/manager/BackupStorageManager.java b/engine/storage/src/org/apache/cloudstack/storage/manager/BackupStorageManager.java
new file mode 100644
index 0000000..f8388c9
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/manager/BackupStorageManager.java
@@ -0,0 +1,39 @@
+/*
+ * 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.manager;
+
+import org.apache.cloudstack.platform.subsystem.api.storage.DataObjectBackupStorageOperationState;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
+
+import com.cloud.storage.Snapshot;
+import com.cloud.storage.Volume;
+import com.cloud.template.VirtualMachineTemplate;
+import com.cloud.utils.fsm.NoTransitionException;
+
+public interface BackupStorageManager {
+ boolean contains(Volume vol);
+ boolean contains(Snapshot snapshot);
+ boolean contains(VirtualMachineTemplate template);
+
+ DataStore getBackupDataStore(Volume vol);
+ DataStore getBackupDataStore(Snapshot snapshot);
+ DataStore getBackupDataStore(VirtualMachineTemplate template);
+
+ boolean updateOperationState(Volume vol, DataObjectBackupStorageOperationState.Event event) throws NoTransitionException;
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/manager/BackupStorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/manager/BackupStorageManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/manager/BackupStorageManagerImpl.java
new file mode 100644
index 0000000..500763c
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/manager/BackupStorageManagerImpl.java
@@ -0,0 +1,66 @@
+/*
+ * 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.manager;
+
+import org.apache.cloudstack.platform.subsystem.api.storage.DataObjectBackupStorageOperationState.Event;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
+
+import com.cloud.storage.Snapshot;
+import com.cloud.storage.Volume;
+import com.cloud.template.VirtualMachineTemplate;
+import com.cloud.utils.fsm.NoTransitionException;
+
+public class BackupStorageManagerImpl implements BackupStorageManager {
+
+ public boolean contains(Volume vol) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean contains(Snapshot snapshot) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean contains(VirtualMachineTemplate template) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public DataStore getBackupDataStore(Volume vol) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public DataStore getBackupDataStore(Snapshot snapshot) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public DataStore getBackupDataStore(VirtualMachineTemplate template) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean updateOperationState(Volume vol, Event event) throws NoTransitionException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManager.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManager.java b/engine/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManager.java
new file mode 100644
index 0000000..6292ab8
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManager.java
@@ -0,0 +1,42 @@
+/*
+ * 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.manager;
+
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
+
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.storage.StoragePool;
+
+public interface PrimaryDataStoreManager {
+ PrimaryDataStore addDataStore(long zoneId, long podId, long clusterId, long hostId,
+ String URI,
+ String storageType,
+ String poolName,
+ String storageProviderName,
+ Map<String, String> params);
+ void deleteStoragePool(long poolId);
+ void enableStoragePool(long poolId);
+ void disableStoragePool(long poolId);
+ Map<String, List<String>> getSupportedPrimaryStorages(long zoneId, HypervisorType hypervisor);
+ Map<String, List<String>> getSupportedSecondaryStorages(long zoneId);
+ PrimaryDataStore getDataStore(String id);
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManagerImpl.java
new file mode 100644
index 0000000..2cae6a8
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/manager/PrimaryDataStoreManagerImpl.java
@@ -0,0 +1,142 @@
+/*
+ * 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.manager;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore.StoreType;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreLifeCycle;
+import org.apache.cloudstack.platform.subsystem.api.storage.StorageProvider;
+import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
+
+import com.cloud.dc.ClusterVO;
+import com.cloud.dc.DataCenterVO;
+import com.cloud.dc.dao.ClusterDao;
+import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.dc.dao.HostPodDao;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.storage.StoragePool;
+import com.cloud.storage.StoragePoolStatus;
+import com.cloud.storage.StoragePoolVO;
+import com.cloud.storage.dao.StoragePoolDao;
+import com.cloud.utils.component.Adapters;
+import com.cloud.utils.component.Inject;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+public class PrimaryDataStoreManagerImpl implements PrimaryDataStoreManager {
+ @Inject(adapter = StorageProvider.class)
+ protected Adapters<StorageProvider> _storageProviders;
+ @Inject
+ protected DataCenterDao _dcDao;
+ @Inject
+ protected HostPodDao _podDao;
+ @Inject
+ protected ClusterDao _clusterDao;
+ @Inject
+ protected StoragePoolDao _storagePoolDao;
+
+ public void deleteStoragePool(long poolId) {
+ StoragePool spool = _storagePoolDao.findById(poolId);
+ StorageProvider sp = findStorageProvider(spool.getStorageProvider());
+ DataStore ds = sp.getDataStore(spool);
+ DataStoreLifeCycle dslc = ds.getLifeCycle();
+ dslc.delete();
+ }
+
+ public void enableStoragePool(long poolId) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void disableStoragePool(long poolId) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public Map<String, List<String>> getSupportedPrimaryStorages(long zoneId, HypervisorType hypervisor) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Map<String, List<String>> getSupportedSecondaryStorages(long zoneId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ protected StorageProvider findStorageProvider(String name) {
+ Iterator<StorageProvider> spIter = _storageProviders.iterator();
+ StorageProvider sp = null;
+ while (spIter.hasNext()) {
+ sp = spIter.next();
+ if (sp.getProviderName().equalsIgnoreCase(name)) {
+ break;
+ }
+ }
+
+ return sp;
+ }
+
+ public StoragePool addStoragePool(long zoneId, long podId, long clusterId, long hostId, String URI, String storageType, String poolName, String storageProviderName, Map<String, String> params) {
+ StoragePoolVO spool = new StoragePoolVO();
+ long poolId = _storagePoolDao.getNextInSequence(Long.class, "id");
+ spool.setId(poolId);
+ spool.setDataCenterId(zoneId);
+ spool.setPodId(podId);
+ spool.setName(poolName);
+ spool.setClusterId(clusterId);
+ spool.setStorageProvider(storageProviderName);
+ spool.setStorageType(storageType);
+ spool.setStatus(StoragePoolStatus.Creating);
+ spool = _storagePoolDao.persist(spool);
+
+ StorageProvider sp = findStorageProvider(storageProviderName);
+ DataStore ds = sp.addDataStore((StoragePool)spool, URI, params);
+
+ DataStoreLifeCycle dslc = ds.getLifeCycle();
+ try {
+ dslc.add();
+ } catch (CloudRuntimeException e) {
+ _storagePoolDao.remove(spool.getId());
+ throw e;
+ }
+
+ spool.setPath(ds.getURI());
+ spool.setUuid(ds.getUUID());
+ spool.setStatus(StoragePoolStatus.Up);
+ _storagePoolDao.update(spool.getId(), spool);
+ spool = _storagePoolDao.findById(spool.getId());
+ return spool;
+ }
+
+ @Override
+ public PrimaryDataStore addDataStore(long zoneId, long podId, long clusterId, long hostId, String URI, String storageType, String poolName, String storageProviderName, Map<String, String> params) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public PrimaryDataStore getDataStore(String id) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/manager/SecondaryStorageManager.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/manager/SecondaryStorageManager.java b/engine/storage/src/org/apache/cloudstack/storage/manager/SecondaryStorageManager.java
new file mode 100644
index 0000000..cc9136e
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/manager/SecondaryStorageManager.java
@@ -0,0 +1,34 @@
+/*
+ * 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.manager;
+
+import java.util.List;
+
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
+
+import com.cloud.storage.Snapshot;
+import com.cloud.storage.Volume;
+import com.cloud.template.VirtualMachineTemplate;
+
+public interface SecondaryStorageManager {
+ DataStore getStore(Volume volume);
+ DataStore getImageStore(DataStore destStore);
+ List<DataStore> getImageStores(long zoneId);
+ DataStore getStore(Snapshot snapshot);
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/manager/SecondaryStorageManagerImpl.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/manager/SecondaryStorageManagerImpl.java b/engine/storage/src/org/apache/cloudstack/storage/manager/SecondaryStorageManagerImpl.java
new file mode 100644
index 0000000..dd4ed68
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/manager/SecondaryStorageManagerImpl.java
@@ -0,0 +1,56 @@
+/*
+ * 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.manager;
+
+import java.util.List;
+
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
+
+import com.cloud.storage.Snapshot;
+import com.cloud.storage.Volume;
+import com.cloud.storage.dao.VMTemplateZoneDao;
+import com.cloud.utils.component.Inject;
+
+public class SecondaryStorageManagerImpl implements SecondaryStorageManager {
+ public DataStore getStore(Volume volume) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public DataStore getImageStore(DataStore destStore) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public List<DataStore> getImageStores() {
+
+ return null;
+ }
+
+ public DataStore getStore(Snapshot snapshot) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public List<DataStore> getImageStores(long zoneId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/provider/DefaultNfsSecondaryStorageProvider.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/provider/DefaultNfsSecondaryStorageProvider.java b/engine/storage/src/org/apache/cloudstack/storage/provider/DefaultNfsSecondaryStorageProvider.java
new file mode 100644
index 0000000..484b485
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/provider/DefaultNfsSecondaryStorageProvider.java
@@ -0,0 +1,131 @@
+/*
+ * 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.provider;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.naming.ConfigurationException;
+
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreConfigurator;
+import org.apache.cloudstack.platform.subsystem.api.storage.StorageProvider;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore.StoreType;
+import org.apache.cloudstack.storage.datastoreconfigurator.NfsSecondaryStorageConfigurator;
+import org.apache.cloudstack.storage.datastoreconfigurator.XenNfsDataStoreConfigurator;
+
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.hypervisor.Hypervisor;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.storage.StoragePool;
+
+public class DefaultNfsSecondaryStorageProvider implements StorageProvider {
+ private String _name = DefaultPrimaryStorageProvider.class.toString();
+ protected Map<HypervisorType, Map<String, DataStoreConfigurator>> _supportedProtocols;
+ public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+ Map<String, DataStoreConfigurator> dscs = new HashMap<String, DataStoreConfigurator>();
+ DataStoreConfigurator nfsdc = new NfsSecondaryStorageConfigurator();
+ dscs.put(nfsdc.getProtocol(), nfsdc);
+
+ _supportedProtocols.put(HypervisorType.XenServer, dscs);
+ _supportedProtocols.put(HypervisorType.KVM, dscs);
+ _supportedProtocols.put(HypervisorType.VMware, dscs);
+ _supportedProtocols.put(HypervisorType.Ovm, dscs);
+ return true;
+ }
+
+ public String getName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean start() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean stop() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public List<HypervisorType> supportedHypervisors() {
+ List<HypervisorType> hypervisors = new ArrayList<HypervisorType>();
+ Set<HypervisorType> hyps = _supportedProtocols.keySet();
+
+ for (HypervisorType hy : hyps) {
+ hypervisors.add(hy);
+ }
+
+ return hypervisors;
+ }
+
+ public String getProviderName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void configure(Map<String, String> storeProviderInfo) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public DataStore addDataStore(StoragePool sp, String url, Map<String, String> params) {
+ URI uri;
+ try {
+ uri = new URI(url);
+ } catch (URISyntaxException e) {
+ throw new InvalidParameterValueException("invalide url" + url);
+ }
+
+ String protocol = uri.getScheme();
+ if (protocol == null) {
+ throw new InvalidParameterValueException("the protocol can't be null");
+ }
+
+ DataStoreConfigurator dscf = _supportedProtocols.get(HypervisorType.XenServer).get(protocol);
+ Map<String, String> configs = dscf.getConfigs(uri, params);
+ dscf.validate(configs);
+ DataStore ds = dscf.getDataStore(sp);
+ return ds;
+ }
+
+ public DataStore getDataStore(StoragePool pool) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Map<HypervisorType, Map<String, DataStoreConfigurator>> getDataStoreConfigs() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public List<StoreType> supportedStoreTypes() {
+ List<StoreType> types = new ArrayList<StoreType>();
+ types.add(StoreType.Image);
+ types.add(StoreType.Backup);
+ return types;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/provider/DefaultPrimaryStorageProvider.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/provider/DefaultPrimaryStorageProvider.java b/engine/storage/src/org/apache/cloudstack/storage/provider/DefaultPrimaryStorageProvider.java
new file mode 100644
index 0000000..a5579d0
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/provider/DefaultPrimaryStorageProvider.java
@@ -0,0 +1,144 @@
+package org.apache.cloudstack.storage.provider;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.ConfigurationException;
+
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreConfigurator;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreLifeCycle;
+import org.apache.cloudstack.platform.subsystem.api.storage.StorageProvider;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore.StoreType;
+import org.apache.cloudstack.storage.datastoreconfigurator.NfsDataStoreConfigurator;
+import org.apache.cloudstack.storage.datastoreconfigurator.XenNfsDataStoreConfigurator;
+
+import com.cloud.dc.ClusterVO;
+import com.cloud.dc.DataCenterVO;
+import com.cloud.dc.HostPodVO;
+import com.cloud.dc.dao.ClusterDao;
+import com.cloud.dc.dao.DataCenterDao;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.hypervisor.Hypervisor;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.storage.StoragePool;
+import com.cloud.storage.StoragePoolStatus;
+import com.cloud.storage.StoragePoolVO;
+import com.cloud.storage.dao.StoragePoolDao;
+import com.cloud.utils.component.Inject;
+
+public class DefaultPrimaryStorageProvider implements StorageProvider {
+ private String _name = DefaultPrimaryStorageProvider.class.toString();
+ static Map<HypervisorType, Map<String, DataStoreConfigurator>> _supportedProtocols;
+ @Inject
+ protected ClusterDao _clusterDao;
+
+ public List<HypervisorType> supportedHypervisors() {
+ List<HypervisorType> hypervisors = new ArrayList<HypervisorType>();
+ hypervisors.add(Hypervisor.HypervisorType.XenServer);
+ return hypervisors;
+ }
+
+ public DefaultPrimaryStorageProvider() {
+ Map<String, DataStoreConfigurator> dscs = new HashMap<String, DataStoreConfigurator>();
+ DataStoreConfigurator nfsdc = new XenNfsDataStoreConfigurator();
+ dscs.put(nfsdc.getProtocol(), nfsdc);
+
+ _supportedProtocols.put(HypervisorType.XenServer, dscs);
+ }
+
+ public List<StoreType> supportedStoreType() {
+ List<StoreType> type = new ArrayList<StoreType>();
+ type.add(StoreType.Primary);
+ return type;
+ }
+
+ public void configure(Map<String, String> storeProviderInfo) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public Map<HypervisorType, Map<String,DataStoreConfigurator>> getDataStoreConfigs() {
+ return _supportedProtocols;
+ }
+
+ public String getProviderName() {
+ return _name;
+ }
+
+ public DataStore createDataStore(HypervisorType hypervisor,
+ DataStoreConfigurator dsc) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public DataStore getDataStore(StoragePool pool) {
+ ClusterVO clu = _clusterDao.findById(pool.getClusterId());
+ HypervisorType hy = clu.getHypervisorType();
+ Map<String, DataStoreConfigurator> dscs = _supportedProtocols.get(hy);
+ DataStoreConfigurator dsc = dscs.get(pool.getPoolType().toString());
+ return dsc.getDataStore(pool);
+ }
+
+ public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public String getName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean start() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean stop() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public DataStore addDataStore(StoragePool spool, String url, Map<String, String> params) {
+ URI uri;
+ try {
+ uri = new URI(url);
+ } catch (URISyntaxException e) {
+ throw new InvalidParameterValueException("invalide url" + url);
+ }
+
+ String protocol = uri.getScheme();
+ if (protocol == null) {
+ throw new InvalidParameterValueException("the protocol can't be null");
+ }
+
+ ClusterVO cluster = _clusterDao.findById(spool.getClusterId());
+
+ Map<String, DataStoreConfigurator> dscs = _supportedProtocols.get(cluster.getHypervisorType());
+ if (dscs.isEmpty()) {
+ throw new InvalidParameterValueException("Doesn't support this hypervisor");
+ }
+
+ DataStoreConfigurator dsc = dscs.get(protocol);
+ if (dsc == null) {
+ throw new InvalidParameterValueException("Doesn't support this protocol");
+ }
+
+ Map<String, String> configs = dsc.getConfigs(uri, params);
+ dsc.validate(configs);
+ DataStore ds = dsc.getDataStore(spool);
+
+ return ds;
+ }
+
+ public List<StoreType> supportedStoreTypes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/provider/HttpImageStoreProvider.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/provider/HttpImageStoreProvider.java b/engine/storage/src/org/apache/cloudstack/storage/provider/HttpImageStoreProvider.java
new file mode 100644
index 0000000..c98320b
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/provider/HttpImageStoreProvider.java
@@ -0,0 +1,91 @@
+/*
+ * 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.provider;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.ConfigurationException;
+
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreConfigurator;
+import org.apache.cloudstack.platform.subsystem.api.storage.StorageProvider;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore.StoreType;
+
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.storage.StoragePool;
+
+public class HttpImageStoreProvider implements StorageProvider {
+
+ public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public String getName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean start() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean stop() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public List<HypervisorType> supportedHypervisors() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getProviderName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public List<StoreType> supportedStoreTypes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void configure(Map<String, String> storeProviderInfo) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public DataStore addDataStore(StoragePool sp, String uri, Map<String, String> params) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public DataStore getDataStore(StoragePool pool) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Map<HypervisorType, Map<String, DataStoreConfigurator>> getDataStoreConfigs() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/provider/S3SecondaryStorageProvider.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/provider/S3SecondaryStorageProvider.java b/engine/storage/src/org/apache/cloudstack/storage/provider/S3SecondaryStorageProvider.java
new file mode 100644
index 0000000..d5c15b3
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/provider/S3SecondaryStorageProvider.java
@@ -0,0 +1,91 @@
+/*
+ * 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.provider;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.ConfigurationException;
+
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreConfigurator;
+import org.apache.cloudstack.platform.subsystem.api.storage.StorageProvider;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore.StoreType;
+
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.storage.StoragePool;
+
+public class S3SecondaryStorageProvider implements StorageProvider {
+
+ public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public String getName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean start() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean stop() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public List<HypervisorType> supportedHypervisors() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getProviderName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public List<StoreType> supportedStoreTypes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void configure(Map<String, String> storeProviderInfo) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public DataStore addDataStore(StoragePool sp, String uri, Map<String, String> params) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public DataStore getDataStore(StoragePool pool) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Map<HypervisorType, Map<String, DataStoreConfigurator>> getDataStoreConfigs() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/provider/SwiftSecondaryStorageProvider.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/provider/SwiftSecondaryStorageProvider.java b/engine/storage/src/org/apache/cloudstack/storage/provider/SwiftSecondaryStorageProvider.java
new file mode 100644
index 0000000..75bf74c
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/provider/SwiftSecondaryStorageProvider.java
@@ -0,0 +1,91 @@
+/*
+ * 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.provider;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.naming.ConfigurationException;
+
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreConfigurator;
+import org.apache.cloudstack.platform.subsystem.api.storage.StorageProvider;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore.StoreType;
+
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.storage.StoragePool;
+
+public class SwiftSecondaryStorageProvider implements StorageProvider {
+
+ public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public String getName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean start() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean stop() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public List<HypervisorType> supportedHypervisors() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getProviderName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public List<StoreType> supportedStoreTypes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public void configure(Map<String, String> storeProviderInfo) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public DataStore addDataStore(StoragePool sp, String uri, Map<String, String> params) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public DataStore getDataStore(StoragePool pool) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Map<HypervisorType, Map<String, DataStoreConfigurator>> getDataStoreConfigs() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/snapshot/SnapshotService.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/snapshot/SnapshotService.java b/engine/storage/src/org/apache/cloudstack/storage/snapshot/SnapshotService.java
new file mode 100644
index 0000000..6adab00
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/snapshot/SnapshotService.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.storage.snapshot;
+
+public interface SnapshotService {
+ long takeSnapshot(long volumeId);
+ boolean deleteSnapshot(long snapshotId);
+}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/a6df8a5b/engine/storage/src/org/apache/cloudstack/storage/strategy/DefaultTemplateStratey.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/strategy/DefaultTemplateStratey.java b/engine/storage/src/org/apache/cloudstack/storage/strategy/DefaultTemplateStratey.java
new file mode 100644
index 0000000..2c6eaa3
--- /dev/null
+++ b/engine/storage/src/org/apache/cloudstack/storage/strategy/DefaultTemplateStratey.java
@@ -0,0 +1,191 @@
+/*
+ * 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.strategy;
+
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStore;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreDriver;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreEndPoint;
+import org.apache.cloudstack.platform.subsystem.api.storage.DataStoreEndPointSelector;
+import org.apache.cloudstack.platform.subsystem.api.storage.StorageEvent;
+import org.apache.cloudstack.platform.subsystem.api.storage.StorageProvider;
+import org.apache.cloudstack.platform.subsystem.api.storage.TemplateProfile;
+import org.apache.cloudstack.platform.subsystem.api.storage.TemplateStrategy;
+import org.apache.cloudstack.storage.image.ImageManager;
+import org.apache.log4j.Logger;
+
+import com.cloud.agent.api.storage.DownloadCommand.Proxy;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.hypervisor.Hypervisor.HypervisorType;
+import com.cloud.storage.Storage.ImageFormat;
+import com.cloud.storage.VMTemplateHostVO;
+import com.cloud.storage.VMTemplateStoragePoolVO;
+import com.cloud.storage.VMTemplateStorageResourceAssoc;
+import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
+import com.cloud.storage.dao.VMTemplateHostDao;
+import com.cloud.storage.dao.VMTemplatePoolDao;
+import com.cloud.utils.component.Inject;
+import com.cloud.utils.exception.CloudRuntimeException;
+
+public class DefaultTemplateStratey implements TemplateStrategy {
+ private static final Logger s_logger = Logger.getLogger(DefaultTemplateStratey.class);
+ protected DataStore _ds;
+ protected DataStoreDriver _driver;
+ protected int _primaryStorageDownloadWait;
+ protected int _installTries = 3;
+ protected int _storagePoolMaxWaitSeconds = 3600;
+ @Inject
+ VMTemplatePoolDao _templatePoolDao;
+ @Inject
+ VMTemplateHostDao _templateImageStoreDao;
+ @Inject
+ ImageManager _templateMgr;
+
+ public DefaultTemplateStratey(DataStore ds) {
+ _ds = ds;
+ }
+
+ public TemplateProfile get(long templateId) {
+ return _templateMgr.getProfile(templateId);
+ }
+
+ public TemplateProfile install(TemplateProfile tp) {
+ DataStoreEndPointSelector dseps = _ds.getEndPointSelector();
+ List<DataStoreEndPoint> eps = dseps.getEndPoints(StorageEvent.DownloadTemplateToPrimary);
+ int tries = Math.min(eps.size(), _installTries);
+
+ VMTemplateStoragePoolVO templateStoragePoolRef = _templatePoolDao.acquireInLockTable(tp.getTemplatePoolRefId(), _storagePoolMaxWaitSeconds);
+ if (templateStoragePoolRef == null) {
+ throw new CloudRuntimeException("Unable to acquire lock on VMTemplateStoragePool: " + tp.getTemplatePoolRefId());
+ }
+
+ try {
+ for (int retry = 0; retry < tries; retry++) {
+ Collections.shuffle(eps);
+ DataStoreEndPoint ep = eps.get(0);
+ try {
+ tp = _driver.install(tp, ep);
+ templateStoragePoolRef.setDownloadPercent(100);
+ templateStoragePoolRef.setDownloadState(Status.DOWNLOADED);
+ templateStoragePoolRef.setLocalDownloadPath(tp.getLocalPath());
+ templateStoragePoolRef.setInstallPath(tp.getLocalPath());
+ templateStoragePoolRef.setTemplateSize(tp.getSize());
+ _templatePoolDao.update(templateStoragePoolRef.getId(), templateStoragePoolRef);
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("Template " + tp.getTemplateId() + " is installed via " + ep.getHostId());
+ }
+ return get(tp.getTemplateId());
+ } catch (CloudRuntimeException e) {
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("Template " + tp.getTemplateId() + " download to pool " + _ds.getId() + " failed due to " + e.toString());
+ }
+ }
+ }
+ } finally {
+ _templatePoolDao.releaseFromLockTable(tp.getTemplatePoolRefId());
+ }
+
+ if (s_logger.isDebugEnabled()) {
+ s_logger.debug("Template " + tp.getTemplateId() + " is not found on and can not be downloaded to pool " + _ds.getId());
+ }
+ return null;
+ }
+
+ public TemplateProfile register(TemplateProfile tp) {
+
+ VMTemplateHostVO vmTemplateHost = _templateImageStoreDao.findByHostTemplate(_ds.getId(), tp.getTemplateId());
+ if (vmTemplateHost == null) {
+ vmTemplateHost = new VMTemplateHostVO(_ds.getId(), tp.getTemplateId(), new Date(), 0, VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED, null, null, "jobid0000", null, tp.getUrl());
+ _templateImageStoreDao.persist(vmTemplateHost);
+ }
+
+ DataStoreEndPointSelector dseps = _ds.getEndPointSelector();
+ List<DataStoreEndPoint> eps = dseps.getEndPoints(StorageEvent.RegisterTemplate);
+
+ Collections.shuffle(eps);
+ DataStoreEndPoint ep = eps.get(0);
+ _driver.register(tp, ep);
+
+ return null;
+ }
+
+ protected boolean checkHypervisor(HypervisorType hypervisor) {
+ StorageProvider sp = _ds.getProvider();
+ List<HypervisorType> spHys = sp.supportedHypervisors();
+ boolean checkHypervisor = false;
+ for (HypervisorType hy : spHys) {
+ if (hy == hypervisor) {
+ checkHypervisor = true;
+ }
+ }
+ return checkHypervisor;
+ }
+
+ protected boolean checkFormat(String url, String format) {
+ if ((!url.toLowerCase().endsWith("vhd")) && (!url.toLowerCase().endsWith("vhd.zip")) && (!url.toLowerCase().endsWith("vhd.bz2")) && (!url.toLowerCase().endsWith("vhd.gz"))
+ && (!url.toLowerCase().endsWith("qcow2")) && (!url.toLowerCase().endsWith("qcow2.zip")) && (!url.toLowerCase().endsWith("qcow2.bz2")) && (!url.toLowerCase().endsWith("qcow2.gz"))
+ && (!url.toLowerCase().endsWith("ova")) && (!url.toLowerCase().endsWith("ova.zip")) && (!url.toLowerCase().endsWith("ova.bz2")) && (!url.toLowerCase().endsWith("ova.gz"))
+ && (!url.toLowerCase().endsWith("img")) && (!url.toLowerCase().endsWith("raw"))) {
+ throw new InvalidParameterValueException("Please specify a valid " + format.toLowerCase());
+ }
+
+ if ((format.equalsIgnoreCase("vhd") && (!url.toLowerCase().endsWith("vhd") && !url.toLowerCase().endsWith("vhd.zip") && !url.toLowerCase().endsWith("vhd.bz2") && !url.toLowerCase().endsWith(
+ "vhd.gz")))
+ || (format.equalsIgnoreCase("qcow2") && (!url.toLowerCase().endsWith("qcow2") && !url.toLowerCase().endsWith("qcow2.zip") && !url.toLowerCase().endsWith("qcow2.bz2") && !url
+ .toLowerCase().endsWith("qcow2.gz")))
+ || (format.equalsIgnoreCase("ova") && (!url.toLowerCase().endsWith("ova") && !url.toLowerCase().endsWith("ova.zip") && !url.toLowerCase().endsWith("ova.bz2") && !url.toLowerCase()
+ .endsWith("ova.gz"))) || (format.equalsIgnoreCase("raw") && (!url.toLowerCase().endsWith("img") && !url.toLowerCase().endsWith("raw")))) {
+ throw new InvalidParameterValueException("Please specify a valid URL. URL:" + url + " is an invalid for the format " + format.toLowerCase());
+ }
+ return true;
+ }
+
+ public boolean canRegister(long templateId) {
+ TemplateProfile tp = get(templateId);
+
+ if (!checkHypervisor(tp.getHypervisorType())) {
+ return false;
+ }
+
+ if (!checkFormat(tp.getUrl(), tp.getFormat().toString())) {
+ return false;
+ }
+
+ return true;
+ }
+
+ public int getDownloadWait() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public long getMaxTemplateSizeInBytes() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public Proxy getHttpProxy() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}