mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	Renamed internal classes to use "imageStorexxx" instead of previous
"imageDataStorexxx". Add new addImageStoreCmd to use 3 image store provider plugins.
This commit is contained in:
		
							parent
							
								
									7699485b4f
								
							
						
					
					
						commit
						a872d6d306
					
				| @ -27,6 +27,7 @@ import org.apache.cloudstack.api.command.admin.host.PrepareForMaintenanceCmd; | |||||||
| import org.apache.cloudstack.api.command.admin.host.ReconnectHostCmd; | import org.apache.cloudstack.api.command.admin.host.ReconnectHostCmd; | ||||||
| import org.apache.cloudstack.api.command.admin.host.UpdateHostCmd; | import org.apache.cloudstack.api.command.admin.host.UpdateHostCmd; | ||||||
| import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd; | import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd; | ||||||
|  | import org.apache.cloudstack.api.command.admin.storage.AddImageStoreCmd; | ||||||
| import org.apache.cloudstack.api.command.admin.storage.AddS3Cmd; | import org.apache.cloudstack.api.command.admin.storage.AddS3Cmd; | ||||||
| import org.apache.cloudstack.api.command.admin.storage.ListS3sCmd; | import org.apache.cloudstack.api.command.admin.storage.ListS3sCmd; | ||||||
| import org.apache.cloudstack.api.command.admin.swift.AddSwiftCmd; | import org.apache.cloudstack.api.command.admin.swift.AddSwiftCmd; | ||||||
| @ -38,7 +39,7 @@ import com.cloud.exception.ResourceInUseException; | |||||||
| import com.cloud.host.Host; | import com.cloud.host.Host; | ||||||
| import com.cloud.hypervisor.Hypervisor.HypervisorType; | import com.cloud.hypervisor.Hypervisor.HypervisorType; | ||||||
| import com.cloud.org.Cluster; | import com.cloud.org.Cluster; | ||||||
| import com.cloud.storage.ObjectStore; | import com.cloud.storage.ImageStore; | ||||||
| import com.cloud.storage.S3; | import com.cloud.storage.S3; | ||||||
| import com.cloud.storage.Swift; | import com.cloud.storage.Swift; | ||||||
| import com.cloud.utils.Pair; | import com.cloud.utils.Pair; | ||||||
| @ -102,7 +103,7 @@ public interface ResourceService { | |||||||
| 
 | 
 | ||||||
|     S3 discoverS3(AddS3Cmd cmd) throws DiscoveryException; |     S3 discoverS3(AddS3Cmd cmd) throws DiscoveryException; | ||||||
| 
 | 
 | ||||||
|     ObjectStore discoverObjectStore(AddSecondaryStorageCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException; |     ImageStore discoverImageStore(AddImageStoreCmd cmd) throws IllegalArgumentException, DiscoveryException, InvalidParameterValueException; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     List<HypervisorType> getSupportedHypervisorTypes(long zoneId, boolean forVirtualRouter, Long podId); |     List<HypervisorType> getSupportedHypervisorTypes(long zoneId, boolean forVirtualRouter, Long podId); | ||||||
|  | |||||||
| @ -19,7 +19,12 @@ package com.cloud.storage; | |||||||
| import org.apache.cloudstack.api.Identity; | import org.apache.cloudstack.api.Identity; | ||||||
| import org.apache.cloudstack.api.InternalIdentity; | import org.apache.cloudstack.api.InternalIdentity; | ||||||
| 
 | 
 | ||||||
| public interface ObjectStore extends Identity, InternalIdentity { | public interface ImageStore extends Identity, InternalIdentity { | ||||||
|  | 
 | ||||||
|  |     public enum State { | ||||||
|  |         Disabled, Enabled, Deactivated; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * @return name of the object store. |      * @return name of the object store. | ||||||
| @ -32,10 +37,9 @@ public interface ObjectStore extends Identity, InternalIdentity { | |||||||
|     Long getDataCenterId(); |     Long getDataCenterId(); | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * @return region id. |      * @return image store state. | ||||||
|      * @return |  | ||||||
|      */ |      */ | ||||||
|     Long getRegionId(); |     State getState(); | ||||||
| 
 | 
 | ||||||
| 	/** | 	/** | ||||||
| 	 * @return object store provider name | 	 * @return object store provider name | ||||||
| @ -326,7 +326,7 @@ public interface ResponseGenerator { | |||||||
| 
 | 
 | ||||||
|     RegionResponse createRegionResponse(Region region); |     RegionResponse createRegionResponse(Region region); | ||||||
| 
 | 
 | ||||||
|     ObjectStoreResponse createObjectStoreResponse(ObjectStore os); |     ImageStoreResponse createImageStoreResponse(ImageStore os); | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * @param resourceTag |      * @param resourceTag | ||||||
|  | |||||||
| @ -25,16 +25,13 @@ import org.apache.cloudstack.api.ApiErrorCode; | |||||||
| import org.apache.cloudstack.api.BaseCmd; | import org.apache.cloudstack.api.BaseCmd; | ||||||
| import org.apache.cloudstack.api.Parameter; | import org.apache.cloudstack.api.Parameter; | ||||||
| import org.apache.cloudstack.api.ServerApiException; | import org.apache.cloudstack.api.ServerApiException; | ||||||
| import org.apache.cloudstack.api.BaseCmd.CommandType; |  | ||||||
| import org.apache.cloudstack.api.response.HostResponse; | import org.apache.cloudstack.api.response.HostResponse; | ||||||
| import org.apache.cloudstack.api.response.ObjectStoreResponse; |  | ||||||
| import org.apache.cloudstack.api.response.RegionResponse; | import org.apache.cloudstack.api.response.RegionResponse; | ||||||
| import org.apache.cloudstack.api.response.ZoneResponse; | import org.apache.cloudstack.api.response.ZoneResponse; | ||||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||||
| 
 | 
 | ||||||
| import com.cloud.exception.DiscoveryException; | import com.cloud.exception.DiscoveryException; | ||||||
| import com.cloud.host.Host; | import com.cloud.host.Host; | ||||||
| import com.cloud.storage.ObjectStore; |  | ||||||
| import com.cloud.user.Account; | import com.cloud.user.Account; | ||||||
| 
 | 
 | ||||||
| @APICommand(name = "addSecondaryStorage", description="Adds secondary storage.", responseObject=HostResponse.class) | @APICommand(name = "addSecondaryStorage", description="Adds secondary storage.", responseObject=HostResponse.class) | ||||||
| @ -114,13 +111,16 @@ public class AddSecondaryStorageCmd extends BaseCmd { | |||||||
|     @Override |     @Override | ||||||
|     public void execute(){ |     public void execute(){ | ||||||
|         try { |         try { | ||||||
|             ObjectStore result = _resourceService.discoverObjectStore(this); |             List<? extends Host> result = _resourceService.discoverHosts(this); | ||||||
|             ObjectStoreResponse storeResponse = null; |             HostResponse hostResponse = null; | ||||||
|             if (result != null ) { |             if (result != null && result.size() > 0) { | ||||||
|                     storeResponse = _responseGenerator.createObjectStoreResponse(result); |                 for (Host host : result) { | ||||||
|                     storeResponse.setResponseName(getCommandName()); |                     // There should only be one secondary storage host per add | ||||||
|                     storeResponse.setObjectName("secondarystorage"); |                     hostResponse = _responseGenerator.createHostResponse(host); | ||||||
|                     this.setResponseObject(storeResponse); |                     hostResponse.setResponseName(getCommandName()); | ||||||
|  |                     hostResponse.setObjectName("secondarystorage"); | ||||||
|  |                     this.setResponseObject(hostResponse); | ||||||
|  |                 } | ||||||
|             } else { |             } else { | ||||||
|                 throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage"); |                 throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage"); | ||||||
|             } |             } | ||||||
| @ -128,5 +128,6 @@ public class AddSecondaryStorageCmd extends BaseCmd { | |||||||
|             s_logger.warn("Exception: ", ex); |             s_logger.warn("Exception: ", ex); | ||||||
|             throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); |             throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -0,0 +1,120 @@ | |||||||
|  | // 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.api.command.admin.storage; | ||||||
|  | 
 | ||||||
|  | import java.util.Map; | ||||||
|  | 
 | ||||||
|  | import org.apache.cloudstack.api.APICommand; | ||||||
|  | import org.apache.cloudstack.api.ApiConstants; | ||||||
|  | import org.apache.cloudstack.api.ApiErrorCode; | ||||||
|  | import org.apache.cloudstack.api.BaseCmd; | ||||||
|  | import org.apache.cloudstack.api.Parameter; | ||||||
|  | import org.apache.cloudstack.api.ServerApiException; | ||||||
|  | import org.apache.cloudstack.api.response.ImageStoreResponse; | ||||||
|  | import org.apache.cloudstack.api.response.ZoneResponse; | ||||||
|  | import org.apache.log4j.Logger; | ||||||
|  | 
 | ||||||
|  | import com.cloud.exception.DiscoveryException; | ||||||
|  | import com.cloud.storage.ImageStore; | ||||||
|  | import com.cloud.user.Account; | ||||||
|  | 
 | ||||||
|  | @APICommand(name = "addImageStore", description="Adds backup image store.", responseObject=ImageStoreResponse.class) | ||||||
|  | public class AddImageStoreCmd extends BaseCmd { | ||||||
|  |     public static final Logger s_logger = Logger.getLogger(AddImageStoreCmd.class.getName()); | ||||||
|  |     private static final String s_name = "addimagestoreresponse"; | ||||||
|  | 
 | ||||||
|  |     ///////////////////////////////////////////////////// | ||||||
|  |     //////////////// API parameters ///////////////////// | ||||||
|  |     ///////////////////////////////////////////////////// | ||||||
|  | 
 | ||||||
|  |     @Parameter(name=ApiConstants.URL, type=CommandType.STRING, required=true, description="the URL for the image store") | ||||||
|  |     private String url; | ||||||
|  | 
 | ||||||
|  |     @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType=ZoneResponse.class, | ||||||
|  |             description="the Zone ID for the image store") | ||||||
|  |     private Long zoneId; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     @Parameter(name=ApiConstants.DETAILS, type=CommandType.MAP, description="the details for the image store") | ||||||
|  |     private Map<String, String> details; | ||||||
|  | 
 | ||||||
|  |     @Parameter(name=ApiConstants.SCOPE, type=CommandType.STRING, | ||||||
|  |             required=false, description="the scope of the image store: zone or region") | ||||||
|  |     private String scope; | ||||||
|  | 
 | ||||||
|  |     @Parameter(name=ApiConstants.PROVIDER, type=CommandType.STRING, | ||||||
|  |             required=false, description="the image store provider name") | ||||||
|  |     private String providerName; | ||||||
|  | 
 | ||||||
|  |     ///////////////////////////////////////////////////// | ||||||
|  |     /////////////////// Accessors /////////////////////// | ||||||
|  |     ///////////////////////////////////////////////////// | ||||||
|  | 
 | ||||||
|  |     public String getUrl() { | ||||||
|  |         return url; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public Long getZoneId() { | ||||||
|  |         return zoneId; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |      public Map<String, String> getDetails() { | ||||||
|  |         return details; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public String getScope() { | ||||||
|  |         return this.scope; | ||||||
|  |      } | ||||||
|  | 
 | ||||||
|  |     public String getProviderName() { | ||||||
|  |         return this.providerName; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     ///////////////////////////////////////////////////// | ||||||
|  |     /////////////// API Implementation/////////////////// | ||||||
|  |     ///////////////////////////////////////////////////// | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public String getCommandName() { | ||||||
|  |         return s_name; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public long getEntityOwnerId() { | ||||||
|  |         return Account.ACCOUNT_ID_SYSTEM; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void execute(){ | ||||||
|  |         try{ | ||||||
|  |             ImageStore result = _resourceService.discoverImageStore(this); | ||||||
|  |             ImageStoreResponse storeResponse = null; | ||||||
|  |             if (result != null ) { | ||||||
|  |                     storeResponse = _responseGenerator.createImageStoreResponse(result); | ||||||
|  |                     storeResponse.setResponseName(getCommandName()); | ||||||
|  |                     storeResponse.setObjectName("secondarystorage"); | ||||||
|  |                     this.setResponseObject(storeResponse); | ||||||
|  |             } else { | ||||||
|  |                 throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add secondary storage"); | ||||||
|  |             } | ||||||
|  |         } catch (DiscoveryException ex) { | ||||||
|  |             s_logger.warn("Exception: ", ex); | ||||||
|  |             throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex.getMessage()); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -21,18 +21,18 @@ import org.apache.cloudstack.api.BaseResponse; | |||||||
| import com.cloud.serializer.Param; | import com.cloud.serializer.Param; | ||||||
| import com.google.gson.annotations.SerializedName; | import com.google.gson.annotations.SerializedName; | ||||||
| 
 | 
 | ||||||
| public class ObjectStoreDetailResponse extends BaseResponse { | public class ImageStoreDetailResponse extends BaseResponse { | ||||||
|     @SerializedName("name") @Param(description="detail property name of the object store") |     @SerializedName("name") @Param(description="detail property name of the image store") | ||||||
|     private String name; |     private String name; | ||||||
| 
 | 
 | ||||||
|     @SerializedName("value") @Param(description="detail property value of the object store") |     @SerializedName("value") @Param(description="detail property value of the image store") | ||||||
|     private String value; |     private String value; | ||||||
| 
 | 
 | ||||||
|     public ObjectStoreDetailResponse(){ |     public ImageStoreDetailResponse(){ | ||||||
|         super(); |         super(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public ObjectStoreDetailResponse(String name, String val){ |     public ImageStoreDetailResponse(String name, String val){ | ||||||
|         super(); |         super(); | ||||||
|         this.name = name; |         this.name = name; | ||||||
|         this.value = val; |         this.value = val; | ||||||
| @ -71,7 +71,7 @@ public class ObjectStoreDetailResponse extends BaseResponse { | |||||||
|             return false; |             return false; | ||||||
|         if (getClass() != obj.getClass()) |         if (getClass() != obj.getClass()) | ||||||
|             return false; |             return false; | ||||||
|         ObjectStoreDetailResponse other = (ObjectStoreDetailResponse) obj; |         ImageStoreDetailResponse other = (ImageStoreDetailResponse) obj; | ||||||
|         String oid = this.getName(); |         String oid = this.getName(); | ||||||
|         if (oid == null) { |         if (oid == null) { | ||||||
|             if (other.getName() != null) |             if (other.getName() != null) | ||||||
| @ -24,48 +24,46 @@ import org.apache.cloudstack.api.BaseResponse; | |||||||
| import org.apache.cloudstack.api.EntityReference; | import org.apache.cloudstack.api.EntityReference; | ||||||
| 
 | 
 | ||||||
| import com.cloud.serializer.Param; | import com.cloud.serializer.Param; | ||||||
| import com.cloud.storage.ObjectStore; | import com.cloud.storage.ImageStore; | ||||||
| import com.cloud.storage.ScopeType; | import com.cloud.storage.ScopeType; | ||||||
| import com.google.gson.annotations.SerializedName; | import com.google.gson.annotations.SerializedName; | ||||||
| 
 | 
 | ||||||
| @EntityReference(value=ObjectStore.class) | @EntityReference(value=ImageStore.class) | ||||||
| public class ObjectStoreResponse extends BaseResponse { | public class ImageStoreResponse extends BaseResponse { | ||||||
|     @SerializedName("id") @Param(description="the ID of the object store") |     @SerializedName("id") @Param(description="the ID of the image store") | ||||||
|     private String id; |     private String id; | ||||||
| 
 | 
 | ||||||
|     @SerializedName("zoneid") @Param(description="the Zone ID of the object store") |     @SerializedName("zoneid") @Param(description="the Zone ID of the image store") | ||||||
|     private String zoneId; |     private String zoneId; | ||||||
| 
 | 
 | ||||||
|     @SerializedName(ApiConstants.ZONE_NAME) @Param(description="the Zone name of the object store") |     @SerializedName(ApiConstants.ZONE_NAME) @Param(description="the Zone name of the image store") | ||||||
|     private String zoneName; |     private String zoneName; | ||||||
| 
 | 
 | ||||||
|     @SerializedName("regionid") @Param(description="the Region ID of the object store") |     @SerializedName("state") @Param(description="the state of the image store") | ||||||
|     private Long regionId; |     private ImageStore.State state; | ||||||
| 
 | 
 | ||||||
|     @SerializedName("regionname") @Param(description="the Region name of the object store") |  | ||||||
|     private String regionName; |  | ||||||
| 
 | 
 | ||||||
|     @SerializedName("name") @Param(description="the name of the object store") |     @SerializedName("name") @Param(description="the name of the image store") | ||||||
|     private String name; |     private String name; | ||||||
| 
 | 
 | ||||||
|     @SerializedName("url") @Param(description="the url of the object store") |     @SerializedName("url") @Param(description="the url of the image store") | ||||||
|     private String url; |     private String url; | ||||||
| 
 | 
 | ||||||
|     @SerializedName("protocol") @Param(description="the protocol of the object store") |     @SerializedName("protocol") @Param(description="the protocol of the image store") | ||||||
|     private String protocol; |     private String protocol; | ||||||
| 
 | 
 | ||||||
|     @SerializedName("providername") @Param(description="the provider name of the object store") |     @SerializedName("providername") @Param(description="the provider name of the image store") | ||||||
|     private String providerName; |     private String providerName; | ||||||
| 
 | 
 | ||||||
|     @SerializedName("scope") @Param(description="the scope of the object store") |     @SerializedName("scope") @Param(description="the scope of the image store") | ||||||
|     private ScopeType scope; |     private ScopeType scope; | ||||||
| 
 | 
 | ||||||
|     @SerializedName("details") @Param(description="the details of the object store") |     @SerializedName("details") @Param(description="the details of the image store") | ||||||
|     private Set<ObjectStoreDetailResponse> details; |     private Set<ImageStoreDetailResponse> details; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     public ObjectStoreResponse(){ |     public ImageStoreResponse(){ | ||||||
|         this.details = new LinkedHashSet<ObjectStoreDetailResponse>(); |         this.details = new LinkedHashSet<ImageStoreDetailResponse>(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
| @ -98,20 +96,12 @@ public class ObjectStoreResponse extends BaseResponse { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     public Long getRegionId() { |     public ImageStore.State getState() { | ||||||
|         return regionId; |         return state; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public void setRegionId(Long regionId) { |     public void setState(ImageStore.State state) { | ||||||
|         this.regionId = regionId; |         this.state = state; | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public String getRegionName() { |  | ||||||
|         return regionName; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public void setRegionName(String regionName) { |  | ||||||
|         this.regionName = regionName; |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public String getName() { |     public String getName() { | ||||||
| @ -155,15 +145,15 @@ public class ObjectStoreResponse extends BaseResponse { | |||||||
|         this.protocol = protocol; |         this.protocol = protocol; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public Set<ObjectStoreDetailResponse> getDetails() { |     public Set<ImageStoreDetailResponse> getDetails() { | ||||||
|         return details; |         return details; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public void setDetails(Set<ObjectStoreDetailResponse> details) { |     public void setDetails(Set<ImageStoreDetailResponse> details) { | ||||||
|         this.details = details; |         this.details = details; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public void addDetail(ObjectStoreDetailResponse detail){ |     public void addDetail(ImageStoreDetailResponse detail){ | ||||||
|         this.details.add(detail); |         this.details.add(detail); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -786,6 +786,9 @@ | |||||||
|   <bean id="vMSnapshotManagerImpl" class="com.cloud.vm.snapshot.VMSnapshotManagerImpl" /> |   <bean id="vMSnapshotManagerImpl" class="com.cloud.vm.snapshot.VMSnapshotManagerImpl" /> | ||||||
|   <bean id="volumeManagerImpl" class="com.cloud.storage.VolumeManagerImpl" /> |   <bean id="volumeManagerImpl" class="com.cloud.storage.VolumeManagerImpl" /> | ||||||
|   <bean id="ClassicalPrimaryDataStoreProvider" class="org.apache.cloudstack.storage.datastore.provider.CloudStackPrimaryDataStoreProviderImpl" /> |   <bean id="ClassicalPrimaryDataStoreProvider" class="org.apache.cloudstack.storage.datastore.provider.CloudStackPrimaryDataStoreProviderImpl" /> | ||||||
|  |   <bean id="cloudStackImageStoreProviderImpl" class="org.apache.cloudstack.storage.datastore.provider.CloudStackImageStoreProviderImpl" /> | ||||||
|  |   <bean id="s3ImageStoreProviderImpl" class="org.apache.cloudstack.storage.datastore.provider.S3ImageStoreProviderImpl" /> | ||||||
|  |   <bean id="swiftImageStoreProviderImpl" class="org.apache.cloudstack.storage.datastore.provider.SwiftImageStoreProviderImpl" />   | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| <!--=======================================================================================================--> | <!--=======================================================================================================--> | ||||||
|  | |||||||
| @ -241,6 +241,9 @@ listSwifts=1 | |||||||
| addS3=1 | addS3=1 | ||||||
| listS3s=1 | listS3s=1 | ||||||
| 
 | 
 | ||||||
|  | #### image store commands | ||||||
|  | addImageStore=1 | ||||||
|  | 
 | ||||||
| #### host commands | #### host commands | ||||||
| addHost=3 | addHost=3 | ||||||
| addCluster=1 | addCluster=1 | ||||||
|  | |||||||
| @ -19,6 +19,6 @@ | |||||||
| package org.apache.cloudstack.engine.subsystem.api.storage; | package org.apache.cloudstack.engine.subsystem.api.storage; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| public interface ImageDataStoreProvider extends DataStoreProvider { | public interface ImageStoreProvider extends DataStoreProvider { | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
| @ -28,38 +28,38 @@ import javax.inject.Inject; | |||||||
| 
 | 
 | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; | import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager; | import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.ImageDataStoreProvider; | import org.apache.cloudstack.engine.subsystem.api.storage.ImageStoreProvider; | ||||||
| import org.apache.cloudstack.storage.image.ImageDataStoreDriver; | import org.apache.cloudstack.storage.image.ImageStoreDriver; | ||||||
| import org.apache.cloudstack.storage.image.datastore.ImageDataStore; | import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity; | ||||||
| import org.apache.cloudstack.storage.image.datastore.ImageDataStoreProviderManager; | import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager; | ||||||
| import org.apache.cloudstack.storage.image.db.ImageDataStoreDao; | import org.apache.cloudstack.storage.image.db.ImageStoreDao; | ||||||
| import org.apache.cloudstack.storage.image.db.ImageDataStoreVO; | import org.apache.cloudstack.storage.image.db.ImageStoreVO; | ||||||
| import org.apache.cloudstack.storage.image.store.ImageDataStoreImpl; | import org.apache.cloudstack.storage.image.store.ImageStoreImpl; | ||||||
| import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||||
| 
 | 
 | ||||||
| import com.cloud.storage.dao.VMTemplateDao; | import com.cloud.storage.dao.VMTemplateDao; | ||||||
| 
 | 
 | ||||||
| @Component | @Component | ||||||
| public class ImageDataStoreProviderManagerImpl implements ImageDataStoreProviderManager { | public class ImageStoreProviderManagerImpl implements ImageStoreProviderManager { | ||||||
|     @Inject |     @Inject | ||||||
|     ImageDataStoreDao dataStoreDao; |     ImageStoreDao dataStoreDao; | ||||||
|     @Inject |     @Inject | ||||||
|     VMTemplateDao imageDataDao; |     VMTemplateDao imageDataDao; | ||||||
|     @Inject |     @Inject | ||||||
|     DataStoreProviderManager providerManager; |     DataStoreProviderManager providerManager; | ||||||
|     Map<String, ImageDataStoreDriver> driverMaps; |     Map<String, ImageStoreDriver> driverMaps; | ||||||
| 
 | 
 | ||||||
|     @PostConstruct |     @PostConstruct | ||||||
|     public void config() { |     public void config() { | ||||||
|         driverMaps = new HashMap<String, ImageDataStoreDriver>(); |         driverMaps = new HashMap<String, ImageStoreDriver>(); | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     @Override |     @Override | ||||||
|     public ImageDataStore getImageDataStore(long dataStoreId) { |     public ImageStoreEntity getImageStore(long dataStoreId) { | ||||||
|         ImageDataStoreVO dataStore = dataStoreDao.findById(dataStoreId); |         ImageStoreVO dataStore = dataStoreDao.findById(dataStoreId); | ||||||
|         String providerName = dataStore.getProviderName(); |         String providerName = dataStore.getProviderName(); | ||||||
|         ImageDataStoreProvider provider = (ImageDataStoreProvider)providerManager.getDataStoreProvider(providerName); |         ImageStoreProvider provider = (ImageStoreProvider)providerManager.getDataStoreProvider(providerName); | ||||||
|         ImageDataStore imgStore = ImageDataStoreImpl.getDataStore(dataStore,  |         ImageStoreEntity imgStore = ImageStoreImpl.getDataStore(dataStore,  | ||||||
|                 driverMaps.get(provider.getName()), provider |                 driverMaps.get(provider.getName()), provider | ||||||
|                 ); |                 ); | ||||||
|         // TODO Auto-generated method stub |         // TODO Auto-generated method stub | ||||||
| @ -67,7 +67,7 @@ public class ImageDataStoreProviderManagerImpl implements ImageDataStoreProvider | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public boolean registerDriver(String providerName, ImageDataStoreDriver driver) { |     public boolean registerDriver(String providerName, ImageStoreDriver driver) { | ||||||
|         if (driverMaps.containsKey(providerName)) { |         if (driverMaps.containsKey(providerName)) { | ||||||
|             return false; |             return false; | ||||||
|         } |         } | ||||||
| @ -76,17 +76,17 @@ public class ImageDataStoreProviderManagerImpl implements ImageDataStoreProvider | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public ImageDataStore getImageDataStore(String uuid) { |     public ImageStoreEntity getImageStore(String uuid) { | ||||||
|         ImageDataStoreVO dataStore = dataStoreDao.findByUuid(uuid); |         ImageStoreVO dataStore = dataStoreDao.findByUuid(uuid); | ||||||
|         return getImageDataStore(dataStore.getId()); |         return getImageStore(dataStore.getId()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public List<DataStore> getList() { |     public List<DataStore> getList() { | ||||||
|         List<ImageDataStoreVO> stores = dataStoreDao.listAll(); |         List<ImageStoreVO> stores = dataStoreDao.listAll(); | ||||||
|         List<DataStore> imageStores = new ArrayList<DataStore>(); |         List<DataStore> imageStores = new ArrayList<DataStore>(); | ||||||
|         for (ImageDataStoreVO store : stores) { |         for (ImageStoreVO store : stores) { | ||||||
|             imageStores.add(getImageDataStore(store.getId())); |             imageStores.add(getImageStore(store.getId())); | ||||||
|         } |         } | ||||||
|         return imageStores; |         return imageStores; | ||||||
|     } |     } | ||||||
| @ -25,46 +25,47 @@ import javax.inject.Inject; | |||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; | import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver; | import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreRole; | import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreRole; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.ImageDataStoreProvider; | import org.apache.cloudstack.engine.subsystem.api.storage.ImageStoreProvider; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.Scope; | import org.apache.cloudstack.engine.subsystem.api.storage.Scope; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo; | import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo; | import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; | import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope; | import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope; | ||||||
| import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager; | import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager; | ||||||
| import org.apache.cloudstack.storage.image.ImageDataStoreDriver; | import org.apache.cloudstack.storage.image.ImageStoreDriver; | ||||||
| import org.apache.cloudstack.storage.image.datastore.ImageDataStore; | import org.apache.cloudstack.storage.image.datastore.ImageStoreEntity; | ||||||
| import org.apache.cloudstack.storage.image.db.ImageDataStoreVO; | import org.apache.cloudstack.storage.image.db.ImageStoreVO; | ||||||
| 
 | 
 | ||||||
|  | import com.cloud.storage.ImageStore; | ||||||
| import com.cloud.storage.dao.VMTemplateDao; | import com.cloud.storage.dao.VMTemplateDao; | ||||||
| import com.cloud.utils.component.ComponentContext; | import com.cloud.utils.component.ComponentContext; | ||||||
| import com.cloud.utils.storage.encoding.EncodingType; | import com.cloud.utils.storage.encoding.EncodingType; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| public class ImageDataStoreImpl implements ImageDataStore { | public class ImageStoreImpl implements ImageStoreEntity { | ||||||
|     @Inject |     @Inject | ||||||
|     VMTemplateDao imageDao; |     VMTemplateDao imageDao; | ||||||
|     @Inject |     @Inject | ||||||
|     private ObjectInDataStoreManager objectInStoreMgr; |     private ObjectInDataStoreManager objectInStoreMgr; | ||||||
|     protected ImageDataStoreDriver driver; |     protected ImageStoreDriver driver; | ||||||
|     protected ImageDataStoreVO imageDataStoreVO; |     protected ImageStoreVO imageDataStoreVO; | ||||||
|     protected ImageDataStoreProvider provider; |     protected ImageStoreProvider provider; | ||||||
|     boolean needDownloadToCacheStorage = false; |     boolean needDownloadToCacheStorage = false; | ||||||
| 
 | 
 | ||||||
|     public ImageDataStoreImpl() { |     public ImageStoreImpl() { | ||||||
| 
 | 
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     protected void configure(ImageDataStoreVO dataStoreVO, ImageDataStoreDriver imageDataStoreDriver, |     protected void configure(ImageStoreVO dataStoreVO, ImageStoreDriver imageDataStoreDriver, | ||||||
|             ImageDataStoreProvider provider) { |             ImageStoreProvider provider) { | ||||||
|         this.driver = imageDataStoreDriver; |         this.driver = imageDataStoreDriver; | ||||||
|         this.imageDataStoreVO = dataStoreVO; |         this.imageDataStoreVO = dataStoreVO; | ||||||
|         this.provider = provider; |         this.provider = provider; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public static ImageDataStore getDataStore(ImageDataStoreVO dataStoreVO, ImageDataStoreDriver imageDataStoreDriver, |     public static ImageStoreEntity getDataStore(ImageStoreVO dataStoreVO, ImageStoreDriver imageDataStoreDriver, | ||||||
|             ImageDataStoreProvider provider) { |             ImageStoreProvider provider) { | ||||||
|         ImageDataStoreImpl instance = (ImageDataStoreImpl)ComponentContext.inject(ImageDataStoreImpl.class); |         ImageStoreImpl instance = (ImageStoreImpl)ComponentContext.inject(ImageStoreImpl.class); | ||||||
|         instance.configure(dataStoreVO, imageDataStoreDriver, provider); |         instance.configure(dataStoreVO, imageDataStoreDriver, provider); | ||||||
|         return instance; |         return instance; | ||||||
|     } |     } | ||||||
| @ -154,8 +155,8 @@ public class ImageDataStoreImpl implements ImageDataStore { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public Long getRegionId() { |     public ImageStore.State getState() { | ||||||
|         return imageDataStoreVO.getRegionId(); |         return imageDataStoreVO.getState(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
| @ -20,5 +20,5 @@ package org.apache.cloudstack.storage.image.store.lifecycle; | |||||||
| 
 | 
 | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle; | import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle; | ||||||
| 
 | 
 | ||||||
| public interface ImageDataStoreLifeCycle extends DataStoreLifeCycle { | public interface ImageStoreLifeCycle extends DataStoreLifeCycle { | ||||||
| } | } | ||||||
| @ -22,7 +22,7 @@ import java.util.UUID; | |||||||
| 
 | 
 | ||||||
| import javax.inject.Inject; | import javax.inject.Inject; | ||||||
| 
 | 
 | ||||||
| import org.apache.cloudstack.storage.to.ImageDataStoreTO; | import org.apache.cloudstack.storage.to.ImageStoreTO; | ||||||
| import org.apache.cloudstack.storage.to.ImageOnPrimayDataStoreTO; | import org.apache.cloudstack.storage.to.ImageOnPrimayDataStoreTO; | ||||||
| import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; | import org.apache.cloudstack.storage.to.PrimaryDataStoreTO; | ||||||
| import org.apache.cloudstack.storage.to.TemplateTO; | import org.apache.cloudstack.storage.to.TemplateTO; | ||||||
| @ -131,7 +131,7 @@ public class DirectAgentTest extends CloudStackTestNGBase { | |||||||
|         Mockito.when(primaryStore.getUuid()).thenReturn(this.getLocalStorageUuid()); |         Mockito.when(primaryStore.getUuid()).thenReturn(this.getLocalStorageUuid()); | ||||||
|         Mockito.when(image.getPrimaryDataStore()).thenReturn(primaryStore); |         Mockito.when(image.getPrimaryDataStore()).thenReturn(primaryStore); | ||||||
|          |          | ||||||
|         ImageDataStoreTO imageStore = Mockito.mock(ImageDataStoreTO.class); |         ImageStoreTO imageStore = Mockito.mock(ImageStoreTO.class); | ||||||
|         Mockito.when(imageStore.getType()).thenReturn("http"); |         Mockito.when(imageStore.getType()).thenReturn("http"); | ||||||
|          |          | ||||||
|         TemplateTO template = Mockito.mock(TemplateTO.class); |         TemplateTO template = Mockito.mock(TemplateTO.class); | ||||||
|  | |||||||
| @ -27,7 +27,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; | |||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.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.DataStoreRole; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.Scope; | import org.apache.cloudstack.engine.subsystem.api.storage.Scope; | ||||||
| import org.apache.cloudstack.storage.image.datastore.ImageDataStoreProviderManager; | import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager; | ||||||
| import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||||
| 
 | 
 | ||||||
| import com.cloud.utils.exception.CloudRuntimeException; | import com.cloud.utils.exception.CloudRuntimeException; | ||||||
| @ -37,14 +37,14 @@ public class DataStoreManagerImpl implements DataStoreManager { | |||||||
|     @Inject |     @Inject | ||||||
|     PrimaryDataStoreProviderManager primaryStorMgr; |     PrimaryDataStoreProviderManager primaryStorMgr; | ||||||
|     @Inject |     @Inject | ||||||
|     ImageDataStoreProviderManager imageDataStoreMgr; |     ImageStoreProviderManager imageDataStoreMgr; | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public DataStore getDataStore(long storeId, DataStoreRole role) { |     public DataStore getDataStore(long storeId, DataStoreRole role) { | ||||||
|         if (role == DataStoreRole.Primary) { |         if (role == DataStoreRole.Primary) { | ||||||
|             return primaryStorMgr.getPrimaryDataStore(storeId); |             return primaryStorMgr.getPrimaryDataStore(storeId); | ||||||
|         } else if (role == DataStoreRole.Image) { |         } else if (role == DataStoreRole.Image) { | ||||||
|             return imageDataStoreMgr.getImageDataStore(storeId); |             return imageDataStoreMgr.getImageStore(storeId); | ||||||
|         } |         } | ||||||
|         throw new CloudRuntimeException("un recognized type" + role); |         throw new CloudRuntimeException("un recognized type" + role); | ||||||
|     } |     } | ||||||
| @ -58,7 +58,7 @@ public class DataStoreManagerImpl implements DataStoreManager { | |||||||
|         if (role == DataStoreRole.Primary) { |         if (role == DataStoreRole.Primary) { | ||||||
|             return primaryStorMgr.getPrimaryDataStore(uuid); |             return primaryStorMgr.getPrimaryDataStore(uuid); | ||||||
|         } else if (role == DataStoreRole.Image) { |         } else if (role == DataStoreRole.Image) { | ||||||
|             return imageDataStoreMgr.getImageDataStore(uuid); |             return imageDataStoreMgr.getImageStore(uuid); | ||||||
|         } |         } | ||||||
|         throw new CloudRuntimeException("un recognized type" + role); |         throw new CloudRuntimeException("un recognized type" + role); | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -31,13 +31,13 @@ import org.apache.cloudstack.api.response.StorageProviderResponse; | |||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider; | import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider.DataStoreProviderType; | import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider.DataStoreProviderType; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager; | import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManager; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.ImageDataStoreProvider; | import org.apache.cloudstack.engine.subsystem.api.storage.ImageStoreProvider; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver; | import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider; | import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider; | ||||||
| import org.apache.cloudstack.storage.image.ImageDataStoreDriver; | import org.apache.cloudstack.storage.image.ImageStoreDriver; | ||||||
| import org.apache.cloudstack.storage.datastore.PrimaryDataStoreProviderManager; | import org.apache.cloudstack.storage.datastore.PrimaryDataStoreProviderManager; | ||||||
| import org.apache.cloudstack.storage.datastore.db.DataStoreProviderDao; | import org.apache.cloudstack.storage.datastore.db.DataStoreProviderDao; | ||||||
| import org.apache.cloudstack.storage.image.datastore.ImageDataStoreProviderManager; | import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager; | ||||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||||
| import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||||
| 
 | 
 | ||||||
| @ -56,7 +56,7 @@ public class DataStoreProviderManagerImpl extends ManagerBase implements DataSto | |||||||
|     @Inject |     @Inject | ||||||
|     PrimaryDataStoreProviderManager primaryDataStoreProviderMgr; |     PrimaryDataStoreProviderManager primaryDataStoreProviderMgr; | ||||||
|     @Inject |     @Inject | ||||||
|     ImageDataStoreProviderManager imageDataStoreProviderMgr; |     ImageStoreProviderManager imageDataStoreProviderMgr; | ||||||
|     @Override |     @Override | ||||||
|     public DataStoreProvider getDataStoreProvider(String name) { |     public DataStoreProvider getDataStoreProvider(String name) { | ||||||
|         return providerMap.get(name); |         return providerMap.get(name); | ||||||
| @ -84,7 +84,7 @@ public class DataStoreProviderManagerImpl extends ManagerBase implements DataSto | |||||||
|     public List<StorageProviderResponse> getImageDataStoreProviders() { |     public List<StorageProviderResponse> getImageDataStoreProviders() { | ||||||
|         List<StorageProviderResponse> providers = new ArrayList<StorageProviderResponse>(); |         List<StorageProviderResponse> providers = new ArrayList<StorageProviderResponse>(); | ||||||
|         for (DataStoreProvider provider : providerMap.values()) { |         for (DataStoreProvider provider : providerMap.values()) { | ||||||
|             if (provider instanceof ImageDataStoreProvider) { |             if (provider instanceof ImageStoreProvider) { | ||||||
|                 StorageProviderResponse response = new StorageProviderResponse(); |                 StorageProviderResponse response = new StorageProviderResponse(); | ||||||
|                 response.setName(provider.getName()); |                 response.setName(provider.getName()); | ||||||
|                 response.setType(DataStoreProvider.DataStoreProviderType.IMAGE.toString()); |                 response.setType(DataStoreProvider.DataStoreProviderType.IMAGE.toString()); | ||||||
| @ -123,7 +123,7 @@ public class DataStoreProviderManagerImpl extends ManagerBase implements DataSto | |||||||
|                     primaryDataStoreProviderMgr.registerHostListener(provider.getName(), provider.getHostListener()); |                     primaryDataStoreProviderMgr.registerHostListener(provider.getName(), provider.getHostListener()); | ||||||
|                 } |                 } | ||||||
|                 else if  (types.contains(DataStoreProviderType.IMAGE)) { |                 else if  (types.contains(DataStoreProviderType.IMAGE)) { | ||||||
|                     imageDataStoreProviderMgr.registerDriver(provider.getName(), (ImageDataStoreDriver)provider.getDataStoreDriver()); |                     imageDataStoreProviderMgr.registerDriver(provider.getName(), (ImageStoreDriver)provider.getDataStoreDriver()); | ||||||
|                 } |                 } | ||||||
|             } catch(Exception e) { |             } catch(Exception e) { | ||||||
|                 s_logger.debug("configure provider failed", e); |                 s_logger.debug("configure provider failed", e); | ||||||
| @ -142,7 +142,7 @@ public class DataStoreProviderManagerImpl extends ManagerBase implements DataSto | |||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public DataStoreProvider getDefaultImageDataStoreProvider() { |     public DataStoreProvider getDefaultImageDataStoreProvider() { | ||||||
|         return this.getDataStoreProvider("cloudstack image data store provider"); |         return this.getDataStoreProvider("cloudstack image store provider"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|  | |||||||
| @ -20,5 +20,5 @@ package org.apache.cloudstack.storage.image; | |||||||
| 
 | 
 | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver; | import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver; | ||||||
| 
 | 
 | ||||||
| public interface ImageDataStoreDriver extends DataStoreDriver { | public interface ImageStoreDriver extends DataStoreDriver { | ||||||
| } | } | ||||||
| @ -25,7 +25,7 @@ import java.util.Map; | |||||||
| 
 | 
 | ||||||
| import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity; | import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo; | import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo; | ||||||
| import org.apache.cloudstack.storage.image.datastore.ImageDataStoreInfo; | import org.apache.cloudstack.storage.image.datastore.ImageStoreInfo; | ||||||
| 
 | 
 | ||||||
| import com.cloud.hypervisor.Hypervisor.HypervisorType; | import com.cloud.hypervisor.Hypervisor.HypervisorType; | ||||||
| import com.cloud.storage.Storage.ImageFormat; | import com.cloud.storage.Storage.ImageFormat; | ||||||
| @ -38,12 +38,12 @@ public class TemplateEntityImpl implements TemplateEntity { | |||||||
|         this.templateInfo = templateInfo; |         this.templateInfo = templateInfo; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public ImageDataStoreInfo getImageDataStore() { |     public ImageStoreInfo getImageDataStore() { | ||||||
|         return (ImageDataStoreInfo)templateInfo.getDataStore(); |         return (ImageStoreInfo)templateInfo.getDataStore(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public long getImageDataStoreId() { |     public long getImageDataStoreId() { | ||||||
|         return getImageDataStore().getImageDataStoreId(); |         return getImageDataStore().getImageStoreId(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public TemplateInfo getTemplateInfo() { |     public TemplateInfo getTemplateInfo() { | ||||||
|  | |||||||
| @ -1,61 +0,0 @@ | |||||||
| /* |  | ||||||
|  * 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.datastore; |  | ||||||
| 
 |  | ||||||
| import java.util.Map; |  | ||||||
| 
 |  | ||||||
| import javax.inject.Inject; |  | ||||||
| 
 |  | ||||||
| import org.apache.cloudstack.storage.image.db.ImageDataStoreDao; |  | ||||||
| import org.apache.cloudstack.storage.image.db.ImageDataStoreVO; |  | ||||||
| import org.springframework.stereotype.Component; |  | ||||||
| 
 |  | ||||||
| import com.cloud.storage.ScopeType; |  | ||||||
| import com.cloud.utils.exception.CloudRuntimeException; |  | ||||||
| 
 |  | ||||||
| @Component |  | ||||||
| public class ImageDataStoreHelper { |  | ||||||
|     @Inject |  | ||||||
|     ImageDataStoreDao imageStoreDao; |  | ||||||
|     public ImageDataStoreVO createImageDataStore(Map<String, Object> params) { |  | ||||||
|         ImageDataStoreVO store = imageStoreDao.findByName((String)params.get("name")); |  | ||||||
|         if (store != null) { |  | ||||||
|             return store; |  | ||||||
|         } |  | ||||||
|         store = new ImageDataStoreVO(); |  | ||||||
|         store.setName((String)params.get("name")); |  | ||||||
|         store.setProtocol((String)params.get("protocol")); |  | ||||||
|         store.setProviderName((String)params.get("providerName")); |  | ||||||
|         store.setScope((ScopeType)params.get("scope")); |  | ||||||
|         store.setUuid((String)params.get("uuid")); |  | ||||||
|         store.setUrl((String)params.get("url")); |  | ||||||
|         store = imageStoreDao.persist(store); |  | ||||||
|         return store; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public boolean deleteImageDataStore(long id) { |  | ||||||
|         ImageDataStoreVO store = imageStoreDao.findById(id); |  | ||||||
|         if (store == null) { |  | ||||||
|             throw new CloudRuntimeException("can't find image store:" + id); |  | ||||||
|         } |  | ||||||
| 
 |  | ||||||
|         imageStoreDao.remove(id); |  | ||||||
|         return true; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -26,9 +26,9 @@ import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo; | |||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo; | import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; | import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; | ||||||
| 
 | 
 | ||||||
| import com.cloud.storage.ObjectStore; | import com.cloud.storage.ImageStore; | ||||||
| 
 | 
 | ||||||
| public interface ImageDataStore extends DataStore, ObjectStore { | public interface ImageStoreEntity extends DataStore, ImageStore { | ||||||
|     TemplateInfo getTemplate(long templateId); |     TemplateInfo getTemplate(long templateId); | ||||||
|     VolumeInfo getVolume(long volumeId); |     VolumeInfo getVolume(long volumeId); | ||||||
|     SnapshotInfo getSnapshot(long snapshotId); |     SnapshotInfo getSnapshot(long snapshotId); | ||||||
| @ -0,0 +1,99 @@ | |||||||
|  | /* | ||||||
|  |  * 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.datastore; | ||||||
|  | 
 | ||||||
|  | import java.util.Iterator; | ||||||
|  | import java.util.Map; | ||||||
|  | 
 | ||||||
|  | import javax.inject.Inject; | ||||||
|  | 
 | ||||||
|  | import org.apache.cloudstack.storage.image.db.ImageStoreDao; | ||||||
|  | import org.apache.cloudstack.storage.image.db.ImageStoreDetailVO; | ||||||
|  | import org.apache.cloudstack.storage.image.db.ImageStoreDetailsDao; | ||||||
|  | import org.apache.cloudstack.storage.image.db.ImageStoreVO; | ||||||
|  | import org.springframework.stereotype.Component; | ||||||
|  | 
 | ||||||
|  | import com.cloud.storage.ImageStore; | ||||||
|  | import com.cloud.storage.ScopeType; | ||||||
|  | import com.cloud.utils.exception.CloudRuntimeException; | ||||||
|  | 
 | ||||||
|  | @Component | ||||||
|  | public class ImageStoreHelper { | ||||||
|  |     @Inject | ||||||
|  |     ImageStoreDao imageStoreDao; | ||||||
|  |     @Inject | ||||||
|  |     ImageStoreDetailsDao imageStoreDetailsDao; | ||||||
|  | 
 | ||||||
|  |     public ImageStoreVO createImageStore(Map<String, Object> params) { | ||||||
|  |         ImageStoreVO store = imageStoreDao.findByName((String)params.get("name")); | ||||||
|  |         if (store != null) { | ||||||
|  |             return store; | ||||||
|  |         } | ||||||
|  |         store = new ImageStoreVO(); | ||||||
|  |         store.setName((String)params.get("name")); | ||||||
|  |         store.setProtocol((String)params.get("protocol")); | ||||||
|  |         store.setProviderName((String)params.get("providerName")); | ||||||
|  |         store.setScope((ScopeType)params.get("scope")); | ||||||
|  |         store.setUuid((String)params.get("uuid")); | ||||||
|  |         store.setUrl((String)params.get("url")); | ||||||
|  |         store.setState(ImageStore.State.Disabled); | ||||||
|  |         store = imageStoreDao.persist(store); | ||||||
|  |         return store; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public ImageStoreVO createImageStore(Map<String, Object> params, Map<String, String> details) { | ||||||
|  |         ImageStoreVO store = imageStoreDao.findByName((String)params.get("name")); | ||||||
|  |         if (store != null) { | ||||||
|  |             return store; | ||||||
|  |         } | ||||||
|  |         store = new ImageStoreVO(); | ||||||
|  |         store.setName((String)params.get("name")); | ||||||
|  |         store.setProtocol((String)params.get("protocol")); | ||||||
|  |         store.setProviderName((String)params.get("providerName")); | ||||||
|  |         store.setScope((ScopeType)params.get("scope")); | ||||||
|  |         store.setUuid((String)params.get("uuid")); | ||||||
|  |         store.setUrl((String)params.get("url")); | ||||||
|  |         store.setState(ImageStore.State.Disabled); | ||||||
|  |         store = imageStoreDao.persist(store); | ||||||
|  | 
 | ||||||
|  |         // persist details | ||||||
|  |         if (details != null){ | ||||||
|  |             Iterator<String> keyIter = details.keySet().iterator(); | ||||||
|  |             while (keyIter.hasNext()){ | ||||||
|  |                 String key = keyIter.next(); | ||||||
|  |                 ImageStoreDetailVO detail = new ImageStoreDetailVO(); | ||||||
|  |                 detail.setStoreId(store.getId()); | ||||||
|  |                 detail.setName(key); | ||||||
|  |                 detail.setValue(details.get(key)); | ||||||
|  |                 imageStoreDetailsDao.persist(detail); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         return store; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public boolean deleteImageStore(long id) { | ||||||
|  |         ImageStoreVO store = imageStoreDao.findById(id); | ||||||
|  |         if (store == null) { | ||||||
|  |             throw new CloudRuntimeException("can't find image store:" + id); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         imageStoreDao.remove(id); | ||||||
|  |         return true; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -20,7 +20,7 @@ package org.apache.cloudstack.storage.image.datastore; | |||||||
| 
 | 
 | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; | import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; | ||||||
| 
 | 
 | ||||||
| public interface ImageDataStoreInfo extends DataStore { | public interface ImageStoreInfo extends DataStore { | ||||||
|     public long getImageDataStoreId(); |     public long getImageStoreId(); | ||||||
|     public String getType(); |     public String getType(); | ||||||
| } | } | ||||||
| @ -21,11 +21,11 @@ package org.apache.cloudstack.storage.image.datastore; | |||||||
| import java.util.List; | import java.util.List; | ||||||
| 
 | 
 | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; | import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; | ||||||
| import org.apache.cloudstack.storage.image.ImageDataStoreDriver; | import org.apache.cloudstack.storage.image.ImageStoreDriver; | ||||||
| 
 | 
 | ||||||
| public interface ImageDataStoreProviderManager { | public interface ImageStoreProviderManager { | ||||||
|     ImageDataStore getImageDataStore(long dataStoreId); |     ImageStoreEntity getImageStore(long dataStoreId); | ||||||
|     ImageDataStore getImageDataStore(String uuid); |     ImageStoreEntity getImageStore(String uuid); | ||||||
|     List<DataStore> getList(); |     List<DataStore> getList(); | ||||||
|     boolean registerDriver(String uuid, ImageDataStoreDriver driver); |     boolean registerDriver(String uuid, ImageStoreDriver driver); | ||||||
| } | } | ||||||
| @ -1,25 +0,0 @@ | |||||||
| /* |  | ||||||
|  * 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.db; |  | ||||||
| 
 |  | ||||||
| import com.cloud.utils.db.GenericDao; |  | ||||||
| 
 |  | ||||||
| public interface ImageDataStoreProviderDao extends GenericDao<ImageDataStoreProviderVO, Long> { |  | ||||||
|     public ImageDataStoreProviderVO findByName(String name); |  | ||||||
| } |  | ||||||
| @ -1,40 +0,0 @@ | |||||||
| /* |  | ||||||
|  * 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.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 |  | ||||||
| public class ImageDataStoreProviderDaoImpl extends GenericDaoBase<ImageDataStoreProviderVO, Long> implements ImageDataStoreProviderDao { |  | ||||||
| 
 |  | ||||||
| 	public ImageDataStoreProviderDaoImpl() { |  | ||||||
| 	} |  | ||||||
| 	 |  | ||||||
| 	@Override |  | ||||||
|     public ImageDataStoreProviderVO findByName(String name) { |  | ||||||
|         SearchCriteriaService<ImageDataStoreProviderVO, ImageDataStoreProviderVO> service = SearchCriteria2.create(ImageDataStoreProviderVO.class); |  | ||||||
|         service.addAnd(service.getEntity().getName(), Op.EQ, name); |  | ||||||
|         return service.find(); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -1,49 +0,0 @@ | |||||||
| /* |  | ||||||
|  * 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.db; |  | ||||||
| 
 |  | ||||||
| import javax.persistence.Column; |  | ||||||
| import javax.persistence.Entity; |  | ||||||
| import javax.persistence.Id; |  | ||||||
| import javax.persistence.Table; |  | ||||||
| import javax.persistence.TableGenerator; |  | ||||||
| 
 |  | ||||||
| @Entity |  | ||||||
| @Table(name = "image_data_store_provider") |  | ||||||
| public class ImageDataStoreProviderVO { |  | ||||||
|     @Id |  | ||||||
|     @TableGenerator(name = "image_data_store_provider_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "image_data_store_provider_seq", allocationSize = 1) |  | ||||||
|     @Column(name = "id", nullable = false) |  | ||||||
|     private long id; |  | ||||||
| 
 |  | ||||||
|     @Column(name = "name", nullable = false) |  | ||||||
|     private String name; |  | ||||||
| 
 |  | ||||||
|     public long getId() { |  | ||||||
|         return this.id; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public String getName() { |  | ||||||
|         return this.name; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public void setName(String name) { |  | ||||||
|         this.name = name; |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @ -20,6 +20,6 @@ package org.apache.cloudstack.storage.image.db; | |||||||
| 
 | 
 | ||||||
| import com.cloud.utils.db.GenericDao; | import com.cloud.utils.db.GenericDao; | ||||||
| 
 | 
 | ||||||
| public interface ImageDataStoreDao extends GenericDao<ImageDataStoreVO, Long> { | public interface ImageStoreDao extends GenericDao<ImageStoreVO, Long> { | ||||||
|     public ImageDataStoreVO findByName(String name); |     public ImageStoreVO findByName(String name); | ||||||
| } | } | ||||||
| @ -26,11 +26,11 @@ import com.cloud.utils.db.SearchCriteriaService; | |||||||
| import com.cloud.utils.db.SearchCriteria.Op; | import com.cloud.utils.db.SearchCriteria.Op; | ||||||
| 
 | 
 | ||||||
| @Component | @Component | ||||||
| public class ImageDaoStoreDaoImpl extends GenericDaoBase<ImageDataStoreVO, Long> implements ImageDataStoreDao { | public class ImageStoreDaoImpl extends GenericDaoBase<ImageStoreVO, Long> implements ImageStoreDao { | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public ImageDataStoreVO findByName(String name) { |     public ImageStoreVO findByName(String name) { | ||||||
|         SearchCriteriaService<ImageDataStoreVO, ImageDataStoreVO> sc =  SearchCriteria2.create(ImageDataStoreVO.class); |         SearchCriteriaService<ImageStoreVO, ImageStoreVO> sc =  SearchCriteria2.create(ImageStoreVO.class); | ||||||
|         sc.addAnd(sc.getEntity().getName(), Op.EQ, name); |         sc.addAnd(sc.getEntity().getName(), Op.EQ, name); | ||||||
|         return sc.find(); |         return sc.find(); | ||||||
|     } |     } | ||||||
| @ -14,7 +14,7 @@ | |||||||
| // KIND, either express or implied.  See the License for the | // KIND, either express or implied.  See the License for the | ||||||
| // specific language governing permissions and limitations | // specific language governing permissions and limitations | ||||||
| // under the License. | // under the License. | ||||||
| package org.apache.cloudstack.storage.datastore.db; | package org.apache.cloudstack.storage.image.db; | ||||||
| 
 | 
 | ||||||
| import org.apache.cloudstack.api.InternalIdentity; | import org.apache.cloudstack.api.InternalIdentity; | ||||||
| 
 | 
 | ||||||
| @ -26,8 +26,8 @@ import javax.persistence.Id; | |||||||
| import javax.persistence.Table; | import javax.persistence.Table; | ||||||
| 
 | 
 | ||||||
| @Entity | @Entity | ||||||
| @Table(name="image_data_store_details") | @Table(name="image_store_details") | ||||||
| public class ImageDataStoreDetailVO implements InternalIdentity { | public class ImageStoreDetailVO implements InternalIdentity { | ||||||
|     @Id |     @Id | ||||||
|     @GeneratedValue(strategy=GenerationType.IDENTITY) |     @GeneratedValue(strategy=GenerationType.IDENTITY) | ||||||
|     @Column(name="id") |     @Column(name="id") | ||||||
| @ -42,7 +42,10 @@ public class ImageDataStoreDetailVO implements InternalIdentity { | |||||||
|     @Column(name="value") |     @Column(name="value") | ||||||
|     String value; |     String value; | ||||||
| 
 | 
 | ||||||
|     public ImageDataStoreDetailVO(long storeId, String name, String value) { |     public ImageStoreDetailVO() { | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public ImageStoreDetailVO(long storeId, String name, String value) { | ||||||
|         this.storeId = storeId; |         this.storeId = storeId; | ||||||
|         this.name = name; |         this.name = name; | ||||||
|         this.value = value; |         this.value = value; | ||||||
| @ -76,6 +79,5 @@ public class ImageDataStoreDetailVO implements InternalIdentity { | |||||||
|         this.value = value; |         this.value = value; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     protected ImageDataStoreDetailVO() { | 
 | ||||||
|     } |  | ||||||
| } | } | ||||||
| @ -14,14 +14,14 @@ | |||||||
| // KIND, either express or implied.  See the License for the | // KIND, either express or implied.  See the License for the | ||||||
| // specific language governing permissions and limitations | // specific language governing permissions and limitations | ||||||
| // under the License. | // under the License. | ||||||
| package org.apache.cloudstack.storage.datastore.db; | package org.apache.cloudstack.storage.image.db; | ||||||
| 
 | 
 | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| import com.cloud.utils.db.GenericDao; | import com.cloud.utils.db.GenericDao; | ||||||
| 
 | 
 | ||||||
| public interface ImageDataStoreDetailsDao extends GenericDao<ImageDataStoreDetailVO, Long> { | public interface ImageStoreDetailsDao extends GenericDao<ImageStoreDetailVO, Long> { | ||||||
| 
 | 
 | ||||||
|     void update(long storeId, Map<String, String> details); |     void update(long storeId, Map<String, String> details); | ||||||
|     Map<String, String> getDetails(long storeId); |     Map<String, String> getDetails(long storeId); | ||||||
| @ -14,7 +14,7 @@ | |||||||
| // KIND, either express or implied.  See the License for the | // KIND, either express or implied.  See the License for the | ||||||
| // specific language governing permissions and limitations | // specific language governing permissions and limitations | ||||||
| // under the License. | // under the License. | ||||||
| package com.cloud.storage.dao; | package org.apache.cloudstack.storage.image.db; | ||||||
| 
 | 
 | ||||||
| import java.util.HashMap; | import java.util.HashMap; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| @ -22,8 +22,6 @@ import java.util.Map; | |||||||
| 
 | 
 | ||||||
| import javax.ejb.Local; | import javax.ejb.Local; | ||||||
| 
 | 
 | ||||||
| import org.apache.cloudstack.storage.datastore.db.ImageDataStoreDetailVO; |  | ||||||
| import org.apache.cloudstack.storage.datastore.db.ImageDataStoreDetailsDao; |  | ||||||
| import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||||
| 
 | 
 | ||||||
| import com.cloud.utils.db.GenericDaoBase; | import com.cloud.utils.db.GenericDaoBase; | ||||||
| @ -32,12 +30,12 @@ import com.cloud.utils.db.SearchCriteria; | |||||||
| import com.cloud.utils.db.Transaction; | import com.cloud.utils.db.Transaction; | ||||||
| 
 | 
 | ||||||
| @Component | @Component | ||||||
| @Local(value=ImageDataStoreDetailsDao.class) | @Local(value=ImageStoreDetailsDao.class) | ||||||
| public class ImageDataStoreDaoImpl extends GenericDaoBase<ImageDataStoreDetailVO, Long> implements ImageDataStoreDetailsDao { | public class ImageStoreDetailsDaoImpl extends GenericDaoBase<ImageStoreDetailVO, Long> implements ImageStoreDetailsDao { | ||||||
| 
 | 
 | ||||||
|     protected final SearchBuilder<ImageDataStoreDetailVO> storeSearch; |     protected final SearchBuilder<ImageStoreDetailVO> storeSearch; | ||||||
| 
 | 
 | ||||||
|     protected ImageDataStoreDaoImpl() { |     protected ImageStoreDetailsDaoImpl() { | ||||||
|         super(); |         super(); | ||||||
|         storeSearch = createSearchBuilder(); |         storeSearch = createSearchBuilder(); | ||||||
|         storeSearch.and("store", storeSearch.entity().getStoreId(), SearchCriteria.Op.EQ); |         storeSearch.and("store", storeSearch.entity().getStoreId(), SearchCriteria.Op.EQ); | ||||||
| @ -47,13 +45,13 @@ public class ImageDataStoreDaoImpl extends GenericDaoBase<ImageDataStoreDetailVO | |||||||
|     @Override |     @Override | ||||||
|     public void update(long storeId, Map<String, String> details) { |     public void update(long storeId, Map<String, String> details) { | ||||||
|         Transaction txn = Transaction.currentTxn(); |         Transaction txn = Transaction.currentTxn(); | ||||||
|         SearchCriteria<ImageDataStoreDetailVO> sc = storeSearch.create(); |         SearchCriteria<ImageStoreDetailVO> sc = storeSearch.create(); | ||||||
|         sc.setParameters("store", storeId); |         sc.setParameters("store", storeId); | ||||||
| 
 | 
 | ||||||
|         txn.start(); |         txn.start(); | ||||||
|         expunge(sc); |         expunge(sc); | ||||||
|         for (Map.Entry<String, String> entry : details.entrySet()) { |         for (Map.Entry<String, String> entry : details.entrySet()) { | ||||||
|             ImageDataStoreDetailVO detail = new ImageDataStoreDetailVO(storeId, entry.getKey(), entry.getValue()); |             ImageStoreDetailVO detail = new ImageStoreDetailVO(storeId, entry.getKey(), entry.getValue()); | ||||||
|             persist(detail); |             persist(detail); | ||||||
|         } |         } | ||||||
|         txn.commit(); |         txn.commit(); | ||||||
| @ -61,12 +59,12 @@ public class ImageDataStoreDaoImpl extends GenericDaoBase<ImageDataStoreDetailVO | |||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public Map<String, String> getDetails(long storeId) { |     public Map<String, String> getDetails(long storeId) { | ||||||
|     	SearchCriteria<ImageDataStoreDetailVO> sc = storeSearch.create(); |     	SearchCriteria<ImageStoreDetailVO> sc = storeSearch.create(); | ||||||
|     	sc.setParameters("store", storeId); |     	sc.setParameters("store", storeId); | ||||||
| 
 | 
 | ||||||
|     	List<ImageDataStoreDetailVO> details = listBy(sc); |     	List<ImageStoreDetailVO> details = listBy(sc); | ||||||
|     	Map<String, String> detailsMap = new HashMap<String, String>(); |     	Map<String, String> detailsMap = new HashMap<String, String>(); | ||||||
|     	for (ImageDataStoreDetailVO detail : details) { |     	for (ImageStoreDetailVO detail : details) { | ||||||
|     		detailsMap.put(detail.getName(), detail.getValue()); |     		detailsMap.put(detail.getName(), detail.getValue()); | ||||||
|     	} |     	} | ||||||
| 
 | 
 | ||||||
| @ -18,6 +18,8 @@ | |||||||
|  */ |  */ | ||||||
| package org.apache.cloudstack.storage.image.db; | package org.apache.cloudstack.storage.image.db; | ||||||
| 
 | 
 | ||||||
|  | import java.util.Date; | ||||||
|  | 
 | ||||||
| import javax.persistence.Column; | import javax.persistence.Column; | ||||||
| import javax.persistence.Entity; | import javax.persistence.Entity; | ||||||
| import javax.persistence.EnumType; | import javax.persistence.EnumType; | ||||||
| @ -27,14 +29,16 @@ import javax.persistence.Table; | |||||||
| import javax.persistence.TableGenerator; | import javax.persistence.TableGenerator; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| import com.cloud.storage.ObjectStore; | 
 | ||||||
|  | import com.cloud.storage.ImageStore; | ||||||
| import com.cloud.storage.ScopeType; | import com.cloud.storage.ScopeType; | ||||||
|  | import com.cloud.utils.db.GenericDao; | ||||||
| 
 | 
 | ||||||
| @Entity | @Entity | ||||||
| @Table(name = "image_data_store") | @Table(name = "image_store") | ||||||
| public class ImageDataStoreVO implements ObjectStore { | public class ImageStoreVO implements ImageStore { | ||||||
|     @Id |     @Id | ||||||
|     @TableGenerator(name = "image_data_store_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "image_data_store_seq", allocationSize = 1) |     @TableGenerator(name = "image_store_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "image_store_seq", allocationSize = 1) | ||||||
|     @Column(name = "id", nullable = false) |     @Column(name = "id", nullable = false) | ||||||
|     private long id; |     private long id; | ||||||
| 
 | 
 | ||||||
| @ -56,13 +60,19 @@ public class ImageDataStoreVO implements ObjectStore { | |||||||
|     @Column(name = "data_center_id") |     @Column(name = "data_center_id") | ||||||
|     private long dcId; |     private long dcId; | ||||||
| 
 | 
 | ||||||
|     @Column(name = "region_id") |     @Column(name = "state") | ||||||
|     private long regionId; |     @Enumerated(value = EnumType.STRING) | ||||||
|  |     private State state; | ||||||
| 
 | 
 | ||||||
|     @Column(name = "scope") |     @Column(name = "scope") | ||||||
|     @Enumerated(value = EnumType.STRING) |     @Enumerated(value = EnumType.STRING) | ||||||
|     private ScopeType scope; |     private ScopeType scope; | ||||||
| 
 | 
 | ||||||
|  |     @Column(name=GenericDao.CREATED_COLUMN) | ||||||
|  |     private Date created; | ||||||
|  | 
 | ||||||
|  |     @Column(name=GenericDao.REMOVED_COLUMN) | ||||||
|  |     private Date removed; | ||||||
| 
 | 
 | ||||||
|     public long getId() { |     public long getId() { | ||||||
|         return this.id; |         return this.id; | ||||||
| @ -100,15 +110,6 @@ public class ImageDataStoreVO implements ObjectStore { | |||||||
|         return this.dcId; |         return this.dcId; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|     public Long getRegionId() { |  | ||||||
|         return regionId; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public void setRegionId(long regionId) { |  | ||||||
|         this.regionId = regionId; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public ScopeType getScope() { |     public ScopeType getScope() { | ||||||
|         return this.scope; |         return this.scope; | ||||||
|     } |     } | ||||||
| @ -133,5 +134,30 @@ public class ImageDataStoreVO implements ObjectStore { | |||||||
|         this.url = url; |         this.url = url; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     public Date getCreated() { | ||||||
|  |         return created; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setCreated(Date created) { | ||||||
|  |         this.created = created; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public Date getRemoved() { | ||||||
|  |         return removed; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setRemoved(Date removed) { | ||||||
|  |         this.removed = removed; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public State getState() { | ||||||
|  |         return state; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void setState(State state) { | ||||||
|  |         this.state = state; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
| @ -16,12 +16,12 @@ | |||||||
| // under the License. | // under the License. | ||||||
| package org.apache.cloudstack.storage.to; | package org.apache.cloudstack.storage.to; | ||||||
| 
 | 
 | ||||||
| import org.apache.cloudstack.storage.image.datastore.ImageDataStoreInfo; | import org.apache.cloudstack.storage.image.datastore.ImageStoreInfo; | ||||||
| 
 | 
 | ||||||
| public class ImageDataStoreTO { | public class ImageStoreTO { | ||||||
|     private final String type; |     private final String type; | ||||||
|     private final String uri; |     private final String uri; | ||||||
|     public ImageDataStoreTO(ImageDataStoreInfo dataStore) { |     public ImageStoreTO(ImageStoreInfo dataStore) { | ||||||
|         this.type = dataStore.getType(); |         this.type = dataStore.getType(); | ||||||
|         this.uri = dataStore.getUri(); |         this.uri = dataStore.getUri(); | ||||||
|     } |     } | ||||||
| @ -18,19 +18,19 @@ package org.apache.cloudstack.storage.to; | |||||||
| 
 | 
 | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo; | import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.disktype.DiskFormat; | import org.apache.cloudstack.engine.subsystem.api.storage.disktype.DiskFormat; | ||||||
| import org.apache.cloudstack.storage.image.datastore.ImageDataStoreInfo; | import org.apache.cloudstack.storage.image.datastore.ImageStoreInfo; | ||||||
| 
 | 
 | ||||||
| public class TemplateTO { | public class TemplateTO { | ||||||
|     private final String path; |     private final String path; | ||||||
|     private final String uuid; |     private final String uuid; | ||||||
|     private  DiskFormat diskType; |     private  DiskFormat diskType; | ||||||
|     private final ImageDataStoreTO imageDataStore; |     private final ImageStoreTO imageDataStore; | ||||||
| 
 | 
 | ||||||
|     public TemplateTO(TemplateInfo template) { |     public TemplateTO(TemplateInfo template) { | ||||||
|         this.path = null; |         this.path = null; | ||||||
|         this.uuid = template.getUuid(); |         this.uuid = template.getUuid(); | ||||||
|         //this.diskType = template.getDiskType(); |         //this.diskType = template.getDiskType(); | ||||||
|         this.imageDataStore = new ImageDataStoreTO((ImageDataStoreInfo)template.getDataStore()); |         this.imageDataStore = new ImageStoreTO((ImageStoreInfo)template.getDataStore()); | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     public String getPath() { |     public String getPath() { | ||||||
| @ -45,7 +45,7 @@ public class TemplateTO { | |||||||
|         return this.diskType; |         return this.diskType; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     public ImageDataStoreTO getImageDataStore() { |     public ImageStoreTO getImageDataStore() { | ||||||
|         return this.imageDataStore; |         return this.imageDataStore; | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -58,6 +58,7 @@ | |||||||
|     <module>user-authenticators/sha256salted</module> |     <module>user-authenticators/sha256salted</module> | ||||||
|     <module>network-elements/dns-notifier</module> |     <module>network-elements/dns-notifier</module> | ||||||
|     <module>storage/image/s3</module> |     <module>storage/image/s3</module> | ||||||
|  |     <module>storage/image/swift</module> | ||||||
|     <module>storage/image/default</module> |     <module>storage/image/default</module> | ||||||
|     <module>storage/image/sample</module>     |     <module>storage/image/sample</module>     | ||||||
|     <module>storage/volume/solidfire</module> |     <module>storage/volume/solidfire</module> | ||||||
|  | |||||||
| @ -33,7 +33,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint; | |||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; | import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; | ||||||
| import org.apache.cloudstack.framework.async.AsyncCompletionCallback; | import org.apache.cloudstack.framework.async.AsyncCompletionCallback; | ||||||
| import org.apache.cloudstack.framework.async.AsyncRpcConext; | import org.apache.cloudstack.framework.async.AsyncRpcConext; | ||||||
| import org.apache.cloudstack.storage.image.ImageDataStoreDriver; | import org.apache.cloudstack.storage.image.ImageStoreDriver; | ||||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||||
| 
 | 
 | ||||||
| import com.cloud.agent.AgentManager; | import com.cloud.agent.AgentManager; | ||||||
| @ -64,9 +64,9 @@ import com.cloud.storage.snapshot.SnapshotManager; | |||||||
| import com.cloud.storage.swift.SwiftManager; | import com.cloud.storage.swift.SwiftManager; | ||||||
| import com.cloud.utils.exception.CloudRuntimeException; | import com.cloud.utils.exception.CloudRuntimeException; | ||||||
| 
 | 
 | ||||||
| public class CloudStackImageDataStoreDriverImpl implements ImageDataStoreDriver { | public class CloudStackImageStoreDriverImpl implements ImageStoreDriver { | ||||||
|     private static final Logger s_logger = Logger |     private static final Logger s_logger = Logger | ||||||
|             .getLogger(CloudStackImageDataStoreDriverImpl.class); |             .getLogger(CloudStackImageStoreDriverImpl.class); | ||||||
|     @Inject |     @Inject | ||||||
|     VMTemplateZoneDao templateZoneDao; |     VMTemplateZoneDao templateZoneDao; | ||||||
|     @Inject |     @Inject | ||||||
| @ -29,11 +29,11 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope; | |||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; | import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.HostScope; | import org.apache.cloudstack.engine.subsystem.api.storage.HostScope; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope; | import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope; | ||||||
| import org.apache.cloudstack.storage.image.datastore.ImageDataStoreHelper; | import org.apache.cloudstack.storage.image.datastore.ImageStoreHelper; | ||||||
| import org.apache.cloudstack.storage.image.datastore.ImageDataStoreProviderManager; | import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager; | ||||||
| import org.apache.cloudstack.storage.image.db.ImageDataStoreDao; | import org.apache.cloudstack.storage.image.db.ImageStoreDao; | ||||||
| import org.apache.cloudstack.storage.image.db.ImageDataStoreVO; | import org.apache.cloudstack.storage.image.db.ImageStoreVO; | ||||||
| import org.apache.cloudstack.storage.image.store.lifecycle.ImageDataStoreLifeCycle; | import org.apache.cloudstack.storage.image.store.lifecycle.ImageStoreLifeCycle; | ||||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||||
| 
 | 
 | ||||||
| import com.cloud.agent.api.StoragePoolInfo; | import com.cloud.agent.api.StoragePoolInfo; | ||||||
| @ -49,18 +49,18 @@ import com.cloud.resource.ServerResource; | |||||||
| import com.cloud.storage.ScopeType; | import com.cloud.storage.ScopeType; | ||||||
| import com.cloud.utils.UriUtils; | import com.cloud.utils.UriUtils; | ||||||
| 
 | 
 | ||||||
| public class CloudStackImageDataStoreLifeCycle implements ImageDataStoreLifeCycle { | public class CloudStackImageStoreLifeCycleImpl implements ImageStoreLifeCycle { | ||||||
| 
 | 
 | ||||||
|     private static final Logger s_logger = Logger |     private static final Logger s_logger = Logger | ||||||
|             .getLogger(CloudStackImageDataStoreLifeCycle.class); |             .getLogger(CloudStackImageStoreLifeCycleImpl.class); | ||||||
|     @Inject |     @Inject | ||||||
|     protected ResourceManager _resourceMgr; |     protected ResourceManager _resourceMgr; | ||||||
|     @Inject |     @Inject | ||||||
| 	protected ImageDataStoreDao imageStoreDao; | 	protected ImageStoreDao imageStoreDao; | ||||||
| 	@Inject | 	@Inject | ||||||
| 	ImageDataStoreHelper imageStoreHelper; | 	ImageStoreHelper imageStoreHelper; | ||||||
| 	@Inject | 	@Inject | ||||||
| 	ImageDataStoreProviderManager imageStoreMgr; | 	ImageStoreProviderManager imageStoreMgr; | ||||||
| 
 | 
 | ||||||
|     protected List<? extends Discoverer> _discoverers; |     protected List<? extends Discoverer> _discoverers; | ||||||
|     public List<? extends Discoverer> getDiscoverers() { |     public List<? extends Discoverer> getDiscoverers() { | ||||||
| @ -70,7 +70,7 @@ public class CloudStackImageDataStoreLifeCycle implements ImageDataStoreLifeCycl | |||||||
|         this._discoverers = _discoverers; |         this._discoverers = _discoverers; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 	public CloudStackImageDataStoreLifeCycle() { | 	public CloudStackImageStoreLifeCycleImpl() { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -80,6 +80,7 @@ public class CloudStackImageDataStoreLifeCycle implements ImageDataStoreLifeCycl | |||||||
|         Long dcId = (Long) dsInfos.get("zoneId"); |         Long dcId = (Long) dsInfos.get("zoneId"); | ||||||
|         String url = (String) dsInfos.get("url"); |         String url = (String) dsInfos.get("url"); | ||||||
|         String providerName = (String)dsInfos.get("providerName"); |         String providerName = (String)dsInfos.get("providerName"); | ||||||
|  |         Map<String, String> details = (Map<String, String>)dsInfos.get("details"); | ||||||
| 
 | 
 | ||||||
|         s_logger.info("Trying to add a new host at " + url + " in data center " + dcId); |         s_logger.info("Trying to add a new host at " + url + " in data center " + dcId); | ||||||
| 
 | 
 | ||||||
| @ -112,11 +113,11 @@ public class CloudStackImageDataStoreLifeCycle implements ImageDataStoreLifeCycl | |||||||
|         imageStoreParameters.put("zoneId", dcId); |         imageStoreParameters.put("zoneId", dcId); | ||||||
|         imageStoreParameters.put("url", url); |         imageStoreParameters.put("url", url); | ||||||
|         imageStoreParameters.put("protocol", uri.getScheme().toLowerCase()); |         imageStoreParameters.put("protocol", uri.getScheme().toLowerCase()); | ||||||
|         imageStoreParameters.put("scope", ScopeType.ZONE); |         imageStoreParameters.put("scope", ScopeType.ZONE);  // default cloudstack provider only supports zone-wide image store | ||||||
|         imageStoreParameters.put("providerName", providerName); |         imageStoreParameters.put("providerName", providerName); | ||||||
| 
 | 
 | ||||||
|         ImageDataStoreVO ids = imageStoreHelper.createImageDataStore(imageStoreParameters); |         ImageStoreVO ids = imageStoreHelper.createImageStore(imageStoreParameters, details); | ||||||
|         return imageStoreMgr.getImageDataStore(ids.getId()); |         return imageStoreMgr.getImageStore(ids.getId()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -18,39 +18,35 @@ | |||||||
|  */ |  */ | ||||||
| package org.apache.cloudstack.storage.datastore.provider; | package org.apache.cloudstack.storage.datastore.provider; | ||||||
| 
 | 
 | ||||||
| import java.util.HashMap; |  | ||||||
| import java.util.HashSet; | import java.util.HashSet; | ||||||
| import java.util.Map; | import java.util.Map; | ||||||
| import java.util.Set; | import java.util.Set; | ||||||
| import java.util.UUID; |  | ||||||
| 
 |  | ||||||
| import javax.inject.Inject; | import javax.inject.Inject; | ||||||
| 
 | 
 | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver; | import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle; | import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener; | import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.ImageDataStoreProvider; | import org.apache.cloudstack.engine.subsystem.api.storage.ImageStoreProvider; | ||||||
| import org.apache.cloudstack.storage.datastore.driver.CloudStackImageDataStoreDriverImpl; | import org.apache.cloudstack.storage.datastore.driver.CloudStackImageStoreDriverImpl; | ||||||
| import org.apache.cloudstack.storage.datastore.lifecycle.CloudStackImageDataStoreLifeCycle; | import org.apache.cloudstack.storage.datastore.lifecycle.CloudStackImageStoreLifeCycleImpl; | ||||||
| import org.apache.cloudstack.storage.image.ImageDataStoreDriver; | import org.apache.cloudstack.storage.image.ImageStoreDriver; | ||||||
| import org.apache.cloudstack.storage.image.datastore.ImageDataStoreHelper; | import org.apache.cloudstack.storage.image.datastore.ImageStoreHelper; | ||||||
| import org.apache.cloudstack.storage.image.datastore.ImageDataStoreProviderManager; | import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager; | ||||||
| import org.apache.cloudstack.storage.image.store.lifecycle.ImageDataStoreLifeCycle; | import org.apache.cloudstack.storage.image.store.lifecycle.ImageStoreLifeCycle; | ||||||
| import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||||
| 
 | 
 | ||||||
| import com.cloud.storage.ScopeType; |  | ||||||
| import com.cloud.utils.component.ComponentContext; | import com.cloud.utils.component.ComponentContext; | ||||||
| 
 | 
 | ||||||
| @Component | @Component | ||||||
| public class CloudStackImageDataStoreProvider implements ImageDataStoreProvider { | public class CloudStackImageStoreProviderImpl implements ImageStoreProvider { | ||||||
| 
 | 
 | ||||||
|     private final String name = "cloudstack image data store provider"; |     private final String providerName = "cloudstack image store provider"; | ||||||
|     protected ImageDataStoreLifeCycle lifeCycle; |     protected ImageStoreLifeCycle lifeCycle; | ||||||
|     protected ImageDataStoreDriver driver; |     protected ImageStoreDriver driver; | ||||||
|     @Inject |     @Inject | ||||||
|     ImageDataStoreProviderManager storeMgr; |     ImageStoreProviderManager storeMgr; | ||||||
|     @Inject |     @Inject | ||||||
|     ImageDataStoreHelper helper; |     ImageStoreHelper helper; | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public DataStoreLifeCycle getDataStoreLifeCycle() { |     public DataStoreLifeCycle getDataStoreLifeCycle() { | ||||||
| @ -59,25 +55,16 @@ public class CloudStackImageDataStoreProvider implements ImageDataStoreProvider | |||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public String getName() { |     public String getName() { | ||||||
|         return this.name; |         return this.providerName; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public boolean configure(Map<String, Object> params) { |     public boolean configure(Map<String, Object> params) { | ||||||
|         lifeCycle = ComponentContext.inject(CloudStackImageDataStoreLifeCycle.class); |         lifeCycle = ComponentContext.inject(CloudStackImageStoreLifeCycleImpl.class); | ||||||
|         driver = ComponentContext.inject(CloudStackImageDataStoreDriverImpl.class); |         driver = ComponentContext.inject(CloudStackImageStoreDriverImpl.class); | ||||||
| 
 | 
 | ||||||
|         storeMgr.registerDriver(this.getName(), driver); |         storeMgr.registerDriver(this.getName(), driver); | ||||||
| 
 | 
 | ||||||
|         Map<String, Object> infos = new HashMap<String, Object>(); |  | ||||||
|         String dataStoreName = UUID.nameUUIDFromBytes(this.name.getBytes()).toString(); |  | ||||||
|         infos.put("name", dataStoreName); |  | ||||||
|         infos.put("uuid", dataStoreName); |  | ||||||
|         infos.put("protocol", "http"); |  | ||||||
|         infos.put("scope", ScopeType.GLOBAL); |  | ||||||
|         infos.put("providerName", this.getName()); |  | ||||||
|         DataStoreLifeCycle lifeCycle = this.getDataStoreLifeCycle(); |  | ||||||
|         lifeCycle.initialize(infos); |  | ||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -0,0 +1,250 @@ | |||||||
|  | /* | ||||||
|  |  * 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.driver; | ||||||
|  | 
 | ||||||
|  | import java.util.List; | ||||||
|  | import java.util.Set; | ||||||
|  | 
 | ||||||
|  | import javax.inject.Inject; | ||||||
|  | 
 | ||||||
|  | import org.apache.cloudstack.engine.subsystem.api.storage.CommandResult; | ||||||
|  | import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult; | ||||||
|  | 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.DataObjectType; | ||||||
|  | import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; | ||||||
|  | import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint; | ||||||
|  | import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; | ||||||
|  | import org.apache.cloudstack.framework.async.AsyncCompletionCallback; | ||||||
|  | import org.apache.cloudstack.framework.async.AsyncRpcConext; | ||||||
|  | import org.apache.cloudstack.storage.image.ImageStoreDriver; | ||||||
|  | import org.apache.log4j.Logger; | ||||||
|  | 
 | ||||||
|  | import com.cloud.agent.AgentManager; | ||||||
|  | import com.cloud.agent.api.Answer; | ||||||
|  | import com.cloud.agent.api.DeleteSnapshotBackupCommand; | ||||||
|  | import com.cloud.agent.api.storage.DeleteVolumeCommand; | ||||||
|  | import com.cloud.agent.api.to.S3TO; | ||||||
|  | import com.cloud.agent.api.to.SwiftTO; | ||||||
|  | import com.cloud.host.HostVO; | ||||||
|  | import com.cloud.host.dao.HostDao; | ||||||
|  | import com.cloud.storage.RegisterVolumePayload; | ||||||
|  | import com.cloud.storage.Storage.ImageFormat; | ||||||
|  | import com.cloud.storage.SnapshotVO; | ||||||
|  | import com.cloud.storage.VMTemplateStorageResourceAssoc; | ||||||
|  | import com.cloud.storage.VMTemplateVO; | ||||||
|  | import com.cloud.storage.VMTemplateZoneVO; | ||||||
|  | import com.cloud.storage.VolumeHostVO; | ||||||
|  | import com.cloud.storage.VolumeVO; | ||||||
|  | import com.cloud.storage.dao.SnapshotDao; | ||||||
|  | import com.cloud.storage.dao.VMTemplateDao; | ||||||
|  | import com.cloud.storage.dao.VMTemplateHostDao; | ||||||
|  | import com.cloud.storage.dao.VMTemplateZoneDao; | ||||||
|  | import com.cloud.storage.dao.VolumeDao; | ||||||
|  | import com.cloud.storage.dao.VolumeHostDao; | ||||||
|  | import com.cloud.storage.download.DownloadMonitor; | ||||||
|  | import com.cloud.storage.s3.S3Manager; | ||||||
|  | import com.cloud.storage.snapshot.SnapshotManager; | ||||||
|  | import com.cloud.storage.swift.SwiftManager; | ||||||
|  | import com.cloud.utils.exception.CloudRuntimeException; | ||||||
|  | 
 | ||||||
|  | public class S3ImageStoreDriverImpl implements ImageStoreDriver { | ||||||
|  |     private static final Logger s_logger = Logger | ||||||
|  |             .getLogger(S3ImageStoreDriverImpl.class); | ||||||
|  |     @Inject | ||||||
|  |     VMTemplateZoneDao templateZoneDao; | ||||||
|  |     @Inject | ||||||
|  |     VMTemplateDao templateDao; | ||||||
|  |     @Inject DownloadMonitor _downloadMonitor; | ||||||
|  |     @Inject  | ||||||
|  |     VMTemplateHostDao _vmTemplateHostDao; | ||||||
|  |     @Inject VolumeDao volumeDao; | ||||||
|  |     @Inject VolumeHostDao volumeHostDao; | ||||||
|  |     @Inject HostDao hostDao; | ||||||
|  |     @Inject SnapshotDao snapshotDao; | ||||||
|  |     @Inject AgentManager agentMgr; | ||||||
|  |     @Inject SnapshotManager snapshotMgr; | ||||||
|  | 	@Inject | ||||||
|  |     private SwiftManager _swiftMgr; | ||||||
|  |     @Inject  | ||||||
|  |     private S3Manager _s3Mgr;  | ||||||
|  |     @Override | ||||||
|  |     public String grantAccess(DataObject data, EndPoint ep) { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public boolean revokeAccess(DataObject data, EndPoint ep) { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public Set<DataObject> listObjects(DataStore store) { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     class CreateContext<T> extends AsyncRpcConext<T> { | ||||||
|  |         final DataObject data; | ||||||
|  |         public CreateContext(AsyncCompletionCallback<T> callback, DataObject data) { | ||||||
|  |             super(callback); | ||||||
|  |             this.data = data; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     @Override | ||||||
|  |     public void createAsync(DataObject data, | ||||||
|  |             AsyncCompletionCallback<CreateCmdResult> callback) { | ||||||
|  |         if (data.getType() == DataObjectType.TEMPLATE) { | ||||||
|  |             List<VMTemplateZoneVO> templateZones = this.templateZoneDao.listByTemplateId(data.getId()); | ||||||
|  |             for (VMTemplateZoneVO templateZone : templateZones) { | ||||||
|  |                 VMTemplateVO template = this.templateDao.findById(data.getId()); | ||||||
|  |                 _downloadMonitor.downloadTemplateToStorage(template, templateZone.getZoneId()); | ||||||
|  |             } | ||||||
|  |         } else if (data.getType() == DataObjectType.VOLUME) { | ||||||
|  |             VolumeVO vol = this.volumeDao.findById(data.getId()); | ||||||
|  |             VolumeInfo volInfo = (VolumeInfo)data; | ||||||
|  |             RegisterVolumePayload payload = (RegisterVolumePayload)volInfo.getpayload(); | ||||||
|  |             _downloadMonitor.downloadVolumeToStorage(vol, vol.getDataCenterId(), payload.getUrl(), | ||||||
|  |                     payload.getChecksum(), ImageFormat.valueOf(payload.getFormat().toUpperCase())); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         CreateCmdResult result = new CreateCmdResult(null, null); | ||||||
|  |         callback.complete(result); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     private void deleteVolume(DataObject data, AsyncCompletionCallback<CommandResult> callback) { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  |         VolumeVO vol = volumeDao.findById(data.getId()); | ||||||
|  |         if (s_logger.isDebugEnabled()) { | ||||||
|  |             s_logger.debug("Expunging " + vol); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         // Find out if the volume is present on secondary storage | ||||||
|  |         VolumeHostVO volumeHost = volumeHostDao.findByVolumeId(vol.getId()); | ||||||
|  |         if (volumeHost != null) { | ||||||
|  |             if (volumeHost.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) { | ||||||
|  |                 HostVO ssHost = hostDao.findById(volumeHost.getHostId()); | ||||||
|  |                 DeleteVolumeCommand dtCommand = new DeleteVolumeCommand( | ||||||
|  |                         ssHost.getStorageUrl(), volumeHost.getInstallPath()); | ||||||
|  |                 Answer answer = agentMgr.sendToSecStorage(ssHost, dtCommand); | ||||||
|  |                 if (answer == null || !answer.getResult()) { | ||||||
|  |                     s_logger.debug("Failed to delete " | ||||||
|  |                             + volumeHost | ||||||
|  |                             + " due to " | ||||||
|  |                             + ((answer == null) ? "answer is null" : answer | ||||||
|  |                                     .getDetails())); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |             } else if (volumeHost.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS) { | ||||||
|  |                 s_logger.debug("Volume: " + vol.getName() | ||||||
|  |                         + " is currently being uploaded; cant' delete it."); | ||||||
|  |                 throw new CloudRuntimeException( | ||||||
|  |                         "Please specify a volume that is not currently being uploaded."); | ||||||
|  |             } | ||||||
|  |             volumeHostDao.remove(volumeHost.getId()); | ||||||
|  |             volumeDao.remove(vol.getId()); | ||||||
|  |             CommandResult result = new CommandResult(); | ||||||
|  |             callback.complete(result); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     private void deleteTemplate(DataObject data, AsyncCompletionCallback<CommandResult> callback) { | ||||||
|  |          | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     private void deleteSnapshot(DataObject data, AsyncCompletionCallback<CommandResult> callback) { | ||||||
|  |     	Long snapshotId = data.getId(); | ||||||
|  |     	SnapshotVO snapshot = this.snapshotDao.findByIdIncludingRemoved(snapshotId); | ||||||
|  |     	CommandResult result = new CommandResult(); | ||||||
|  |     	if (snapshot == null) { | ||||||
|  |     		s_logger.debug("Destroying snapshot " + snapshotId + " backup failed due to unable to find snapshot "); | ||||||
|  |     		result.setResult("Unable to find snapshot: " + snapshotId); | ||||||
|  |     		callback.complete(result); | ||||||
|  |     		return; | ||||||
|  |     	} | ||||||
|  | 
 | ||||||
|  |     	try { | ||||||
|  |     		String secondaryStoragePoolUrl = this.snapshotMgr.getSecondaryStorageURL(snapshot); | ||||||
|  |     		Long dcId = snapshot.getDataCenterId(); | ||||||
|  |     		Long accountId = snapshot.getAccountId(); | ||||||
|  |     		Long volumeId = snapshot.getVolumeId(); | ||||||
|  | 
 | ||||||
|  |     		String backupOfSnapshot = snapshot.getBackupSnapshotId(); | ||||||
|  |     		if (backupOfSnapshot == null) { | ||||||
|  |     			callback.complete(result); | ||||||
|  |     			return; | ||||||
|  |     		} | ||||||
|  |     		SwiftTO swift = _swiftMgr.getSwiftTO(snapshot.getSwiftId()); | ||||||
|  |     		S3TO s3 = _s3Mgr.getS3TO(); | ||||||
|  | 
 | ||||||
|  |     		DeleteSnapshotBackupCommand cmd = new DeleteSnapshotBackupCommand( | ||||||
|  |     				swift, s3, secondaryStoragePoolUrl, dcId, accountId, volumeId, | ||||||
|  |     				backupOfSnapshot, false); | ||||||
|  |     		Answer answer = agentMgr.sendToSSVM(dcId, cmd); | ||||||
|  | 
 | ||||||
|  |     		if ((answer != null) && answer.getResult()) { | ||||||
|  |     			snapshot.setBackupSnapshotId(null); | ||||||
|  |     			snapshotDao.update(snapshotId, snapshot); | ||||||
|  |     		} else if (answer != null) { | ||||||
|  |     			result.setResult(answer.getDetails()); | ||||||
|  |     		} | ||||||
|  |     	} catch (Exception e) { | ||||||
|  |     		s_logger.debug("failed to delete snapshot: " + snapshotId + ": " + e.toString()); | ||||||
|  |     		result.setResult(e.toString()); | ||||||
|  |     	} | ||||||
|  |     	callback.complete(result); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     @Override | ||||||
|  |     public void deleteAsync(DataObject data, | ||||||
|  |             AsyncCompletionCallback<CommandResult> callback) { | ||||||
|  |         if (data.getType() == DataObjectType.VOLUME) { | ||||||
|  |             deleteVolume(data, callback); | ||||||
|  |         } else if (data.getType() == DataObjectType.TEMPLATE) { | ||||||
|  |             deleteTemplate(data, callback); | ||||||
|  |         } else if (data.getType() == DataObjectType.SNAPSHOT) { | ||||||
|  |         	deleteSnapshot(data, callback); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void copyAsync(DataObject srcdata, DataObject destData, | ||||||
|  |             AsyncCompletionCallback<CopyCommandResult> callback) { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public boolean canCopy(DataObject srcData, DataObject destData) { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 	@Override | ||||||
|  | 	public void resize(DataObject data, | ||||||
|  | 			AsyncCompletionCallback<CreateCmdResult> callback) { | ||||||
|  | 		// TODO Auto-generated method stub | ||||||
|  | 		 | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -0,0 +1,177 @@ | |||||||
|  | // 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.lifecycle; | ||||||
|  | 
 | ||||||
|  | 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.inject.Inject; | ||||||
|  | 
 | ||||||
|  | import org.apache.cloudstack.api.ApiConstants; | ||||||
|  | import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope; | ||||||
|  | import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; | ||||||
|  | import org.apache.cloudstack.engine.subsystem.api.storage.HostScope; | ||||||
|  | import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope; | ||||||
|  | import org.apache.cloudstack.storage.image.datastore.ImageStoreHelper; | ||||||
|  | import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager; | ||||||
|  | import org.apache.cloudstack.storage.image.db.ImageStoreDao; | ||||||
|  | import org.apache.cloudstack.storage.image.db.ImageStoreVO; | ||||||
|  | import org.apache.cloudstack.storage.image.store.lifecycle.ImageStoreLifeCycle; | ||||||
|  | import org.apache.log4j.Logger; | ||||||
|  | 
 | ||||||
|  | import com.cloud.agent.api.StoragePoolInfo; | ||||||
|  | import com.cloud.exception.DiscoveryException; | ||||||
|  | import com.cloud.exception.InvalidParameterValueException; | ||||||
|  | import com.cloud.host.Host; | ||||||
|  | import com.cloud.host.HostVO; | ||||||
|  | import com.cloud.hypervisor.kvm.discoverer.KvmDummyResourceBase; | ||||||
|  | import com.cloud.resource.Discoverer; | ||||||
|  | import com.cloud.resource.ResourceListener; | ||||||
|  | import com.cloud.resource.ResourceManager; | ||||||
|  | import com.cloud.resource.ServerResource; | ||||||
|  | import com.cloud.storage.ScopeType; | ||||||
|  | import com.cloud.storage.s3.S3Manager; | ||||||
|  | import com.cloud.utils.UriUtils; | ||||||
|  | 
 | ||||||
|  | public class S3ImageStoreLifeCycleImpl implements ImageStoreLifeCycle { | ||||||
|  | 
 | ||||||
|  |     private static final Logger s_logger = Logger | ||||||
|  |             .getLogger(S3ImageStoreLifeCycleImpl.class); | ||||||
|  |     @Inject | ||||||
|  |     protected ResourceManager _resourceMgr; | ||||||
|  |     @Inject | ||||||
|  | 	protected ImageStoreDao imageStoreDao; | ||||||
|  | 	@Inject | ||||||
|  | 	ImageStoreHelper imageStoreHelper; | ||||||
|  | 	@Inject | ||||||
|  | 	ImageStoreProviderManager imageStoreMgr; | ||||||
|  |     @Inject | ||||||
|  |     S3Manager                      _s3Mgr; | ||||||
|  | 
 | ||||||
|  |     protected List<? extends Discoverer> _discoverers; | ||||||
|  |     public List<? extends Discoverer> getDiscoverers() { | ||||||
|  |         return _discoverers; | ||||||
|  |     } | ||||||
|  |     public void setDiscoverers(List<? extends Discoverer> _discoverers) { | ||||||
|  |         this._discoverers = _discoverers; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 	public S3ImageStoreLifeCycleImpl() { | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public DataStore initialize(Map<String, Object> dsInfos) { | ||||||
|  | 
 | ||||||
|  |         Long dcId = (Long) dsInfos.get("zoneId"); | ||||||
|  |         String url = (String) dsInfos.get("url"); | ||||||
|  |         String providerName = (String)dsInfos.get("providerName"); | ||||||
|  |         ScopeType scope = (ScopeType)dsInfos.get("scope"); | ||||||
|  |         Map<String, String> details = (Map<String, String>)dsInfos.get("details"); | ||||||
|  | 
 | ||||||
|  |         s_logger.info("Trying to add a S3 store in data center " + dcId); | ||||||
|  | 
 | ||||||
|  |         try{ | ||||||
|  |         // verify S3 parameters | ||||||
|  |         _s3Mgr.verifyS3Fields(details); | ||||||
|  |         } | ||||||
|  |         catch (DiscoveryException ex){ | ||||||
|  |             throw new InvalidParameterValueException("failed to verify S3 parameters!"); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         Map<String, Object> imageStoreParameters = new HashMap<String, Object>(); | ||||||
|  |         imageStoreParameters.put("name", url); | ||||||
|  |         imageStoreParameters.put("zoneId", dcId); | ||||||
|  |         imageStoreParameters.put("url", url); | ||||||
|  |         String protocol = "http"; | ||||||
|  |         String useHttps = details.get(ApiConstants.S3_HTTPS_FLAG); | ||||||
|  |         if (useHttps != null && Boolean.parseBoolean(useHttps)){ | ||||||
|  |             protocol = "https"; | ||||||
|  |         } | ||||||
|  |         imageStoreParameters.put("protocol", protocol); | ||||||
|  |         if (scope != null) { | ||||||
|  |             imageStoreParameters.put("scope", scope); | ||||||
|  |         } else { | ||||||
|  |             imageStoreParameters.put("scope", ScopeType.REGION); | ||||||
|  |         } | ||||||
|  |         imageStoreParameters.put("providerName", providerName); | ||||||
|  | 
 | ||||||
|  |         ImageStoreVO ids = imageStoreHelper.createImageStore(imageStoreParameters, details); | ||||||
|  |         return imageStoreMgr.getImageStore(ids.getId()); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public boolean attachCluster(DataStore store, ClusterScope scope) { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public boolean attachHost(DataStore store, HostScope scope, | ||||||
|  |             StoragePoolInfo existingInfo) { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public boolean attachZone(DataStore dataStore, ZoneScope scope) { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public boolean dettach() { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public boolean unmanaged() { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public boolean maintain(DataStore store) { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public boolean cancelMaintain(DataStore store) { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public boolean deleteDataStore(DataStore store) { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -0,0 +1,90 @@ | |||||||
|  | /* | ||||||
|  |  * 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.provider; | ||||||
|  | 
 | ||||||
|  | import java.util.HashMap; | ||||||
|  | import java.util.HashSet; | ||||||
|  | import java.util.Map; | ||||||
|  | import java.util.Set; | ||||||
|  | import java.util.UUID; | ||||||
|  | 
 | ||||||
|  | import javax.inject.Inject; | ||||||
|  | 
 | ||||||
|  | import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver; | ||||||
|  | import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle; | ||||||
|  | import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener; | ||||||
|  | import org.apache.cloudstack.engine.subsystem.api.storage.ImageStoreProvider; | ||||||
|  | import org.apache.cloudstack.storage.datastore.driver.S3ImageStoreDriverImpl; | ||||||
|  | import org.apache.cloudstack.storage.datastore.lifecycle.S3ImageStoreLifeCycleImpl; | ||||||
|  | import org.apache.cloudstack.storage.image.ImageStoreDriver; | ||||||
|  | import org.apache.cloudstack.storage.image.datastore.ImageStoreHelper; | ||||||
|  | import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager; | ||||||
|  | import org.apache.cloudstack.storage.image.store.lifecycle.ImageStoreLifeCycle; | ||||||
|  | import org.springframework.stereotype.Component; | ||||||
|  | 
 | ||||||
|  | import com.cloud.storage.ScopeType; | ||||||
|  | import com.cloud.utils.component.ComponentContext; | ||||||
|  | 
 | ||||||
|  | @Component | ||||||
|  | public class S3ImageStoreProviderImpl implements ImageStoreProvider { | ||||||
|  | 
 | ||||||
|  |     private final String providerName = "S3 image store provider"; | ||||||
|  |     protected ImageStoreLifeCycle lifeCycle; | ||||||
|  |     protected ImageStoreDriver driver; | ||||||
|  |     @Inject | ||||||
|  |     ImageStoreProviderManager storeMgr; | ||||||
|  |     @Inject | ||||||
|  |     ImageStoreHelper helper; | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public DataStoreLifeCycle getDataStoreLifeCycle() { | ||||||
|  |         return lifeCycle; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public String getName() { | ||||||
|  |         return this.providerName; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public boolean configure(Map<String, Object> params) { | ||||||
|  |         lifeCycle = ComponentContext.inject(S3ImageStoreLifeCycleImpl.class); | ||||||
|  |         driver = ComponentContext.inject(S3ImageStoreDriverImpl.class); | ||||||
|  |         storeMgr.registerDriver(this.getName(), driver); | ||||||
|  |         return true; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public DataStoreDriver getDataStoreDriver() { | ||||||
|  |         return this.driver; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public HypervisorHostListener getHostListener() { | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public Set<DataStoreProviderType> getTypes() { | ||||||
|  |         Set<DataStoreProviderType> types =  new HashSet<DataStoreProviderType>(); | ||||||
|  |         types.add(DataStoreProviderType.IMAGE); | ||||||
|  |         return types; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -33,17 +33,17 @@ import org.apache.cloudstack.framework.async.AsyncCompletionCallback; | |||||||
| import org.apache.cloudstack.storage.command.CreateObjectAnswer; | import org.apache.cloudstack.storage.command.CreateObjectAnswer; | ||||||
| import org.apache.cloudstack.storage.command.CreateObjectCommand; | import org.apache.cloudstack.storage.command.CreateObjectCommand; | ||||||
| import org.apache.cloudstack.storage.endpoint.EndPointSelector; | import org.apache.cloudstack.storage.endpoint.EndPointSelector; | ||||||
| import org.apache.cloudstack.storage.image.ImageDataStoreDriver; | import org.apache.cloudstack.storage.image.ImageStoreDriver; | ||||||
| 
 | 
 | ||||||
| import com.cloud.storage.dao.VMTemplateDao; | import com.cloud.storage.dao.VMTemplateDao; | ||||||
| 
 | 
 | ||||||
| //http-read-only based image store | //http-read-only based image store | ||||||
| public class SampleImageDataStoreDriverImpl implements ImageDataStoreDriver { | public class SampleImageStoreDriverImpl implements ImageStoreDriver { | ||||||
|     @Inject |     @Inject | ||||||
|     EndPointSelector selector; |     EndPointSelector selector; | ||||||
|     @Inject |     @Inject | ||||||
|     VMTemplateDao imageDataDao; |     VMTemplateDao imageDataDao; | ||||||
|     public SampleImageDataStoreDriverImpl() { |     public SampleImageStoreDriverImpl() { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
| @ -24,29 +24,29 @@ import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope; | |||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; | import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.HostScope; | import org.apache.cloudstack.engine.subsystem.api.storage.HostScope; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope; | import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope; | ||||||
| import org.apache.cloudstack.storage.image.datastore.ImageDataStoreHelper; | import org.apache.cloudstack.storage.image.datastore.ImageStoreHelper; | ||||||
| import org.apache.cloudstack.storage.image.datastore.ImageDataStoreProviderManager; | import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager; | ||||||
| import org.apache.cloudstack.storage.image.db.ImageDataStoreDao; | import org.apache.cloudstack.storage.image.db.ImageStoreDao; | ||||||
| import org.apache.cloudstack.storage.image.db.ImageDataStoreVO; | import org.apache.cloudstack.storage.image.db.ImageStoreVO; | ||||||
| import org.apache.cloudstack.storage.image.store.lifecycle.ImageDataStoreLifeCycle; | import org.apache.cloudstack.storage.image.store.lifecycle.ImageStoreLifeCycle; | ||||||
| 
 | 
 | ||||||
| import com.cloud.agent.api.StoragePoolInfo; | import com.cloud.agent.api.StoragePoolInfo; | ||||||
| 
 | 
 | ||||||
| public class SampleImageDataStoreLifeCycle implements ImageDataStoreLifeCycle { | public class SampleImageStoreLifeCycleImpl implements ImageStoreLifeCycle { | ||||||
|     @Inject |     @Inject | ||||||
| 	protected ImageDataStoreDao imageStoreDao; | 	protected ImageStoreDao imageStoreDao; | ||||||
| 	@Inject | 	@Inject | ||||||
| 	ImageDataStoreHelper imageStoreHelper; | 	ImageStoreHelper imageStoreHelper; | ||||||
| 	@Inject | 	@Inject | ||||||
| 	ImageDataStoreProviderManager imageStoreMgr; | 	ImageStoreProviderManager imageStoreMgr; | ||||||
| 	public SampleImageDataStoreLifeCycle() { | 	public SampleImageStoreLifeCycleImpl() { | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public DataStore initialize(Map<String, Object> dsInfos) { |     public DataStore initialize(Map<String, Object> dsInfos) { | ||||||
|         ImageDataStoreVO ids = imageStoreHelper.createImageDataStore(dsInfos); |         ImageStoreVO ids = imageStoreHelper.createImageStore(dsInfos); | ||||||
|         return imageStoreMgr.getImageDataStore(ids.getId()); |         return imageStoreMgr.getImageStore(ids.getId()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -27,21 +27,21 @@ import javax.inject.Inject; | |||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver; | import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle; | import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener; | import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.ImageDataStoreProvider; | import org.apache.cloudstack.engine.subsystem.api.storage.ImageStoreProvider; | ||||||
| import org.apache.cloudstack.storage.datastore.driver.SampleImageDataStoreDriverImpl; | import org.apache.cloudstack.storage.datastore.driver.SampleImageStoreDriverImpl; | ||||||
| import org.apache.cloudstack.storage.datastore.lifecycle.SampleImageDataStoreLifeCycle; | import org.apache.cloudstack.storage.datastore.lifecycle.SampleImageStoreLifeCycleImpl; | ||||||
| import org.apache.cloudstack.storage.image.ImageDataStoreDriver; | import org.apache.cloudstack.storage.image.ImageStoreDriver; | ||||||
| import org.apache.cloudstack.storage.image.datastore.ImageDataStoreProviderManager; | import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager; | ||||||
| import org.apache.cloudstack.storage.image.store.lifecycle.ImageDataStoreLifeCycle; | import org.apache.cloudstack.storage.image.store.lifecycle.ImageStoreLifeCycle; | ||||||
| 
 | 
 | ||||||
| import com.cloud.utils.component.ComponentContext; | import com.cloud.utils.component.ComponentContext; | ||||||
| 
 | 
 | ||||||
| public class SampleImageDataStoreProvider implements ImageDataStoreProvider { | public class SampleImageStoreProviderImpl implements ImageStoreProvider { | ||||||
|     private final String name = "sample image data store provider"; |     private final String name = "sample image data store provider"; | ||||||
|     protected ImageDataStoreLifeCycle lifeCycle; |     protected ImageStoreLifeCycle lifeCycle; | ||||||
|     protected ImageDataStoreDriver driver; |     protected ImageStoreDriver driver; | ||||||
|     @Inject |     @Inject | ||||||
|     ImageDataStoreProviderManager storeMgr; |     ImageStoreProviderManager storeMgr; | ||||||
|     long id; |     long id; | ||||||
|     String uuid; |     String uuid; | ||||||
|     @Override |     @Override | ||||||
| @ -56,8 +56,8 @@ public class SampleImageDataStoreProvider implements ImageDataStoreProvider { | |||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public boolean configure(Map<String, Object> params) { |     public boolean configure(Map<String, Object> params) { | ||||||
|         lifeCycle = ComponentContext.inject(SampleImageDataStoreLifeCycle.class); |         lifeCycle = ComponentContext.inject(SampleImageStoreLifeCycleImpl.class); | ||||||
|         driver = ComponentContext.inject(SampleImageDataStoreDriverImpl.class); |         driver = ComponentContext.inject(SampleImageStoreDriverImpl.class); | ||||||
| 
 | 
 | ||||||
|         storeMgr.registerDriver(this.getName(), driver); |         storeMgr.registerDriver(this.getName(), driver); | ||||||
|         return true; |         return true; | ||||||
							
								
								
									
										56
									
								
								plugins/storage/image/swift/pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								plugins/storage/image/swift/pom.xml
									
									
									
									
									
										Normal file
									
								
							| @ -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. --> | ||||||
|  | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||||
|  |   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||||||
|  |   <modelVersion>4.0.0</modelVersion> | ||||||
|  |   <artifactId>cloud-plugin-storage-image-swift</artifactId> | ||||||
|  |   <name>Apache CloudStack Plugin - Storage Image Swift provider</name> | ||||||
|  |   <parent> | ||||||
|  |     <groupId>org.apache.cloudstack</groupId> | ||||||
|  |     <artifactId>cloudstack-plugins</artifactId> | ||||||
|  |     <version>4.2.0-SNAPSHOT</version> | ||||||
|  |     <relativePath>../../../pom.xml</relativePath> | ||||||
|  |   </parent> | ||||||
|  |   <dependencies> | ||||||
|  |     <dependency> | ||||||
|  |       <groupId>org.apache.cloudstack</groupId> | ||||||
|  |       <artifactId>cloud-engine-storage-image</artifactId> | ||||||
|  |       <version>${project.version}</version> | ||||||
|  |     </dependency> | ||||||
|  |     <dependency> | ||||||
|  |       <groupId>mysql</groupId> | ||||||
|  |       <artifactId>mysql-connector-java</artifactId> | ||||||
|  |       <version>${cs.mysql.version}</version> | ||||||
|  |       <scope>provided</scope> | ||||||
|  |     </dependency> | ||||||
|  |   </dependencies> | ||||||
|  |   <build> | ||||||
|  |     <defaultGoal>install</defaultGoal> | ||||||
|  |     <sourceDirectory>src</sourceDirectory> | ||||||
|  |     <testSourceDirectory>test</testSourceDirectory> | ||||||
|  |     <plugins> | ||||||
|  |       <plugin> | ||||||
|  |         <artifactId>maven-surefire-plugin</artifactId> | ||||||
|  |         <configuration> | ||||||
|  |           <skipTests>true</skipTests> | ||||||
|  |         </configuration> | ||||||
|  |         <executions> | ||||||
|  |           <execution> | ||||||
|  |             <phase>integration-test</phase> | ||||||
|  |             <goals> | ||||||
|  |               <goal>test</goal> | ||||||
|  |             </goals> | ||||||
|  |           </execution> | ||||||
|  |         </executions> | ||||||
|  |       </plugin> | ||||||
|  |     </plugins> | ||||||
|  |   </build> | ||||||
|  | </project> | ||||||
| @ -0,0 +1,250 @@ | |||||||
|  | /* | ||||||
|  |  * 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.driver; | ||||||
|  | 
 | ||||||
|  | import java.util.List; | ||||||
|  | import java.util.Set; | ||||||
|  | 
 | ||||||
|  | import javax.inject.Inject; | ||||||
|  | 
 | ||||||
|  | import org.apache.cloudstack.engine.subsystem.api.storage.CommandResult; | ||||||
|  | import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult; | ||||||
|  | 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.DataObjectType; | ||||||
|  | import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; | ||||||
|  | import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint; | ||||||
|  | import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; | ||||||
|  | import org.apache.cloudstack.framework.async.AsyncCompletionCallback; | ||||||
|  | import org.apache.cloudstack.framework.async.AsyncRpcConext; | ||||||
|  | import org.apache.cloudstack.storage.image.ImageStoreDriver; | ||||||
|  | import org.apache.log4j.Logger; | ||||||
|  | 
 | ||||||
|  | import com.cloud.agent.AgentManager; | ||||||
|  | import com.cloud.agent.api.Answer; | ||||||
|  | import com.cloud.agent.api.DeleteSnapshotBackupCommand; | ||||||
|  | import com.cloud.agent.api.storage.DeleteVolumeCommand; | ||||||
|  | import com.cloud.agent.api.to.S3TO; | ||||||
|  | import com.cloud.agent.api.to.SwiftTO; | ||||||
|  | import com.cloud.host.HostVO; | ||||||
|  | import com.cloud.host.dao.HostDao; | ||||||
|  | import com.cloud.storage.RegisterVolumePayload; | ||||||
|  | import com.cloud.storage.Storage.ImageFormat; | ||||||
|  | import com.cloud.storage.SnapshotVO; | ||||||
|  | import com.cloud.storage.VMTemplateStorageResourceAssoc; | ||||||
|  | import com.cloud.storage.VMTemplateVO; | ||||||
|  | import com.cloud.storage.VMTemplateZoneVO; | ||||||
|  | import com.cloud.storage.VolumeHostVO; | ||||||
|  | import com.cloud.storage.VolumeVO; | ||||||
|  | import com.cloud.storage.dao.SnapshotDao; | ||||||
|  | import com.cloud.storage.dao.VMTemplateDao; | ||||||
|  | import com.cloud.storage.dao.VMTemplateHostDao; | ||||||
|  | import com.cloud.storage.dao.VMTemplateZoneDao; | ||||||
|  | import com.cloud.storage.dao.VolumeDao; | ||||||
|  | import com.cloud.storage.dao.VolumeHostDao; | ||||||
|  | import com.cloud.storage.download.DownloadMonitor; | ||||||
|  | import com.cloud.storage.s3.S3Manager; | ||||||
|  | import com.cloud.storage.snapshot.SnapshotManager; | ||||||
|  | import com.cloud.storage.swift.SwiftManager; | ||||||
|  | import com.cloud.utils.exception.CloudRuntimeException; | ||||||
|  | 
 | ||||||
|  | public class SwiftImageStoreDriverImpl implements ImageStoreDriver { | ||||||
|  |     private static final Logger s_logger = Logger | ||||||
|  |             .getLogger(SwiftImageStoreDriverImpl.class); | ||||||
|  |     @Inject | ||||||
|  |     VMTemplateZoneDao templateZoneDao; | ||||||
|  |     @Inject | ||||||
|  |     VMTemplateDao templateDao; | ||||||
|  |     @Inject DownloadMonitor _downloadMonitor; | ||||||
|  |     @Inject  | ||||||
|  |     VMTemplateHostDao _vmTemplateHostDao; | ||||||
|  |     @Inject VolumeDao volumeDao; | ||||||
|  |     @Inject VolumeHostDao volumeHostDao; | ||||||
|  |     @Inject HostDao hostDao; | ||||||
|  |     @Inject SnapshotDao snapshotDao; | ||||||
|  |     @Inject AgentManager agentMgr; | ||||||
|  |     @Inject SnapshotManager snapshotMgr; | ||||||
|  | 	@Inject | ||||||
|  |     private SwiftManager _swiftMgr; | ||||||
|  |     @Inject  | ||||||
|  |     private S3Manager _s3Mgr;  | ||||||
|  |     @Override | ||||||
|  |     public String grantAccess(DataObject data, EndPoint ep) { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public boolean revokeAccess(DataObject data, EndPoint ep) { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public Set<DataObject> listObjects(DataStore store) { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     class CreateContext<T> extends AsyncRpcConext<T> { | ||||||
|  |         final DataObject data; | ||||||
|  |         public CreateContext(AsyncCompletionCallback<T> callback, DataObject data) { | ||||||
|  |             super(callback); | ||||||
|  |             this.data = data; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     @Override | ||||||
|  |     public void createAsync(DataObject data, | ||||||
|  |             AsyncCompletionCallback<CreateCmdResult> callback) { | ||||||
|  |         if (data.getType() == DataObjectType.TEMPLATE) { | ||||||
|  |             List<VMTemplateZoneVO> templateZones = this.templateZoneDao.listByTemplateId(data.getId()); | ||||||
|  |             for (VMTemplateZoneVO templateZone : templateZones) { | ||||||
|  |                 VMTemplateVO template = this.templateDao.findById(data.getId()); | ||||||
|  |                 _downloadMonitor.downloadTemplateToStorage(template, templateZone.getZoneId()); | ||||||
|  |             } | ||||||
|  |         } else if (data.getType() == DataObjectType.VOLUME) { | ||||||
|  |             VolumeVO vol = this.volumeDao.findById(data.getId()); | ||||||
|  |             VolumeInfo volInfo = (VolumeInfo)data; | ||||||
|  |             RegisterVolumePayload payload = (RegisterVolumePayload)volInfo.getpayload(); | ||||||
|  |             _downloadMonitor.downloadVolumeToStorage(vol, vol.getDataCenterId(), payload.getUrl(), | ||||||
|  |                     payload.getChecksum(), ImageFormat.valueOf(payload.getFormat().toUpperCase())); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         CreateCmdResult result = new CreateCmdResult(null, null); | ||||||
|  |         callback.complete(result); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     private void deleteVolume(DataObject data, AsyncCompletionCallback<CommandResult> callback) { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  |         VolumeVO vol = volumeDao.findById(data.getId()); | ||||||
|  |         if (s_logger.isDebugEnabled()) { | ||||||
|  |             s_logger.debug("Expunging " + vol); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         // Find out if the volume is present on secondary storage | ||||||
|  |         VolumeHostVO volumeHost = volumeHostDao.findByVolumeId(vol.getId()); | ||||||
|  |         if (volumeHost != null) { | ||||||
|  |             if (volumeHost.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED) { | ||||||
|  |                 HostVO ssHost = hostDao.findById(volumeHost.getHostId()); | ||||||
|  |                 DeleteVolumeCommand dtCommand = new DeleteVolumeCommand( | ||||||
|  |                         ssHost.getStorageUrl(), volumeHost.getInstallPath()); | ||||||
|  |                 Answer answer = agentMgr.sendToSecStorage(ssHost, dtCommand); | ||||||
|  |                 if (answer == null || !answer.getResult()) { | ||||||
|  |                     s_logger.debug("Failed to delete " | ||||||
|  |                             + volumeHost | ||||||
|  |                             + " due to " | ||||||
|  |                             + ((answer == null) ? "answer is null" : answer | ||||||
|  |                                     .getDetails())); | ||||||
|  |                     return; | ||||||
|  |                 } | ||||||
|  |             } else if (volumeHost.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS) { | ||||||
|  |                 s_logger.debug("Volume: " + vol.getName() | ||||||
|  |                         + " is currently being uploaded; cant' delete it."); | ||||||
|  |                 throw new CloudRuntimeException( | ||||||
|  |                         "Please specify a volume that is not currently being uploaded."); | ||||||
|  |             } | ||||||
|  |             volumeHostDao.remove(volumeHost.getId()); | ||||||
|  |             volumeDao.remove(vol.getId()); | ||||||
|  |             CommandResult result = new CommandResult(); | ||||||
|  |             callback.complete(result); | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     private void deleteTemplate(DataObject data, AsyncCompletionCallback<CommandResult> callback) { | ||||||
|  |          | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     private void deleteSnapshot(DataObject data, AsyncCompletionCallback<CommandResult> callback) { | ||||||
|  |     	Long snapshotId = data.getId(); | ||||||
|  |     	SnapshotVO snapshot = this.snapshotDao.findByIdIncludingRemoved(snapshotId); | ||||||
|  |     	CommandResult result = new CommandResult(); | ||||||
|  |     	if (snapshot == null) { | ||||||
|  |     		s_logger.debug("Destroying snapshot " + snapshotId + " backup failed due to unable to find snapshot "); | ||||||
|  |     		result.setResult("Unable to find snapshot: " + snapshotId); | ||||||
|  |     		callback.complete(result); | ||||||
|  |     		return; | ||||||
|  |     	} | ||||||
|  | 
 | ||||||
|  |     	try { | ||||||
|  |     		String secondaryStoragePoolUrl = this.snapshotMgr.getSecondaryStorageURL(snapshot); | ||||||
|  |     		Long dcId = snapshot.getDataCenterId(); | ||||||
|  |     		Long accountId = snapshot.getAccountId(); | ||||||
|  |     		Long volumeId = snapshot.getVolumeId(); | ||||||
|  | 
 | ||||||
|  |     		String backupOfSnapshot = snapshot.getBackupSnapshotId(); | ||||||
|  |     		if (backupOfSnapshot == null) { | ||||||
|  |     			callback.complete(result); | ||||||
|  |     			return; | ||||||
|  |     		} | ||||||
|  |     		SwiftTO swift = _swiftMgr.getSwiftTO(snapshot.getSwiftId()); | ||||||
|  |     		S3TO s3 = _s3Mgr.getS3TO(); | ||||||
|  | 
 | ||||||
|  |     		DeleteSnapshotBackupCommand cmd = new DeleteSnapshotBackupCommand( | ||||||
|  |     				swift, s3, secondaryStoragePoolUrl, dcId, accountId, volumeId, | ||||||
|  |     				backupOfSnapshot, false); | ||||||
|  |     		Answer answer = agentMgr.sendToSSVM(dcId, cmd); | ||||||
|  | 
 | ||||||
|  |     		if ((answer != null) && answer.getResult()) { | ||||||
|  |     			snapshot.setBackupSnapshotId(null); | ||||||
|  |     			snapshotDao.update(snapshotId, snapshot); | ||||||
|  |     		} else if (answer != null) { | ||||||
|  |     			result.setResult(answer.getDetails()); | ||||||
|  |     		} | ||||||
|  |     	} catch (Exception e) { | ||||||
|  |     		s_logger.debug("failed to delete snapshot: " + snapshotId + ": " + e.toString()); | ||||||
|  |     		result.setResult(e.toString()); | ||||||
|  |     	} | ||||||
|  |     	callback.complete(result); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     @Override | ||||||
|  |     public void deleteAsync(DataObject data, | ||||||
|  |             AsyncCompletionCallback<CommandResult> callback) { | ||||||
|  |         if (data.getType() == DataObjectType.VOLUME) { | ||||||
|  |             deleteVolume(data, callback); | ||||||
|  |         } else if (data.getType() == DataObjectType.TEMPLATE) { | ||||||
|  |             deleteTemplate(data, callback); | ||||||
|  |         } else if (data.getType() == DataObjectType.SNAPSHOT) { | ||||||
|  |         	deleteSnapshot(data, callback); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void copyAsync(DataObject srcdata, DataObject destData, | ||||||
|  |             AsyncCompletionCallback<CopyCommandResult> callback) { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public boolean canCopy(DataObject srcData, DataObject destData) { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 	@Override | ||||||
|  | 	public void resize(DataObject data, | ||||||
|  | 			AsyncCompletionCallback<CreateCmdResult> callback) { | ||||||
|  | 		// TODO Auto-generated method stub | ||||||
|  | 		 | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -0,0 +1,161 @@ | |||||||
|  | // 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.lifecycle; | ||||||
|  | 
 | ||||||
|  | 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.inject.Inject; | ||||||
|  | 
 | ||||||
|  | import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope; | ||||||
|  | import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; | ||||||
|  | import org.apache.cloudstack.engine.subsystem.api.storage.HostScope; | ||||||
|  | import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope; | ||||||
|  | import org.apache.cloudstack.storage.image.datastore.ImageStoreHelper; | ||||||
|  | import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager; | ||||||
|  | import org.apache.cloudstack.storage.image.db.ImageStoreDao; | ||||||
|  | import org.apache.cloudstack.storage.image.db.ImageStoreVO; | ||||||
|  | import org.apache.cloudstack.storage.image.store.lifecycle.ImageStoreLifeCycle; | ||||||
|  | import org.apache.log4j.Logger; | ||||||
|  | 
 | ||||||
|  | import com.cloud.agent.api.StoragePoolInfo; | ||||||
|  | import com.cloud.exception.DiscoveryException; | ||||||
|  | import com.cloud.exception.InvalidParameterValueException; | ||||||
|  | import com.cloud.host.Host; | ||||||
|  | import com.cloud.host.HostVO; | ||||||
|  | import com.cloud.hypervisor.kvm.discoverer.KvmDummyResourceBase; | ||||||
|  | import com.cloud.resource.Discoverer; | ||||||
|  | import com.cloud.resource.ResourceListener; | ||||||
|  | import com.cloud.resource.ResourceManager; | ||||||
|  | import com.cloud.resource.ServerResource; | ||||||
|  | import com.cloud.storage.ScopeType; | ||||||
|  | import com.cloud.utils.UriUtils; | ||||||
|  | 
 | ||||||
|  | public class SwiftImageStoreLifeCycleImpl implements ImageStoreLifeCycle { | ||||||
|  | 
 | ||||||
|  |     private static final Logger s_logger = Logger | ||||||
|  |             .getLogger(SwiftImageStoreLifeCycleImpl.class); | ||||||
|  |     @Inject | ||||||
|  |     protected ResourceManager _resourceMgr; | ||||||
|  |     @Inject | ||||||
|  | 	protected ImageStoreDao imageStoreDao; | ||||||
|  | 	@Inject | ||||||
|  | 	ImageStoreHelper imageStoreHelper; | ||||||
|  | 	@Inject | ||||||
|  | 	ImageStoreProviderManager imageStoreMgr; | ||||||
|  | 
 | ||||||
|  |     protected List<? extends Discoverer> _discoverers; | ||||||
|  |     public List<? extends Discoverer> getDiscoverers() { | ||||||
|  |         return _discoverers; | ||||||
|  |     } | ||||||
|  |     public void setDiscoverers(List<? extends Discoverer> _discoverers) { | ||||||
|  |         this._discoverers = _discoverers; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 	public SwiftImageStoreLifeCycleImpl() { | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public DataStore initialize(Map<String, Object> dsInfos) { | ||||||
|  | 
 | ||||||
|  |         Long dcId = (Long) dsInfos.get("zoneId"); | ||||||
|  |         String url = (String) dsInfos.get("url"); | ||||||
|  |         ScopeType scope = (ScopeType)dsInfos.get("scope"); | ||||||
|  |         String providerName = (String)dsInfos.get("providerName"); | ||||||
|  |         Map<String, String> details = (Map<String, String>)dsInfos.get("details"); | ||||||
|  | 
 | ||||||
|  |         s_logger.info("Trying to add a swift store at " + url + " in data center " + dcId); | ||||||
|  | 
 | ||||||
|  |         // just need to insert an entry in DB | ||||||
|  |         Map<String, Object> imageStoreParameters = new HashMap<String, Object>(); | ||||||
|  |         imageStoreParameters.put("name", url); | ||||||
|  |         imageStoreParameters.put("zoneId", dcId); | ||||||
|  |         imageStoreParameters.put("url", url); | ||||||
|  |         imageStoreParameters.put("protocol", "http"); | ||||||
|  |         if (scope != null) { | ||||||
|  |             imageStoreParameters.put("scope", scope); | ||||||
|  |         } else { | ||||||
|  |             imageStoreParameters.put("scope", ScopeType.REGION); | ||||||
|  |         } | ||||||
|  |         imageStoreParameters.put("providerName", providerName); | ||||||
|  | 
 | ||||||
|  |         ImageStoreVO ids = imageStoreHelper.createImageStore(imageStoreParameters); | ||||||
|  |         return imageStoreMgr.getImageStore(ids.getId()); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public boolean attachCluster(DataStore store, ClusterScope scope) { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public boolean attachHost(DataStore store, HostScope scope, | ||||||
|  |             StoragePoolInfo existingInfo) { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public boolean attachZone(DataStore dataStore, ZoneScope scope) { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public boolean dettach() { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public boolean unmanaged() { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public boolean maintain(DataStore store) { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public boolean cancelMaintain(DataStore store) { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public boolean deleteDataStore(DataStore store) { | ||||||
|  |         // TODO Auto-generated method stub | ||||||
|  |         return false; | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -0,0 +1,92 @@ | |||||||
|  | /* | ||||||
|  |  * 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.provider; | ||||||
|  | 
 | ||||||
|  | import java.util.HashMap; | ||||||
|  | import java.util.HashSet; | ||||||
|  | import java.util.Map; | ||||||
|  | import java.util.Set; | ||||||
|  | import java.util.UUID; | ||||||
|  | 
 | ||||||
|  | import javax.inject.Inject; | ||||||
|  | 
 | ||||||
|  | import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver; | ||||||
|  | import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle; | ||||||
|  | import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener; | ||||||
|  | import org.apache.cloudstack.engine.subsystem.api.storage.ImageStoreProvider; | ||||||
|  | import org.apache.cloudstack.storage.datastore.driver.SwiftImageStoreDriverImpl; | ||||||
|  | import org.apache.cloudstack.storage.datastore.lifecycle.SwiftImageStoreLifeCycleImpl; | ||||||
|  | import org.apache.cloudstack.storage.image.ImageStoreDriver; | ||||||
|  | import org.apache.cloudstack.storage.image.datastore.ImageStoreHelper; | ||||||
|  | import org.apache.cloudstack.storage.image.datastore.ImageStoreProviderManager; | ||||||
|  | import org.apache.cloudstack.storage.image.store.lifecycle.ImageStoreLifeCycle; | ||||||
|  | import org.springframework.stereotype.Component; | ||||||
|  | 
 | ||||||
|  | import com.cloud.storage.ScopeType; | ||||||
|  | import com.cloud.utils.component.ComponentContext; | ||||||
|  | 
 | ||||||
|  | @Component | ||||||
|  | public class SwiftImageStoreProviderImpl implements ImageStoreProvider { | ||||||
|  | 
 | ||||||
|  |     private final String providerName = "Swift image store provider"; | ||||||
|  |     protected ImageStoreLifeCycle lifeCycle; | ||||||
|  |     protected ImageStoreDriver driver; | ||||||
|  |     @Inject | ||||||
|  |     ImageStoreProviderManager storeMgr; | ||||||
|  |     @Inject | ||||||
|  |     ImageStoreHelper helper; | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public DataStoreLifeCycle getDataStoreLifeCycle() { | ||||||
|  |         return lifeCycle; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public String getName() { | ||||||
|  |         return this.providerName; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public boolean configure(Map<String, Object> params) { | ||||||
|  |         lifeCycle = ComponentContext.inject(SwiftImageStoreLifeCycleImpl.class); | ||||||
|  |         driver = ComponentContext.inject(SwiftImageStoreDriverImpl.class); | ||||||
|  | 
 | ||||||
|  |         storeMgr.registerDriver(this.getName(), driver); | ||||||
|  | 
 | ||||||
|  |         return true; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public DataStoreDriver getDataStoreDriver() { | ||||||
|  |         return this.driver; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public HypervisorHostListener getHostListener() { | ||||||
|  |         return null; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public Set<DataStoreProviderType> getTypes() { | ||||||
|  |         Set<DataStoreProviderType> types =  new HashSet<DataStoreProviderType>(); | ||||||
|  |         types.add(DataStoreProviderType.IMAGE); | ||||||
|  |         return types; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | } | ||||||
| @ -34,7 +34,7 @@ import org.apache.cloudstack.api.response.DomainRouterResponse; | |||||||
| import org.apache.cloudstack.api.response.EventResponse; | import org.apache.cloudstack.api.response.EventResponse; | ||||||
| import org.apache.cloudstack.api.response.HostResponse; | import org.apache.cloudstack.api.response.HostResponse; | ||||||
| import org.apache.cloudstack.api.response.InstanceGroupResponse; | import org.apache.cloudstack.api.response.InstanceGroupResponse; | ||||||
| import org.apache.cloudstack.api.response.ObjectStoreResponse; | import org.apache.cloudstack.api.response.ImageStoreResponse; | ||||||
| import org.apache.cloudstack.api.response.ProjectAccountResponse; | import org.apache.cloudstack.api.response.ProjectAccountResponse; | ||||||
| import org.apache.cloudstack.api.response.ProjectInvitationResponse; | import org.apache.cloudstack.api.response.ProjectInvitationResponse; | ||||||
| import org.apache.cloudstack.api.response.ProjectResponse; | import org.apache.cloudstack.api.response.ProjectResponse; | ||||||
| @ -56,7 +56,7 @@ import com.cloud.api.query.dao.DataCenterJoinDao; | |||||||
| import com.cloud.api.query.dao.DiskOfferingJoinDao; | import com.cloud.api.query.dao.DiskOfferingJoinDao; | ||||||
| import com.cloud.api.query.dao.DomainRouterJoinDao; | import com.cloud.api.query.dao.DomainRouterJoinDao; | ||||||
| import com.cloud.api.query.dao.HostJoinDao; | import com.cloud.api.query.dao.HostJoinDao; | ||||||
| import com.cloud.api.query.dao.ImageDataStoreJoinDao; | import com.cloud.api.query.dao.ImageStoreJoinDao; | ||||||
| import com.cloud.api.query.dao.InstanceGroupJoinDao; | import com.cloud.api.query.dao.InstanceGroupJoinDao; | ||||||
| import com.cloud.api.query.dao.ProjectAccountJoinDao; | import com.cloud.api.query.dao.ProjectAccountJoinDao; | ||||||
| import com.cloud.api.query.dao.ProjectInvitationJoinDao; | import com.cloud.api.query.dao.ProjectInvitationJoinDao; | ||||||
| @ -75,7 +75,7 @@ import com.cloud.api.query.vo.DiskOfferingJoinVO; | |||||||
| import com.cloud.api.query.vo.DomainRouterJoinVO; | import com.cloud.api.query.vo.DomainRouterJoinVO; | ||||||
| import com.cloud.api.query.vo.EventJoinVO; | import com.cloud.api.query.vo.EventJoinVO; | ||||||
| import com.cloud.api.query.vo.HostJoinVO; | import com.cloud.api.query.vo.HostJoinVO; | ||||||
| import com.cloud.api.query.vo.ImageDataStoreJoinVO; | import com.cloud.api.query.vo.ImageStoreJoinVO; | ||||||
| import com.cloud.api.query.vo.InstanceGroupJoinVO; | import com.cloud.api.query.vo.InstanceGroupJoinVO; | ||||||
| import com.cloud.api.query.vo.ProjectAccountJoinVO; | import com.cloud.api.query.vo.ProjectAccountJoinVO; | ||||||
| import com.cloud.api.query.vo.ProjectInvitationJoinVO; | import com.cloud.api.query.vo.ProjectInvitationJoinVO; | ||||||
| @ -208,6 +208,7 @@ import com.cloud.service.dao.ServiceOfferingDao; | |||||||
| import com.cloud.storage.DiskOfferingVO; | import com.cloud.storage.DiskOfferingVO; | ||||||
| import com.cloud.storage.GuestOS; | import com.cloud.storage.GuestOS; | ||||||
| import com.cloud.storage.GuestOSCategoryVO; | import com.cloud.storage.GuestOSCategoryVO; | ||||||
|  | import com.cloud.storage.ImageStore; | ||||||
| import com.cloud.storage.Snapshot; | import com.cloud.storage.Snapshot; | ||||||
| import com.cloud.storage.SnapshotVO; | import com.cloud.storage.SnapshotVO; | ||||||
| import com.cloud.storage.Storage.ImageFormat; | import com.cloud.storage.Storage.ImageFormat; | ||||||
| @ -365,7 +366,7 @@ public class ApiDBUtils { | |||||||
|     static HostJoinDao _hostJoinDao; |     static HostJoinDao _hostJoinDao; | ||||||
|     static VolumeJoinDao _volJoinDao; |     static VolumeJoinDao _volJoinDao; | ||||||
|     static StoragePoolJoinDao _poolJoinDao; |     static StoragePoolJoinDao _poolJoinDao; | ||||||
|     static ImageDataStoreJoinDao _imageStoreJoinDao; |     static ImageStoreJoinDao _imageStoreJoinDao; | ||||||
|     static AccountJoinDao _accountJoinDao; |     static AccountJoinDao _accountJoinDao; | ||||||
|     static AsyncJobJoinDao _jobJoinDao; |     static AsyncJobJoinDao _jobJoinDao; | ||||||
| 
 | 
 | ||||||
| @ -470,7 +471,7 @@ public class ApiDBUtils { | |||||||
|     @Inject private HostJoinDao hostJoinDao; |     @Inject private HostJoinDao hostJoinDao; | ||||||
|     @Inject private VolumeJoinDao volJoinDao; |     @Inject private VolumeJoinDao volJoinDao; | ||||||
|     @Inject private StoragePoolJoinDao poolJoinDao; |     @Inject private StoragePoolJoinDao poolJoinDao; | ||||||
|     @Inject private ImageDataStoreJoinDao imageStoreJoinDao; |     @Inject private ImageStoreJoinDao imageStoreJoinDao; | ||||||
|     @Inject private AccountJoinDao accountJoinDao; |     @Inject private AccountJoinDao accountJoinDao; | ||||||
|     @Inject private AsyncJobJoinDao jobJoinDao; |     @Inject private AsyncJobJoinDao jobJoinDao; | ||||||
| 
 | 
 | ||||||
| @ -1541,16 +1542,16 @@ public class ApiDBUtils { | |||||||
|         return _poolJoinDao.newStoragePoolView(vr); |         return _poolJoinDao.newStoragePoolView(vr); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public static ObjectStoreResponse newImageStoreResponse(ImageDataStoreJoinVO vr) { |     public static ImageStoreResponse newImageStoreResponse(ImageStoreJoinVO vr) { | ||||||
|         return _imageStoreJoinDao.newObjectStoreResponse(vr); |         return _imageStoreJoinDao.newImageStoreResponse(vr); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public static ObjectStoreResponse fillImageStoreDetails(ObjectStoreResponse vrData, ImageDataStoreJoinVO vr){ |     public static ImageStoreResponse fillImageStoreDetails(ImageStoreResponse vrData, ImageStoreJoinVO vr){ | ||||||
|         return _imageStoreJoinDao.setObjectStoreResponse(vrData, vr); |         return _imageStoreJoinDao.setImageStoreResponse(vrData, vr); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public static List<ImageDataStoreJoinVO> newImageStoreView(ObjectStore vr){ |     public static List<ImageStoreJoinVO> newImageStoreView(ImageStore vr){ | ||||||
|         return _imageStoreJoinDao.newObjectStoreView(vr); |         return _imageStoreJoinDao.newImageStoreView(vr); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -80,7 +80,7 @@ import org.apache.cloudstack.api.response.NetworkOfferingResponse; | |||||||
| import org.apache.cloudstack.api.response.NetworkResponse; | import org.apache.cloudstack.api.response.NetworkResponse; | ||||||
| import org.apache.cloudstack.api.response.NicResponse; | import org.apache.cloudstack.api.response.NicResponse; | ||||||
| import org.apache.cloudstack.api.response.NicSecondaryIpResponse; | import org.apache.cloudstack.api.response.NicSecondaryIpResponse; | ||||||
| import org.apache.cloudstack.api.response.ObjectStoreResponse; | import org.apache.cloudstack.api.response.ImageStoreResponse; | ||||||
| import org.apache.cloudstack.api.response.PhysicalNetworkResponse; | import org.apache.cloudstack.api.response.PhysicalNetworkResponse; | ||||||
| import org.apache.cloudstack.api.response.PodResponse; | import org.apache.cloudstack.api.response.PodResponse; | ||||||
| import org.apache.cloudstack.api.response.PrivateGatewayResponse; | import org.apache.cloudstack.api.response.PrivateGatewayResponse; | ||||||
| @ -142,7 +142,7 @@ import com.cloud.api.query.vo.DiskOfferingJoinVO; | |||||||
| import com.cloud.api.query.vo.DomainRouterJoinVO; | import com.cloud.api.query.vo.DomainRouterJoinVO; | ||||||
| import com.cloud.api.query.vo.EventJoinVO; | import com.cloud.api.query.vo.EventJoinVO; | ||||||
| import com.cloud.api.query.vo.HostJoinVO; | import com.cloud.api.query.vo.HostJoinVO; | ||||||
| import com.cloud.api.query.vo.ImageDataStoreJoinVO; | import com.cloud.api.query.vo.ImageStoreJoinVO; | ||||||
| import com.cloud.api.query.vo.InstanceGroupJoinVO; | import com.cloud.api.query.vo.InstanceGroupJoinVO; | ||||||
| import com.cloud.api.query.vo.ProjectAccountJoinVO; | import com.cloud.api.query.vo.ProjectAccountJoinVO; | ||||||
| import com.cloud.api.query.vo.ProjectInvitationJoinVO; | import com.cloud.api.query.vo.ProjectInvitationJoinVO; | ||||||
| @ -237,7 +237,7 @@ import com.cloud.service.ServiceOfferingVO; | |||||||
| import com.cloud.storage.DiskOfferingVO; | import com.cloud.storage.DiskOfferingVO; | ||||||
| import com.cloud.storage.GuestOS; | import com.cloud.storage.GuestOS; | ||||||
| import com.cloud.storage.GuestOSCategoryVO; | import com.cloud.storage.GuestOSCategoryVO; | ||||||
| import com.cloud.storage.ObjectStore; | import com.cloud.storage.ImageStore; | ||||||
| import com.cloud.storage.S3; | import com.cloud.storage.S3; | ||||||
| import com.cloud.storage.Snapshot; | import com.cloud.storage.Snapshot; | ||||||
| import com.cloud.storage.SnapshotVO; | import com.cloud.storage.SnapshotVO; | ||||||
| @ -892,9 +892,9 @@ public class ApiResponseHelper implements ResponseGenerator { | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public ObjectStoreResponse createObjectStoreResponse(ObjectStore os) { |     public ImageStoreResponse createImageStoreResponse(ImageStore os) { | ||||||
|         List<ImageDataStoreJoinVO> viewStores = ApiDBUtils.newImageStoreView(os); |         List<ImageStoreJoinVO> viewStores = ApiDBUtils.newImageStoreView(os); | ||||||
|         List<ObjectStoreResponse> listStores = ViewResponseHelper.createObjectStoreResponse(viewStores.toArray(new ImageDataStoreJoinVO[viewStores.size()])); |         List<ImageStoreResponse> listStores = ViewResponseHelper.createObjectStoreResponse(viewStores.toArray(new ImageStoreJoinVO[viewStores.size()])); | ||||||
|         assert listStores != null && listStores.size() == 1 : "There should be one image data store returned"; |         assert listStores != null && listStores.size() == 1 : "There should be one image data store returned"; | ||||||
|         return listStores.get(0); |         return listStores.get(0); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -30,7 +30,7 @@ import org.apache.cloudstack.api.response.DomainRouterResponse; | |||||||
| import org.apache.cloudstack.api.response.EventResponse; | import org.apache.cloudstack.api.response.EventResponse; | ||||||
| import org.apache.cloudstack.api.response.HostResponse; | import org.apache.cloudstack.api.response.HostResponse; | ||||||
| import org.apache.cloudstack.api.response.InstanceGroupResponse; | import org.apache.cloudstack.api.response.InstanceGroupResponse; | ||||||
| import org.apache.cloudstack.api.response.ObjectStoreResponse; | import org.apache.cloudstack.api.response.ImageStoreResponse; | ||||||
| import org.apache.cloudstack.api.response.ProjectAccountResponse; | import org.apache.cloudstack.api.response.ProjectAccountResponse; | ||||||
| import org.apache.cloudstack.api.response.ProjectInvitationResponse; | import org.apache.cloudstack.api.response.ProjectInvitationResponse; | ||||||
| import org.apache.cloudstack.api.response.ProjectResponse; | import org.apache.cloudstack.api.response.ProjectResponse; | ||||||
| @ -52,7 +52,7 @@ import com.cloud.api.query.vo.DiskOfferingJoinVO; | |||||||
| import com.cloud.api.query.vo.DomainRouterJoinVO; | import com.cloud.api.query.vo.DomainRouterJoinVO; | ||||||
| import com.cloud.api.query.vo.EventJoinVO; | import com.cloud.api.query.vo.EventJoinVO; | ||||||
| import com.cloud.api.query.vo.HostJoinVO; | import com.cloud.api.query.vo.HostJoinVO; | ||||||
| import com.cloud.api.query.vo.ImageDataStoreJoinVO; | import com.cloud.api.query.vo.ImageStoreJoinVO; | ||||||
| import com.cloud.api.query.vo.InstanceGroupJoinVO; | import com.cloud.api.query.vo.InstanceGroupJoinVO; | ||||||
| import com.cloud.api.query.vo.ProjectAccountJoinVO; | import com.cloud.api.query.vo.ProjectAccountJoinVO; | ||||||
| import com.cloud.api.query.vo.ProjectInvitationJoinVO; | import com.cloud.api.query.vo.ProjectInvitationJoinVO; | ||||||
| @ -265,11 +265,11 @@ public class ViewResponseHelper { | |||||||
|         return new ArrayList<StoragePoolResponse>(vrDataList.values()); |         return new ArrayList<StoragePoolResponse>(vrDataList.values()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public static List<ObjectStoreResponse> createObjectStoreResponse(ImageDataStoreJoinVO... stores) { |     public static List<ImageStoreResponse> createObjectStoreResponse(ImageStoreJoinVO... stores) { | ||||||
|         Hashtable<Long, ObjectStoreResponse> vrDataList = new Hashtable<Long, ObjectStoreResponse>(); |         Hashtable<Long, ImageStoreResponse> vrDataList = new Hashtable<Long, ImageStoreResponse>(); | ||||||
|         // Initialise the vrdatalist with the input data |         // Initialise the vrdatalist with the input data | ||||||
|         for (ImageDataStoreJoinVO vr : stores) { |         for (ImageStoreJoinVO vr : stores) { | ||||||
|             ObjectStoreResponse vrData = vrDataList.get(vr.getId()); |             ImageStoreResponse vrData = vrDataList.get(vr.getId()); | ||||||
|             if ( vrData == null ){ |             if ( vrData == null ){ | ||||||
|                 // first time encountering this vm |                 // first time encountering this vm | ||||||
|                 vrData = ApiDBUtils.newImageStoreResponse(vr); |                 vrData = ApiDBUtils.newImageStoreResponse(vr); | ||||||
| @ -280,7 +280,7 @@ public class ViewResponseHelper { | |||||||
|             } |             } | ||||||
|             vrDataList.put(vr.getId(), vrData); |             vrDataList.put(vr.getId(), vrData); | ||||||
|         } |         } | ||||||
|         return new ArrayList<ObjectStoreResponse>(vrDataList.values()); |         return new ArrayList<ImageStoreResponse>(vrDataList.values()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -18,19 +18,19 @@ package com.cloud.api.query.dao; | |||||||
| 
 | 
 | ||||||
| import java.util.List; | import java.util.List; | ||||||
| 
 | 
 | ||||||
| import org.apache.cloudstack.api.response.ObjectStoreResponse; | import org.apache.cloudstack.api.response.ImageStoreResponse; | ||||||
| import com.cloud.api.query.vo.ImageDataStoreJoinVO; | import com.cloud.api.query.vo.ImageStoreJoinVO; | ||||||
| import com.cloud.storage.ObjectStore; | import com.cloud.storage.ImageStore; | ||||||
| import com.cloud.utils.db.GenericDao; | import com.cloud.utils.db.GenericDao; | ||||||
| 
 | 
 | ||||||
| public interface ImageDataStoreJoinDao extends GenericDao<ImageDataStoreJoinVO, Long> { | public interface ImageStoreJoinDao extends GenericDao<ImageStoreJoinVO, Long> { | ||||||
| 
 | 
 | ||||||
|     ObjectStoreResponse newObjectStoreResponse(ImageDataStoreJoinVO os); |     ImageStoreResponse newImageStoreResponse(ImageStoreJoinVO os); | ||||||
| 
 | 
 | ||||||
|     ObjectStoreResponse setObjectStoreResponse(ObjectStoreResponse response, ImageDataStoreJoinVO os); |     ImageStoreResponse setImageStoreResponse(ImageStoreResponse response, ImageStoreJoinVO os); | ||||||
| 
 | 
 | ||||||
|     List<ImageDataStoreJoinVO> newObjectStoreView(ObjectStore os); |     List<ImageStoreJoinVO> newImageStoreView(ImageStore os); | ||||||
| 
 | 
 | ||||||
|     List<ImageDataStoreJoinVO> searchByIds(Long... spIds); |     List<ImageStoreJoinVO> searchByIds(Long... spIds); | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
| @ -22,33 +22,33 @@ import java.util.List; | |||||||
| import javax.ejb.Local; | import javax.ejb.Local; | ||||||
| import javax.inject.Inject; | import javax.inject.Inject; | ||||||
| 
 | 
 | ||||||
| import org.apache.cloudstack.api.response.ObjectStoreDetailResponse; | import org.apache.cloudstack.api.response.ImageStoreDetailResponse; | ||||||
| import org.apache.cloudstack.api.response.ObjectStoreResponse; | import org.apache.cloudstack.api.response.ImageStoreResponse; | ||||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||||
| import org.springframework.stereotype.Component; | import org.springframework.stereotype.Component; | ||||||
| 
 | 
 | ||||||
| import com.cloud.api.query.vo.ImageDataStoreJoinVO; | import com.cloud.api.query.vo.ImageStoreJoinVO; | ||||||
| import com.cloud.configuration.dao.ConfigurationDao; | import com.cloud.configuration.dao.ConfigurationDao; | ||||||
| import com.cloud.storage.ObjectStore; | import com.cloud.storage.ImageStore; | ||||||
| import com.cloud.utils.db.GenericDaoBase; | import com.cloud.utils.db.GenericDaoBase; | ||||||
| import com.cloud.utils.db.SearchBuilder; | import com.cloud.utils.db.SearchBuilder; | ||||||
| import com.cloud.utils.db.SearchCriteria; | import com.cloud.utils.db.SearchCriteria; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @Component | @Component | ||||||
| @Local(value={ImageDataStoreJoinDao.class}) | @Local(value={ImageStoreJoinDao.class}) | ||||||
| public class ImageDataStoreJoinDaoImpl extends GenericDaoBase<ImageDataStoreJoinVO, Long> implements ImageDataStoreJoinDao { | public class ImageStoreJoinDaoImpl extends GenericDaoBase<ImageStoreJoinVO, Long> implements ImageStoreJoinDao { | ||||||
|     public static final Logger s_logger = Logger.getLogger(ImageDataStoreJoinDaoImpl.class); |     public static final Logger s_logger = Logger.getLogger(ImageStoreJoinDaoImpl.class); | ||||||
| 
 | 
 | ||||||
|     @Inject |     @Inject | ||||||
|     private ConfigurationDao  _configDao; |     private ConfigurationDao  _configDao; | ||||||
| 
 | 
 | ||||||
|     private final SearchBuilder<ImageDataStoreJoinVO> dsSearch; |     private final SearchBuilder<ImageStoreJoinVO> dsSearch; | ||||||
| 
 | 
 | ||||||
|     private final SearchBuilder<ImageDataStoreJoinVO> dsIdSearch; |     private final SearchBuilder<ImageStoreJoinVO> dsIdSearch; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     protected ImageDataStoreJoinDaoImpl() { |     protected ImageStoreJoinDaoImpl() { | ||||||
| 
 | 
 | ||||||
|         dsSearch = createSearchBuilder(); |         dsSearch = createSearchBuilder(); | ||||||
|         dsSearch.and("idIN", dsSearch.entity().getId(), SearchCriteria.Op.IN); |         dsSearch.and("idIN", dsSearch.entity().getId(), SearchCriteria.Op.IN); | ||||||
| @ -66,8 +66,8 @@ public class ImageDataStoreJoinDaoImpl extends GenericDaoBase<ImageDataStoreJoin | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public ObjectStoreResponse newObjectStoreResponse(ImageDataStoreJoinVO ids) { |     public ImageStoreResponse newImageStoreResponse(ImageStoreJoinVO ids) { | ||||||
|         ObjectStoreResponse osResponse = new ObjectStoreResponse(); |         ImageStoreResponse osResponse = new ImageStoreResponse(); | ||||||
|         osResponse.setId(ids.getUuid()); |         osResponse.setId(ids.getUuid()); | ||||||
|         osResponse.setName(ids.getName()); |         osResponse.setName(ids.getName()); | ||||||
|         osResponse.setProviderName(ids.getProviderName()); |         osResponse.setProviderName(ids.getProviderName()); | ||||||
| @ -76,15 +76,14 @@ public class ImageDataStoreJoinDaoImpl extends GenericDaoBase<ImageDataStoreJoin | |||||||
|         osResponse.setScope(ids.getScope()); |         osResponse.setScope(ids.getScope()); | ||||||
|         osResponse.setZoneId(ids.getZoneUuid()); |         osResponse.setZoneId(ids.getZoneUuid()); | ||||||
|         osResponse.setZoneName(ids.getZoneName()); |         osResponse.setZoneName(ids.getZoneName()); | ||||||
|         osResponse.setRegionId(ids.getRegionId()); |         osResponse.setState(ids.getState()); | ||||||
|         osResponse.setRegionName(ids.getRegionName()); |  | ||||||
| 
 | 
 | ||||||
|         String detailName = ids.getDetailName(); |         String detailName = ids.getDetailName(); | ||||||
|         if ( detailName != null && detailName.length() > 0 ){ |         if ( detailName != null && detailName.length() > 0 ){ | ||||||
|             ObjectStoreDetailResponse osdResponse = new ObjectStoreDetailResponse(detailName, ids.getDetailValue()); |             ImageStoreDetailResponse osdResponse = new ImageStoreDetailResponse(detailName, ids.getDetailValue()); | ||||||
|             osResponse.addDetail(osdResponse); |             osResponse.addDetail(osdResponse); | ||||||
|         } |         } | ||||||
|         osResponse.setObjectName("objectstore"); |         osResponse.setObjectName("imagestore"); | ||||||
|         return osResponse; |         return osResponse; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -93,10 +92,10 @@ public class ImageDataStoreJoinDaoImpl extends GenericDaoBase<ImageDataStoreJoin | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public ObjectStoreResponse setObjectStoreResponse(ObjectStoreResponse response, ImageDataStoreJoinVO ids) { |     public ImageStoreResponse setImageStoreResponse(ImageStoreResponse response, ImageStoreJoinVO ids) { | ||||||
|         String detailName = ids.getDetailName(); |         String detailName = ids.getDetailName(); | ||||||
|         if ( detailName != null && detailName.length() > 0 ){ |         if ( detailName != null && detailName.length() > 0 ){ | ||||||
|             ObjectStoreDetailResponse osdResponse = new ObjectStoreDetailResponse(detailName, ids.getDetailValue()); |             ImageStoreDetailResponse osdResponse = new ImageStoreDetailResponse(detailName, ids.getDetailValue()); | ||||||
|             response.addDetail(osdResponse); |             response.addDetail(osdResponse); | ||||||
|         } |         } | ||||||
|         return response; |         return response; | ||||||
| @ -105,8 +104,8 @@ public class ImageDataStoreJoinDaoImpl extends GenericDaoBase<ImageDataStoreJoin | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public List<ImageDataStoreJoinVO> newObjectStoreView(ObjectStore os) { |     public List<ImageStoreJoinVO> newImageStoreView(ImageStore os) { | ||||||
|         SearchCriteria<ImageDataStoreJoinVO> sc = dsIdSearch.create(); |         SearchCriteria<ImageStoreJoinVO> sc = dsIdSearch.create(); | ||||||
|         sc.setParameters("id", os.getId()); |         sc.setParameters("id", os.getId()); | ||||||
|         return searchIncludingRemoved(sc, null, null, false); |         return searchIncludingRemoved(sc, null, null, false); | ||||||
| 
 | 
 | ||||||
| @ -115,7 +114,7 @@ public class ImageDataStoreJoinDaoImpl extends GenericDaoBase<ImageDataStoreJoin | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public List<ImageDataStoreJoinVO> searchByIds(Long... spIds) { |     public List<ImageStoreJoinVO> searchByIds(Long... spIds) { | ||||||
|         // set detail batch query size |         // set detail batch query size | ||||||
|         int DETAILS_BATCH_SIZE = 2000; |         int DETAILS_BATCH_SIZE = 2000; | ||||||
|         String batchCfg = _configDao.getValue("detail.batch.query.size"); |         String batchCfg = _configDao.getValue("detail.batch.query.size"); | ||||||
| @ -123,7 +122,7 @@ public class ImageDataStoreJoinDaoImpl extends GenericDaoBase<ImageDataStoreJoin | |||||||
|             DETAILS_BATCH_SIZE = Integer.parseInt(batchCfg); |             DETAILS_BATCH_SIZE = Integer.parseInt(batchCfg); | ||||||
|         } |         } | ||||||
|         // query details by batches |         // query details by batches | ||||||
|         List<ImageDataStoreJoinVO> uvList = new ArrayList<ImageDataStoreJoinVO>(); |         List<ImageStoreJoinVO> uvList = new ArrayList<ImageStoreJoinVO>(); | ||||||
|         // query details by batches |         // query details by batches | ||||||
|         int curr_index = 0; |         int curr_index = 0; | ||||||
|         if ( spIds.length > DETAILS_BATCH_SIZE ){ |         if ( spIds.length > DETAILS_BATCH_SIZE ){ | ||||||
| @ -132,9 +131,9 @@ public class ImageDataStoreJoinDaoImpl extends GenericDaoBase<ImageDataStoreJoin | |||||||
|                 for (int k = 0, j = curr_index; j < curr_index + DETAILS_BATCH_SIZE; j++, k++) { |                 for (int k = 0, j = curr_index; j < curr_index + DETAILS_BATCH_SIZE; j++, k++) { | ||||||
|                     ids[k] = spIds[j]; |                     ids[k] = spIds[j]; | ||||||
|                 } |                 } | ||||||
|                 SearchCriteria<ImageDataStoreJoinVO> sc = dsSearch.create(); |                 SearchCriteria<ImageStoreJoinVO> sc = dsSearch.create(); | ||||||
|                 sc.setParameters("idIN", ids); |                 sc.setParameters("idIN", ids); | ||||||
|                 List<ImageDataStoreJoinVO> vms = searchIncludingRemoved(sc, null, null, false); |                 List<ImageStoreJoinVO> vms = searchIncludingRemoved(sc, null, null, false); | ||||||
|                 if (vms != null) { |                 if (vms != null) { | ||||||
|                     uvList.addAll(vms); |                     uvList.addAll(vms); | ||||||
|                 } |                 } | ||||||
| @ -148,9 +147,9 @@ public class ImageDataStoreJoinDaoImpl extends GenericDaoBase<ImageDataStoreJoin | |||||||
|             for (int k = 0, j = curr_index; j < curr_index + batch_size; j++, k++) { |             for (int k = 0, j = curr_index; j < curr_index + batch_size; j++, k++) { | ||||||
|                 ids[k] = spIds[j]; |                 ids[k] = spIds[j]; | ||||||
|             } |             } | ||||||
|             SearchCriteria<ImageDataStoreJoinVO> sc = dsSearch.create(); |             SearchCriteria<ImageStoreJoinVO> sc = dsSearch.create(); | ||||||
|             sc.setParameters("idIN", ids); |             sc.setParameters("idIN", ids); | ||||||
|             List<ImageDataStoreJoinVO> vms = searchIncludingRemoved(sc, null, null, false); |             List<ImageStoreJoinVO> vms = searchIncludingRemoved(sc, null, null, false); | ||||||
|             if (vms != null) { |             if (vms != null) { | ||||||
|                 uvList.addAll(vms); |                 uvList.addAll(vms); | ||||||
|             } |             } | ||||||
| @ -22,6 +22,8 @@ import javax.persistence.EnumType; | |||||||
| import javax.persistence.Enumerated; | import javax.persistence.Enumerated; | ||||||
| import javax.persistence.Id; | import javax.persistence.Id; | ||||||
| import javax.persistence.Table; | import javax.persistence.Table; | ||||||
|  | 
 | ||||||
|  | import com.cloud.storage.ImageStore; | ||||||
| import com.cloud.storage.ScopeType; | import com.cloud.storage.ScopeType; | ||||||
| import org.apache.cloudstack.api.Identity; | import org.apache.cloudstack.api.Identity; | ||||||
| import org.apache.cloudstack.api.InternalIdentity; | import org.apache.cloudstack.api.InternalIdentity; | ||||||
| @ -31,8 +33,8 @@ import org.apache.cloudstack.api.InternalIdentity; | |||||||
|  * |  * | ||||||
|  */ |  */ | ||||||
| @Entity | @Entity | ||||||
| @Table(name="image_data_store_view") | @Table(name="image_store_view") | ||||||
| public class ImageDataStoreJoinVO extends BaseViewVO implements InternalIdentity, Identity { | public class ImageStoreJoinVO extends BaseViewVO implements InternalIdentity, Identity { | ||||||
| 
 | 
 | ||||||
|     @Id |     @Id | ||||||
|     @Column(name="id") |     @Column(name="id") | ||||||
| @ -66,11 +68,8 @@ public class ImageDataStoreJoinVO extends BaseViewVO implements InternalIdentity | |||||||
|     @Column(name="data_center_name") |     @Column(name="data_center_name") | ||||||
|     private String zoneName; |     private String zoneName; | ||||||
| 
 | 
 | ||||||
|     @Column(name="region_id") |     @Column(name="state") | ||||||
|     private long regionId; |     private ImageStore.State state; | ||||||
| 
 |  | ||||||
|     @Column(name="region_name") |  | ||||||
|     private String regionName; |  | ||||||
| 
 | 
 | ||||||
|     @Column(name="detail_name") |     @Column(name="detail_name") | ||||||
|     private String detailName; |     private String detailName; | ||||||
| @ -160,20 +159,13 @@ public class ImageDataStoreJoinVO extends BaseViewVO implements InternalIdentity | |||||||
|         this.scope = scope; |         this.scope = scope; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public long getRegionId() { | 
 | ||||||
|         return regionId; |     public ImageStore.State getState() { | ||||||
|  |         return state; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public void setRegionId(long regionId) { |     public void setState(ImageStore.State state) { | ||||||
|         this.regionId = regionId; |         this.state = state; | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public String getRegionName() { |  | ||||||
|         return regionName; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     public void setRegionName(String regionName) { |  | ||||||
|         this.regionName = regionName; |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public void setName(String name) { |     public void setName(String name) { | ||||||
| @ -25,13 +25,14 @@ import javax.persistence.Enumerated; | |||||||
| import javax.persistence.Id; | import javax.persistence.Id; | ||||||
| import javax.persistence.Table; | import javax.persistence.Table; | ||||||
| import com.cloud.org.Cluster; | import com.cloud.org.Cluster; | ||||||
|  | import com.cloud.storage.ScopeType; | ||||||
| import com.cloud.storage.StoragePoolStatus; | import com.cloud.storage.StoragePoolStatus; | ||||||
| import com.cloud.storage.Storage.StoragePoolType; | import com.cloud.storage.Storage.StoragePoolType; | ||||||
| import com.cloud.utils.db.GenericDao; | import com.cloud.utils.db.GenericDao; | ||||||
| 
 | 
 | ||||||
| import org.apache.cloudstack.api.Identity; | import org.apache.cloudstack.api.Identity; | ||||||
| import org.apache.cloudstack.api.InternalIdentity; | import org.apache.cloudstack.api.InternalIdentity; | ||||||
| import org.apache.cloudstack.engine.subsystem.api.storage.ScopeType; | 
 | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  * Storage Pool DB view. |  * Storage Pool DB view. | ||||||
|  | |||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @ -19,6 +19,7 @@ | |||||||
| package com.cloud.storage.s3; | package com.cloud.storage.s3; | ||||||
| 
 | 
 | ||||||
| import java.util.List; | import java.util.List; | ||||||
|  | import java.util.Map; | ||||||
| 
 | 
 | ||||||
| import com.cloud.agent.api.to.S3TO; | import com.cloud.agent.api.to.S3TO; | ||||||
| import org.apache.cloudstack.api.command.admin.storage.AddS3Cmd; | import org.apache.cloudstack.api.command.admin.storage.AddS3Cmd; | ||||||
| @ -40,6 +41,8 @@ public interface S3Manager extends Manager { | |||||||
| 
 | 
 | ||||||
|     S3 addS3(AddS3Cmd addS3Cmd) throws DiscoveryException; |     S3 addS3(AddS3Cmd addS3Cmd) throws DiscoveryException; | ||||||
| 
 | 
 | ||||||
|  |     void verifyS3Fields(Map<String, String> params) throws DiscoveryException; | ||||||
|  | 
 | ||||||
|     Long chooseZoneForTemplateExtract(VMTemplateVO template); |     Long chooseZoneForTemplateExtract(VMTemplateVO template); | ||||||
| 
 | 
 | ||||||
|     boolean isS3Enabled(); |     boolean isS3Enabled(); | ||||||
|  | |||||||
| @ -46,6 +46,7 @@ import javax.ejb.Local; | |||||||
| import javax.inject.Inject; | import javax.inject.Inject; | ||||||
| import javax.naming.ConfigurationException; | import javax.naming.ConfigurationException; | ||||||
| 
 | 
 | ||||||
|  | import org.apache.cloudstack.api.ApiConstants; | ||||||
| import org.apache.cloudstack.api.command.admin.storage.AddS3Cmd; | import org.apache.cloudstack.api.command.admin.storage.AddS3Cmd; | ||||||
| import org.apache.cloudstack.api.command.admin.storage.ListS3sCmd; | import org.apache.cloudstack.api.command.admin.storage.ListS3sCmd; | ||||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||||
| @ -95,6 +96,7 @@ public class S3ManagerImpl extends ManagerBase implements S3Manager { | |||||||
|     @Inject |     @Inject | ||||||
|     private S3Dao s3Dao; |     private S3Dao s3Dao; | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|     @Inject |     @Inject | ||||||
|     private VMTemplateZoneDao vmTemplateZoneDao; |     private VMTemplateZoneDao vmTemplateZoneDao; | ||||||
| 
 | 
 | ||||||
| @ -247,6 +249,26 @@ public class S3ManagerImpl extends ManagerBase implements S3Manager { | |||||||
| 
 | 
 | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
|  |     @Override | ||||||
|  |     public void verifyS3Fields(Map<String, String> params) throws DiscoveryException { | ||||||
|  |         final S3VO s3VO = new S3VO(UUID.randomUUID().toString(), | ||||||
|  |                 params.get(ApiConstants.S3_ACCESS_KEY), | ||||||
|  |                 params.get(ApiConstants.S3_SECRET_KEY), | ||||||
|  |                 params.get(ApiConstants.S3_END_POINT), | ||||||
|  |                 params.get(ApiConstants.S3_BUCKET_NAME), | ||||||
|  |                 Boolean.valueOf(params.get(ApiConstants.S3_HTTPS_FLAG)), | ||||||
|  |                 Integer.valueOf(params.get(ApiConstants.S3_CONNECTION_TIMEOUT)), | ||||||
|  |                 Integer.valueOf(params.get(ApiConstants.S3_MAX_ERROR_RETRY)), | ||||||
|  |                 Integer.valueOf(params.get(ApiConstants.S3_SOCKET_TIMEOUT)), now()); | ||||||
|  | 
 | ||||||
|  |         this.validateFields(s3VO); | ||||||
|  | 
 | ||||||
|  |         final S3TO s3 = s3VO.toS3TO(); | ||||||
|  |         this.verifyConnection(s3); | ||||||
|  |         this.verifyBuckets(s3); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     @Override |     @Override | ||||||
|     public boolean isS3Enabled() { |     public boolean isS3Enabled() { | ||||||
|         return Boolean |         return Boolean | ||||||
|  | |||||||
| @ -49,7 +49,7 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType; | |||||||
| import com.cloud.org.Cluster; | import com.cloud.org.Cluster; | ||||||
| import com.cloud.resource.ResourceState.Event; | import com.cloud.resource.ResourceState.Event; | ||||||
| import com.cloud.service.ServiceOfferingVO; | import com.cloud.service.ServiceOfferingVO; | ||||||
| import com.cloud.storage.ObjectStore; | import com.cloud.storage.ImageStore; | ||||||
| import com.cloud.storage.S3; | import com.cloud.storage.S3; | ||||||
| import com.cloud.storage.Swift; | import com.cloud.storage.Swift; | ||||||
| import com.cloud.template.VirtualMachineTemplate; | import com.cloud.template.VirtualMachineTemplate; | ||||||
| @ -610,7 +610,7 @@ public class MockResourceManagerImpl extends ManagerBase implements ResourceMana | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|     @Override |     @Override | ||||||
|     public ObjectStore discoverObjectStore(AddSecondaryStorageCmd cmd) throws IllegalArgumentException, DiscoveryException, |     public ImageStore discoverImageStore(AddImageStoreCmd cmd) throws IllegalArgumentException, DiscoveryException, | ||||||
|             InvalidParameterValueException { |             InvalidParameterValueException { | ||||||
|         // TODO Auto-generated method stub |         // TODO Auto-generated method stub | ||||||
|         return null; |         return null; | ||||||
|  | |||||||
| @ -68,54 +68,53 @@ CREATE TABLE  `cloud`.`object_datastore_ref` ( | |||||||
| --  PRIMARY KEY(`id`) | --  PRIMARY KEY(`id`) | ||||||
| -- ) ENGINE=InnoDB DEFAULT CHARSET=utf8; | -- ) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||||||
| 
 | 
 | ||||||
| CREATE TABLE `cloud`.`image_data_store` ( | CREATE TABLE `cloud`.`image_store` ( | ||||||
|   `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', |   `id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT 'id', | ||||||
|   `name` varchar(255) NOT NULL COMMENT 'name of data store', |   `name` varchar(255) NOT NULL COMMENT 'name of data store', | ||||||
|   `image_provider_name` varchar(255) NOT NULL COMMENT 'id of image_data_store_provider', |   `image_provider_name` varchar(255) NOT NULL COMMENT 'id of image_store_provider', | ||||||
|   `protocol` varchar(255) NOT NULL COMMENT 'protocol of data store', |   `protocol` varchar(255) NOT NULL COMMENT 'protocol of data store', | ||||||
|   `url` varchar(255) COMMENT 'url for image data store', |   `url` varchar(255) COMMENT 'url for image data store', | ||||||
|   `data_center_id` bigint unsigned  COMMENT 'datacenter id of data store', |   `data_center_id` bigint unsigned  COMMENT 'datacenter id of data store', | ||||||
|   `region_id` bigint unsigned  COMMENT 'region id of data store', |  | ||||||
|   `scope` varchar(255) COMMENT 'scope of data store', |   `scope` varchar(255) COMMENT 'scope of data store', | ||||||
|   `uuid` varchar(255) COMMENT 'uuid of data store', |   `uuid` varchar(255) COMMENT 'uuid of data store', | ||||||
|  |   `state` varchar(30) COMMENT 'state of data store', | ||||||
|  |   `created` datetime COMMENT 'date the image store first signed on', | ||||||
|  |   `removed` datetime COMMENT 'date removed if not null',   | ||||||
|   PRIMARY KEY(`id`) |   PRIMARY KEY(`id`) | ||||||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||||||
| 
 | 
 | ||||||
| CREATE TABLE `cloud`.`image_data_store_details` ( | CREATE TABLE `cloud`.`image_store_details` ( | ||||||
|   `id` bigint unsigned UNIQUE NOT NULL AUTO_INCREMENT COMMENT 'id', |   `id` bigint unsigned UNIQUE NOT NULL AUTO_INCREMENT COMMENT 'id', | ||||||
|   `store_id` bigint unsigned NOT NULL COMMENT 'store the detail is related to', |   `store_id` bigint unsigned NOT NULL COMMENT 'store the detail is related to', | ||||||
|   `name` varchar(255) NOT NULL COMMENT 'name of the detail', |   `name` varchar(255) NOT NULL COMMENT 'name of the detail', | ||||||
|   `value` varchar(255) NOT NULL COMMENT 'value of the detail', |   `value` varchar(255) NOT NULL COMMENT 'value of the detail', | ||||||
|   PRIMARY KEY (`id`), |   PRIMARY KEY (`id`), | ||||||
|   CONSTRAINT `fk_image_data_store_details__store_id` FOREIGN KEY `fk_image_data_store__store_id`(`store_id`) REFERENCES `image_data_store`(`id`) ON DELETE CASCADE, |   CONSTRAINT `fk_image_store_details__store_id` FOREIGN KEY `fk_image_store__store_id`(`store_id`) REFERENCES `image_store`(`id`) ON DELETE CASCADE, | ||||||
|   INDEX `i_image_data_store__name__value`(`name`(128), `value`(128)) |   INDEX `i_image_store__name__value`(`name`(128), `value`(128)) | ||||||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; | ||||||
| 
 | 
 | ||||||
| DROP VIEW IF EXISTS `cloud`.`image_data_store_view`; | DROP VIEW IF EXISTS `cloud`.`image_store_view`; | ||||||
| CREATE VIEW `cloud`.`image_data_store_view` AS | CREATE VIEW `cloud`.`image_store_view` AS | ||||||
|     select  |     select  | ||||||
|         image_data_store.id, |         image_store.id, | ||||||
|         image_data_store.uuid, |         image_store.uuid, | ||||||
|         image_data_store.name, |         image_store.name, | ||||||
|         image_data_store.provider_name, |         image_store.image_provider_name, | ||||||
|         image_data_store.protocol, |         image_store.protocol, | ||||||
|         image_data_store.url, |         image_store.url, | ||||||
|         image_data_store.scope, |         image_store.scope, | ||||||
|  |         image_store.state, | ||||||
|         data_center.id data_center_id, |         data_center.id data_center_id, | ||||||
|         data_center.uuid data_center_uuid, |         data_center.uuid data_center_uuid, | ||||||
|         data_center.name data_center_name, |         data_center.name data_center_name, | ||||||
|         region.id region_id, |         image_store_details.name detail_name, | ||||||
|         region.name region_name, |         image_store_details.value detail_value | ||||||
|         image_data_store_details.name detail_name, |  | ||||||
|         image_data_store_details.value detail_value |  | ||||||
|     from |     from | ||||||
|         `cloud`.`image_data_store` |         `cloud`.`image_store` | ||||||
|             left join |             left join | ||||||
|         `cloud`.`data_center` ON image_data_store.data_center_id = data_center.id |         `cloud`.`data_center` ON image_store.data_center_id = data_center.id | ||||||
|             left join |             left join | ||||||
|         `cloud`.`region` ON image_data_store.region_id = region.id |         `cloud`.`image_store_details` ON image_store_details.store_id = image_store.id; | ||||||
|             left join |  | ||||||
|         `cloud`.`image_data_store_details` ON image_data_store_details.store_id = image_data_store.id; |  | ||||||
|              |              | ||||||
|              |              | ||||||
| CREATE TABLE  `cloud`.`template_store_ref` ( | CREATE TABLE  `cloud`.`template_store_ref` ( | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user