mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-15 18:12:35 +01:00
refactor api, based on suggestion from community
This commit is contained in:
parent
8ba00f7558
commit
8af85b04d0
@ -30,6 +30,11 @@
|
||||
<artifactId>cloud-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cloudstack</groupId>
|
||||
<artifactId>cloud-framework-ipc</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-bundle-jaxrs</artifactId>
|
||||
|
||||
@ -20,7 +20,7 @@ package org.apache.cloudstack.engine.cloud.entity.api;
|
||||
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.StorageEntity;
|
||||
import org.apache.cloudstack.engine.entity.api.CloudStackEntity;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.DiskFormat;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeType;
|
||||
|
||||
|
||||
@ -76,12 +76,9 @@ public interface VolumeEntity extends CloudStackEntity {
|
||||
|
||||
long getSize();
|
||||
|
||||
VolumeDiskType getDiskType();
|
||||
DiskFormat getDiskType();
|
||||
|
||||
VolumeType getType();
|
||||
|
||||
StorageEntity getDataStore();
|
||||
|
||||
boolean createVolumeFromTemplate(long dataStoreId, VolumeDiskType diskType, TemplateEntity template);
|
||||
boolean createVolume(long dataStoreId, VolumeDiskType diskType);
|
||||
}
|
||||
|
||||
@ -16,21 +16,24 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.command;
|
||||
package org.apache.cloudstack.engine.subsystem.api.storage;
|
||||
|
||||
public class CommandResult {
|
||||
private boolean success;
|
||||
private String result;
|
||||
|
||||
public CommandResult() {
|
||||
this.success = true;
|
||||
this.result = "";
|
||||
}
|
||||
|
||||
|
||||
public boolean isSuccess() {
|
||||
return this.success;
|
||||
}
|
||||
|
||||
public boolean isFailed() {
|
||||
return !this.success;
|
||||
}
|
||||
|
||||
public void setSucess(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
@ -16,16 +16,16 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image.store;
|
||||
package org.apache.cloudstack.engine.subsystem.api.storage;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.DataStore;
|
||||
import org.apache.cloudstack.storage.image.TemplateObject;
|
||||
|
||||
public interface ImageDataStore extends ImageDataStoreInfo {
|
||||
TemplateObject registerTemplate(long templateId);
|
||||
boolean deleteTemplate(long templateId);
|
||||
|
||||
boolean needDownloadToCacheStorage();
|
||||
public class CopyCommandResult extends CommandResult {
|
||||
private final String path;
|
||||
public CopyCommandResult(String path) {
|
||||
super();
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
TemplateObject getTemplate(long templateId);
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.engine.subsystem.api.storage;
|
||||
|
||||
public class CreateCmdResult extends CommandResult {
|
||||
private String path;
|
||||
public CreateCmdResult(String path) {
|
||||
super();
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.engine.subsystem.api.storage;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.DiskFormat;
|
||||
|
||||
public interface DataObject {
|
||||
public long getId();
|
||||
public String getUri();
|
||||
public DataStore getDataStore();
|
||||
public long getSize();
|
||||
public DataObjectType getType();
|
||||
public DiskFormat getFormat();
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.engine.subsystem.api.storage;
|
||||
|
||||
public enum DataObjectType {
|
||||
VOLUME,
|
||||
SNAPSHOT,
|
||||
TEMPLATE
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package org.apache.cloudstack.engine.subsystem.api.storage;
|
||||
|
||||
public interface DataStore {
|
||||
DataStoreDriver getDriver();
|
||||
DataStoreRole getRole();
|
||||
long getId();
|
||||
String getUri();
|
||||
Scope getScope();
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.engine.subsystem.api.storage;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
||||
|
||||
public interface DataStoreDriver {
|
||||
public String grantAccess(DataObject data, EndPoint ep);
|
||||
public boolean revokeAccess(DataObject data, EndPoint ep);
|
||||
public Set<DataObject> listObjects(DataStore store);
|
||||
public void createAsync(DataObject data, AsyncCompletionCallback<CreateCmdResult> callback);
|
||||
public void deleteAsync(DataObject data, AsyncCompletionCallback<CommandResult> callback);
|
||||
public void copyAsync(DataObject srcdata, DataObject destData, AsyncCompletionCallback<CopyCommandResult> callback);
|
||||
public boolean canCopy(DataObject srcData, DataObject destData);
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.engine.subsystem.api.storage;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public interface DataStoreLifeCycle {
|
||||
public boolean initialize(DataStore store, Map<String, String> dsInfos);
|
||||
|
||||
public boolean attachCluster(DataStore store, ClusterScope scope);
|
||||
|
||||
boolean attachZone(DataStore dataStore, ZoneScope scope);
|
||||
|
||||
public boolean dettach();
|
||||
|
||||
public boolean unmanaged();
|
||||
|
||||
public boolean maintain();
|
||||
|
||||
public boolean cancelMaintain();
|
||||
|
||||
public boolean deleteDataStore();
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.engine.subsystem.api.storage;
|
||||
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public enum DataStoreRole {
|
||||
Primary("primary"),
|
||||
Image("image"),
|
||||
ImageCache("imagecache"),
|
||||
Backup("backup");
|
||||
|
||||
public boolean isImageStore() {
|
||||
return (this.role.equalsIgnoreCase("image") || this.role.equalsIgnoreCase("imagecache")) ? true : false;
|
||||
}
|
||||
|
||||
private final String role;
|
||||
DataStoreRole(String type) {
|
||||
this.role = type;
|
||||
}
|
||||
|
||||
public static DataStoreRole getRole(String role) {
|
||||
if (role == null) {
|
||||
throw new CloudRuntimeException("role can't be empty");
|
||||
}
|
||||
if (role.equalsIgnoreCase("primary")) {
|
||||
return Primary;
|
||||
} else if (role.equalsIgnoreCase("image")) {
|
||||
return Image;
|
||||
} else if (role.equalsIgnoreCase("imagecache")) {
|
||||
return ImageCache;
|
||||
} else if (role.equalsIgnoreCase("backup")) {
|
||||
return Backup;
|
||||
} else {
|
||||
throw new CloudRuntimeException("can't identify the role");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
package org.apache.cloudstack.engine.subsystem.api.storage;
|
||||
|
||||
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
|
||||
public interface EndPoint {
|
||||
public Answer sendMessage(Command cmd);
|
||||
public void sendMessageAsync(Command cmd, AsyncCompletionCallback<Answer> callback);
|
||||
}
|
||||
@ -20,17 +20,13 @@ package org.apache.cloudstack.engine.subsystem.api.storage;
|
||||
|
||||
|
||||
import org.apache.cloudstack.engine.datacenter.entity.api.DataCenterResourceEntity;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
|
||||
|
||||
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.DiskFormat;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.storage.Volume;
|
||||
|
||||
public interface PrimaryDataStoreInfo {
|
||||
public boolean isHypervisorSupported(HypervisorType hypervisor);
|
||||
public boolean isLocalStorageSupported();
|
||||
public boolean isVolumeDiskTypeSupported(VolumeDiskType diskType);
|
||||
public boolean isVolumeDiskTypeSupported(DiskFormat diskType);
|
||||
public long getCapacity();
|
||||
public long getAvailableCapacity();
|
||||
|
||||
@ -40,6 +36,4 @@ public interface PrimaryDataStoreInfo {
|
||||
public String getName();
|
||||
public String getType();
|
||||
public PrimaryDataStoreLifeCycle getLifeCycle();
|
||||
PrimaryDataStoreProvider getProvider();
|
||||
|
||||
}
|
||||
|
||||
@ -18,25 +18,6 @@
|
||||
*/
|
||||
package org.apache.cloudstack.engine.subsystem.api.storage;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface PrimaryDataStoreLifeCycle {
|
||||
public boolean initialize(Map<String, String> dsInfos);
|
||||
|
||||
public boolean attachCluster(ClusterScope scope);
|
||||
|
||||
public boolean dettach();
|
||||
|
||||
public boolean unmanaged();
|
||||
|
||||
public boolean maintain();
|
||||
|
||||
public boolean cancelMaintain();
|
||||
|
||||
public boolean deleteDataStore();
|
||||
|
||||
/**
|
||||
* @param dataStore
|
||||
*/
|
||||
void setDataStore(PrimaryDataStoreInfo dataStore);
|
||||
public interface PrimaryDataStoreLifeCycle extends DataStoreLifeCycle {
|
||||
}
|
||||
|
||||
@ -14,21 +14,3 @@
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.engine.subsystem.api.storage;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface PrimaryDataStoreProvider {
|
||||
public PrimaryDataStoreInfo getDataStore(long dataStoreId);
|
||||
public long getId();
|
||||
public String getName();
|
||||
|
||||
/**
|
||||
* @param dsInfos
|
||||
* @return
|
||||
*/
|
||||
PrimaryDataStoreInfo registerDataStore(Map<String, String> dsInfos);
|
||||
|
||||
//LifeCycle of provider
|
||||
public boolean configure();
|
||||
}
|
||||
|
||||
@ -22,7 +22,7 @@ import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity;
|
||||
import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.DiskFormat;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeType;
|
||||
|
||||
import com.cloud.deploy.DeploymentPlan;
|
||||
@ -62,7 +62,7 @@ public interface StorageOrchestrator {
|
||||
*/
|
||||
void prepareAttachDiskToVM(long diskId, long vmId, String reservationId);
|
||||
|
||||
boolean createVolume(VolumeEntity volume, long dataStoreId, VolumeDiskType diskType);
|
||||
boolean createVolumeFromTemplate(VolumeEntity volume, long dataStoreId, VolumeDiskType dis, TemplateEntity template);
|
||||
boolean createVolume(VolumeEntity volume, long dataStoreId, DiskFormat diskType);
|
||||
boolean createVolumeFromTemplate(VolumeEntity volume, long dataStoreId, DiskFormat dis, TemplateEntity template);
|
||||
VolumeEntity allocateVolumeInDb(long size, VolumeType type,String volName, Long templateId);
|
||||
}
|
||||
|
||||
@ -19,28 +19,12 @@
|
||||
package org.apache.cloudstack.engine.subsystem.api.storage;
|
||||
|
||||
|
||||
import java.util.Date;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.DiskFormat;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeType;
|
||||
|
||||
import com.cloud.storage.Volume;
|
||||
|
||||
public interface VolumeInfo {
|
||||
public long getSize();
|
||||
public interface VolumeInfo extends DataObject {
|
||||
public String getUuid();
|
||||
public String getPath();
|
||||
public PrimaryDataStoreInfo getDataStore() ;
|
||||
public String getTemplateUuid();
|
||||
public String getTemplatePath();
|
||||
public VolumeType getType();
|
||||
public VolumeDiskType getDiskType();
|
||||
public long getId();
|
||||
public Volume.State getCurrentState();
|
||||
public Volume.State getDesiredState();
|
||||
public Date getCreatedDate();
|
||||
public Date getUpdatedDate();
|
||||
public String getOwner();
|
||||
public String getName();
|
||||
|
||||
public boolean isAttachedVM();
|
||||
public String getPath();
|
||||
}
|
||||
|
||||
@ -0,0 +1,22 @@
|
||||
package org.apache.cloudstack.engine.subsystem.api.storage.disktype;
|
||||
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
public enum DiskFormat {
|
||||
VMDK,
|
||||
VHD,
|
||||
ISO,
|
||||
QCOW2;
|
||||
public static DiskFormat getFormat(String format) {
|
||||
if (VMDK.toString().equalsIgnoreCase(format)) {
|
||||
return VMDK;
|
||||
} else if (VHD.toString().equalsIgnoreCase(format)) {
|
||||
return VHD;
|
||||
} else if (QCOW2.toString().equalsIgnoreCase(format)) {
|
||||
return QCOW2;
|
||||
} else if (ISO.toString().equalsIgnoreCase(format)) {
|
||||
return ISO;
|
||||
}
|
||||
throw new CloudRuntimeException("can't find format match: " + format);
|
||||
}
|
||||
}
|
||||
@ -14,13 +14,3 @@
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.engine.subsystem.api.storage.disktype;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class QCOW2 extends VolumeDiskTypeBase {
|
||||
public QCOW2() {
|
||||
this.type = "QCOW2";
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,10 +14,3 @@
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.engine.subsystem.api.storage.disktype;
|
||||
|
||||
public class Unknown extends VolumeDiskTypeBase {
|
||||
public Unknown() {
|
||||
this.type = "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,13 +14,3 @@
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.engine.subsystem.api.storage.disktype;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class VHD extends VolumeDiskTypeBase {
|
||||
public VHD() {
|
||||
this.type = "VHD";
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,13 +14,3 @@
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.engine.subsystem.api.storage.disktype;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class VMDK extends VolumeDiskTypeBase {
|
||||
public VMDK() {
|
||||
this.type = "VMDK";
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,7 +14,3 @@
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.engine.subsystem.api.storage.disktype;
|
||||
|
||||
public interface VolumeDiskType {
|
||||
}
|
||||
|
||||
@ -14,37 +14,3 @@
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.engine.subsystem.api.storage.disktype;
|
||||
|
||||
public class VolumeDiskTypeBase implements VolumeDiskType {
|
||||
protected String type = "Unknown";
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
if (this == that) {
|
||||
return true;
|
||||
}
|
||||
if (that instanceof String) {
|
||||
if (getType().equalsIgnoreCase((String)that)) {
|
||||
return true;
|
||||
}
|
||||
} else if (that instanceof VolumeDiskTypeBase) {
|
||||
VolumeDiskTypeBase th = (VolumeDiskTypeBase)that;
|
||||
if (this.getType().equalsIgnoreCase(th.getType())) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getType();
|
||||
}
|
||||
|
||||
protected String getType() {
|
||||
return this.type;
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,32 +14,3 @@
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.engine.subsystem.api.storage.disktype;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class VolumeDiskTypeHelper {
|
||||
|
||||
static private List<VolumeDiskType> diskTypes;
|
||||
static final private VolumeDiskType defaultType = new Unknown();
|
||||
|
||||
@Inject
|
||||
public void setDiskTypes(List<VolumeDiskType> diskTypes) {
|
||||
VolumeDiskTypeHelper.diskTypes = diskTypes;
|
||||
}
|
||||
|
||||
public static VolumeDiskType getDiskType(String type) {
|
||||
for (VolumeDiskType diskType : diskTypes) {
|
||||
if (diskType.equals(type)) {
|
||||
return diskType;
|
||||
}
|
||||
}
|
||||
|
||||
return VolumeDiskTypeHelper.defaultType;
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,6 +42,7 @@
|
||||
<module>storage/imagemotion</module>
|
||||
<module>storage/backup</module>
|
||||
<module>storage/snapshot</module>
|
||||
<module>storage/integration-test</module>
|
||||
<module>components-api</module>
|
||||
<module>schema</module>
|
||||
<module>network</module>
|
||||
|
||||
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectType;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.storage.datastore.DataStoreManager;
|
||||
import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
|
||||
import org.apache.cloudstack.storage.db.ObjectInDataStoreVO;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataVO;
|
||||
import org.apache.cloudstack.storage.image.store.TemplateObject;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ImageDataFactoryImpl implements ImageDataFactory {
|
||||
@Inject
|
||||
ImageDataDao imageDataDao;
|
||||
@Inject
|
||||
ObjectInDataStoreManager objMap;
|
||||
@Inject
|
||||
DataStoreManager storeMgr;
|
||||
@Override
|
||||
public TemplateInfo getTemplate(long templateId, DataStore store) {
|
||||
ObjectInDataStoreVO obj = objMap.findObject(templateId, DataObjectType.TEMPLATE, store.getId(), store.getRole());
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
ImageDataVO templ = imageDataDao.findById(templateId);
|
||||
TemplateObject tmpl = new TemplateObject(templ, store);
|
||||
return tmpl;
|
||||
}
|
||||
}
|
||||
@ -20,75 +20,141 @@ package org.apache.cloudstack.storage.image;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity;
|
||||
import org.apache.cloudstack.storage.EndPoint;
|
||||
import org.apache.cloudstack.storage.image.downloader.ImageDownloader;
|
||||
import org.apache.cloudstack.storage.image.manager.ImageDataStoreManager;
|
||||
import org.apache.cloudstack.storage.image.provider.ImageDataStoreProviderManager;
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.CommandResult;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.framework.async.AsyncCallFuture;
|
||||
import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
|
||||
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
||||
import org.apache.cloudstack.framework.async.AsyncRpcConext;
|
||||
import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
|
||||
import org.apache.cloudstack.storage.db.ObjectInDataStoreVO;
|
||||
import org.apache.cloudstack.storage.image.store.TemplateObject;
|
||||
import org.apache.cloudstack.storage.volume.ObjectInDataStoreStateMachine.Event;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.utils.fsm.NoTransitionException;
|
||||
|
||||
@Component
|
||||
public class ImageServiceImpl implements ImageService {
|
||||
private static final Logger s_logger = Logger.getLogger(ImageServiceImpl.class);
|
||||
@Inject
|
||||
ImageDataStoreProviderManager imageStoreProviderMgr;
|
||||
|
||||
public ImageServiceImpl() {
|
||||
ObjectInDataStoreManager objectInDataStoreMgr;
|
||||
|
||||
class CreateTemplateContext<T> extends AsyncRpcConext<T> {
|
||||
final TemplateInfo srcTemplate;
|
||||
final TemplateInfo templateOnStore;
|
||||
final AsyncCallFuture<CommandResult> future;
|
||||
final ObjectInDataStoreVO obj;
|
||||
public CreateTemplateContext(AsyncCompletionCallback<T> callback, TemplateInfo srcTemplate,
|
||||
TemplateInfo templateOnStore,
|
||||
AsyncCallFuture<CommandResult> future,
|
||||
ObjectInDataStoreVO obj) {
|
||||
super(callback);
|
||||
this.srcTemplate = srcTemplate;
|
||||
this.templateOnStore = templateOnStore;
|
||||
this.future = future;
|
||||
this.obj = obj;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateEntity registerTemplate(long templateId, long imageStoreId) {
|
||||
ImageDataStore ids = imageStoreProviderMgr.getDataStore(imageStoreId);
|
||||
TemplateObject to = ids.registerTemplate(templateId);
|
||||
return new TemplateEntityImpl(to);
|
||||
public AsyncCallFuture<CommandResult> createTemplateAsync(
|
||||
TemplateInfo template, DataStore store) {
|
||||
TemplateObject to = (TemplateObject) template;
|
||||
AsyncCallFuture<CommandResult> future = new AsyncCallFuture<CommandResult>();
|
||||
try {
|
||||
to.stateTransit(TemplateEvent.CreateRequested);
|
||||
} catch (NoTransitionException e) {
|
||||
s_logger.debug("Failed to transit state:", e);
|
||||
CommandResult result = new CommandResult();
|
||||
result.setResult(e.toString());
|
||||
future.complete(result);
|
||||
return future;
|
||||
}
|
||||
|
||||
ObjectInDataStoreVO obj = objectInDataStoreMgr.findObject(template.getId(), template.getType(), store.getId(), store.getRole());
|
||||
TemplateInfo templateOnStore = null;
|
||||
if (obj == null) {
|
||||
templateOnStore = objectInDataStoreMgr.create(template, store);
|
||||
} else {
|
||||
CommandResult result = new CommandResult();
|
||||
result.setResult("duplicate template on the storage");
|
||||
future.complete(result);
|
||||
return future;
|
||||
}
|
||||
|
||||
try {
|
||||
objectInDataStoreMgr.update(templateOnStore, Event.CreateOnlyRequested);
|
||||
} catch (NoTransitionException e) {
|
||||
s_logger.debug("failed to transit", e);
|
||||
CommandResult result = new CommandResult();
|
||||
result.setResult(e.toString());
|
||||
future.complete(result);
|
||||
return future;
|
||||
}
|
||||
CreateTemplateContext<CommandResult> context = new CreateTemplateContext<CommandResult>(null,
|
||||
template, templateOnStore,
|
||||
future,
|
||||
obj);
|
||||
AsyncCallbackDispatcher<ImageServiceImpl, CreateCmdResult> caller = AsyncCallbackDispatcher.create(this);
|
||||
caller.setCallback(caller.getTarget().createTemplateCallback(null, null))
|
||||
.setContext(context);
|
||||
store.getDriver().createAsync(templateOnStore, caller);
|
||||
return future;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteTemplate(long templateId) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long registerIso(String isoUrl, long accountId) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteIso(long isoId) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean revokeTemplateAccess(long templateId, long endpointId) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String grantIsoAccess(long isoId, long endpointId) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
protected Void createTemplateCallback(AsyncCallbackDispatcher<ImageServiceImpl, CreateCmdResult> callback,
|
||||
CreateTemplateContext<CreateCmdResult> context) {
|
||||
|
||||
TemplateInfo templateOnStore = context.templateOnStore;
|
||||
TemplateObject template = (TemplateObject)context.srcTemplate;
|
||||
AsyncCallFuture<CommandResult> future = context.future;
|
||||
CommandResult result = new CommandResult();
|
||||
|
||||
CreateCmdResult callbackResult = callback.getResult();
|
||||
if (callbackResult.isFailed()) {
|
||||
try {
|
||||
objectInDataStoreMgr.update(templateOnStore, Event.OperationFailed);
|
||||
} catch (NoTransitionException e) {
|
||||
s_logger.debug("failed to transit state", e);
|
||||
}
|
||||
result.setResult(callbackResult.getResult());
|
||||
future.complete(result);
|
||||
return null;
|
||||
}
|
||||
|
||||
ObjectInDataStoreVO obj = context.obj;
|
||||
obj.setInstallPath(callbackResult.getPath());
|
||||
|
||||
try {
|
||||
objectInDataStoreMgr.update(templateOnStore, Event.OperationSuccessed);
|
||||
} catch (NoTransitionException e) {
|
||||
s_logger.debug("Failed to transit state", e);
|
||||
result.setResult(e.toString());
|
||||
future.complete(result);
|
||||
return null;
|
||||
}
|
||||
|
||||
template.setImageStoreId(templateOnStore.getDataStore().getId());
|
||||
try {
|
||||
template.stateTransit(TemplateEvent.OperationSucceeded);
|
||||
} catch (NoTransitionException e) {
|
||||
s_logger.debug("Failed to transit state", e);
|
||||
result.setResult(e.toString());
|
||||
future.complete(result);
|
||||
return null;
|
||||
}
|
||||
|
||||
future.complete(result);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean revokeIsoAccess(long isoId, long endpointId) {
|
||||
public AsyncCallFuture<CommandResult> deleteTemplateAsync(
|
||||
TemplateInfo template) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateEntity getTemplateEntity(long templateId) {
|
||||
ImageDataStore dataStore = imageStoreProviderMgr.getDataStoreFromTemplateId(templateId);
|
||||
TemplateObject to = dataStore.getTemplate(templateId);
|
||||
return new TemplateEntityImpl(to);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean grantTemplateAccess(TemplateInfo template, EndPoint endpointId) {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskTypeHelper;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataVO;
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStoreInfo;
|
||||
|
||||
public class TemplateObject implements TemplateInfo {
|
||||
private ImageDataVO imageVO;
|
||||
private ImageDataStoreInfo dataStore;
|
||||
|
||||
public TemplateObject(ImageDataVO template, ImageDataStoreInfo dataStore) {
|
||||
this.imageVO = template;
|
||||
this.dataStore = dataStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageDataStoreInfo getDataStore() {
|
||||
return this.dataStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return this.imageVO.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public VolumeDiskType getDiskType() {
|
||||
return VolumeDiskTypeHelper.getDiskType(imageVO.getFormat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
//TODO: add installation path if it's downloaded to cache storage already
|
||||
return this.imageVO.getUrl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUuid() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image.driver;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
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.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
|
||||
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
||||
import org.apache.cloudstack.storage.image.ImageDataStoreDriver;
|
||||
|
||||
public class DefaultImageDataStoreDriverImpl implements ImageDataStoreDriver {
|
||||
|
||||
public DefaultImageDataStoreDriverImpl() {
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createAsync(DataObject data,
|
||||
AsyncCompletionCallback<CreateCmdResult> callback) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAsync(DataObject data,
|
||||
AsyncCompletionCallback<CommandResult> callback) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCopy(DataObject srcData, DataObject destData) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copyAsync(DataObject srcdata, DataObject destData,
|
||||
AsyncCompletionCallback<CopyCommandResult> callback) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,53 +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.driver;
|
||||
|
||||
import org.apache.cloudstack.storage.EndPoint;
|
||||
import org.apache.cloudstack.storage.image.TemplateInfo;
|
||||
import org.apache.cloudstack.storage.image.TemplateObject;
|
||||
|
||||
public class ImageDataStoreDriverImpl implements ImageDataStoreDriver {
|
||||
|
||||
public ImageDataStoreDriverImpl() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerTemplate(TemplateInfo template) {
|
||||
// TODO: check the availability of template
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String grantAccess(TemplateObject template, EndPoint endPointId) {
|
||||
return template.getPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean revokeAccess(long templateId, long endPointId) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteTemplate(TemplateInfo template) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image.manager;
|
||||
|
||||
import org.apache.cloudstack.storage.image.TemplateEvent;
|
||||
import org.apache.cloudstack.storage.image.TemplateState;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataVO;
|
||||
|
||||
import com.cloud.utils.fsm.StateMachine2;
|
||||
|
||||
public interface ImageDataManager {
|
||||
StateMachine2<TemplateState, TemplateEvent, ImageDataVO> getStateMachine();
|
||||
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image.manager;
|
||||
|
||||
import org.apache.cloudstack.storage.image.TemplateEvent;
|
||||
import org.apache.cloudstack.storage.image.TemplateState;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataVO;
|
||||
|
||||
import com.cloud.utils.fsm.StateMachine2;
|
||||
|
||||
public class ImageDataManagerImpl implements ImageDataManager {
|
||||
private final static StateMachine2<TemplateState, TemplateEvent, ImageDataVO>
|
||||
stateMachine = new StateMachine2<TemplateState, TemplateEvent, ImageDataVO>();
|
||||
|
||||
public ImageDataManagerImpl() {
|
||||
stateMachine.addTransition(TemplateState.Allocated, TemplateEvent.CreateRequested, TemplateState.Creating);
|
||||
stateMachine.addTransition(TemplateState.Creating, TemplateEvent.CreateRequested, TemplateState.Creating);
|
||||
stateMachine.addTransition(TemplateState.Creating, TemplateEvent.OperationSucceeded, TemplateState.Ready);
|
||||
stateMachine.addTransition(TemplateState.Creating, TemplateEvent.OperationFailed, TemplateState.Allocated);
|
||||
stateMachine.addTransition(TemplateState.Creating, TemplateEvent.DestroyRequested, TemplateState.Destroying);
|
||||
stateMachine.addTransition(TemplateState.Ready, TemplateEvent.DestroyRequested, TemplateState.Destroying);
|
||||
stateMachine.addTransition(TemplateState.Allocated, TemplateEvent.DestroyRequested, TemplateState.Destroying);
|
||||
stateMachine.addTransition(TemplateState.Destroying, TemplateEvent.DestroyRequested, TemplateState.Destroying);
|
||||
stateMachine.addTransition(TemplateState.Destroying, TemplateEvent.OperationFailed, TemplateState.Destroying);
|
||||
stateMachine.addTransition(TemplateState.Destroying, TemplateEvent.OperationSucceeded, TemplateState.Destroyed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StateMachine2<TemplateState, TemplateEvent, ImageDataVO> getStateMachine() {
|
||||
return stateMachine;
|
||||
}
|
||||
}
|
||||
@ -18,24 +18,52 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image.manager;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.provider.DataStoreProvider;
|
||||
import org.apache.cloudstack.storage.datastore.provider.DataStoreProviderManager;
|
||||
import org.apache.cloudstack.storage.image.ImageDataStoreDriver;
|
||||
import org.apache.cloudstack.storage.image.datastore.ImageDataStore;
|
||||
import org.apache.cloudstack.storage.image.datastore.ImageDataStoreManager;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreVO;
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStore;
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStoreImpl;
|
||||
import org.apache.cloudstack.storage.volume.PrimaryDataStoreDriver;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ImageDataStoreManagerImpl implements ImageDataStoreManager {
|
||||
@Inject
|
||||
ImageDataStoreDao dataStoreDao;
|
||||
@Inject
|
||||
ImageDataDao imageDataDao;
|
||||
@Inject
|
||||
DataStoreProviderManager providerManager;
|
||||
Map<String, ImageDataStoreDriver> driverMaps = new HashMap<String, ImageDataStoreDriver>();
|
||||
|
||||
@Override
|
||||
public ImageDataStore getImageDataStore(long dataStoreId) {
|
||||
ImageDataStoreVO dataStore = dataStoreDao.findById(dataStoreId);
|
||||
long providerId = dataStore.getProvider();
|
||||
DataStoreProvider provider = providerManager.getDataStoreProviderById(providerId);
|
||||
ImageDataStore imgStore = new ImageDataStoreImpl(dataStore,
|
||||
driverMaps.get(provider.getUuid())
|
||||
);
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
return imgStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerDriver(String uuid, ImageDataStoreDriver driver) {
|
||||
if (driverMaps.containsKey(uuid)) {
|
||||
return false;
|
||||
}
|
||||
driverMaps.put(uuid, driver);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,75 +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.provider;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreProviderDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreProviderVO;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreVO;
|
||||
import org.apache.cloudstack.storage.image.driver.ImageDataStoreDriver;
|
||||
import org.apache.cloudstack.storage.image.driver.ImageDataStoreDriverImpl;
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStore;
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStoreImpl;
|
||||
import org.apache.cloudstack.storage.image.store.lifecycle.DefaultImageDataStoreLifeCycle;
|
||||
import org.apache.cloudstack.storage.image.store.lifecycle.ImageDataStoreLifeCycle;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
|
||||
@Component
|
||||
public class DefaultImageDataStoreProvider implements ImageDataStoreProvider {
|
||||
private final String providerName = "DefaultProvider";
|
||||
@Inject
|
||||
ImageDataStoreProviderDao providerDao;
|
||||
@Inject
|
||||
ImageDataStoreDao imageStoreDao;
|
||||
ImageDataStoreProviderVO provider;
|
||||
|
||||
@Override
|
||||
public ImageDataStore getImageDataStore(long imageStoreId) {
|
||||
ImageDataStoreVO idsv = imageStoreDao.findById(imageStoreId);
|
||||
ImageDataStoreDriver driver = new ImageDataStoreDriverImpl();
|
||||
ImageDataStore ids = new ImageDataStoreImpl(idsv, driver, false);
|
||||
ids = ComponentContext.inject(ids);
|
||||
return ids;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return providerName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean register(long providerId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean init() {
|
||||
provider = providerDao.findByName(providerName);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageDataStoreLifeCycle getLifeCycle() {
|
||||
return new DefaultImageDataStoreLifeCycle(this, provider, imageStoreDao);
|
||||
}
|
||||
}
|
||||
@ -1,39 +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.provider;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.storage.image.TemplateObject;
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStore;
|
||||
|
||||
import com.cloud.utils.component.Manager;
|
||||
|
||||
public interface ImageDataStoreProviderManager extends Manager {
|
||||
public ImageDataStoreProvider getProvider(long providerId);
|
||||
public List<ImageDataStoreProvider> listProvider();
|
||||
public ImageDataStore getDataStore(Long dataStoreId);
|
||||
|
||||
public ImageDataStore getDataStoreFromTemplateId(long templateId);
|
||||
/**
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
ImageDataStoreProvider getProvider(String name);
|
||||
}
|
||||
@ -1,135 +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.provider;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreProviderDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreProviderVO;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreVO;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataVO;
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStore;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ImageDataStoreProviderManagerImpl implements ImageDataStoreProviderManager {
|
||||
@Inject
|
||||
ImageDataStoreProviderDao providerDao;
|
||||
@Inject
|
||||
ImageDataStoreDao dataStoreDao;
|
||||
@Inject
|
||||
ImageDataDao imageDataDao;
|
||||
@Inject
|
||||
List<ImageDataStoreProvider> providers;
|
||||
|
||||
@Override
|
||||
public ImageDataStoreProvider getProvider(long providerId) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageDataStoreProvider getProvider(String name) {
|
||||
for (ImageDataStoreProvider provider : providers) {
|
||||
if (provider.getName().equalsIgnoreCase(name)) {
|
||||
return provider;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageDataStore getDataStore(Long dataStoreId) {
|
||||
if (dataStoreId == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ImageDataStoreVO idsv = dataStoreDao.findById(dataStoreId);
|
||||
if (idsv == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
long providerId = idsv.getProvider();
|
||||
ImageDataStoreProviderVO idspv = providerDao.findById(providerId);
|
||||
ImageDataStoreProvider provider = getProvider(idspv.getName());
|
||||
return provider.getImageDataStore(dataStoreId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImageDataStore getDataStoreFromTemplateId(long templateId) {
|
||||
ImageDataVO iddv = imageDataDao.findById(templateId);
|
||||
return getDataStore(iddv.getImageDataStoreId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
List<ImageDataStoreProviderVO> existingProviders = providerDao.listAll();
|
||||
//TODO: hold global lock
|
||||
boolean foundExistingProvider = false;
|
||||
for (ImageDataStoreProvider provider : providers) {
|
||||
foundExistingProvider = false;
|
||||
for (ImageDataStoreProviderVO existingProvider : existingProviders) {
|
||||
if (provider.getName().equalsIgnoreCase(existingProvider.getName())) {
|
||||
foundExistingProvider = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundExistingProvider) {
|
||||
//add a new provider into db
|
||||
ImageDataStoreProviderVO nProvider = new ImageDataStoreProviderVO();
|
||||
nProvider.setName(provider.getName());
|
||||
nProvider = providerDao.persist(nProvider);
|
||||
provider.register(nProvider.getId());
|
||||
}
|
||||
provider.init();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ImageDataStoreProvider> listProvider() {
|
||||
return providers;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image.store;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle;
|
||||
import org.apache.cloudstack.storage.datastore.provider.ImageDataStoreProvider;
|
||||
import org.apache.cloudstack.storage.image.ImageDataStoreDriver;
|
||||
import org.apache.cloudstack.storage.image.datastore.ImageDataStoreManager;
|
||||
import org.apache.cloudstack.storage.image.driver.DefaultImageDataStoreDriverImpl;
|
||||
import org.apache.cloudstack.storage.image.store.lifecycle.DefaultImageDataStoreLifeCycle;
|
||||
import org.apache.cloudstack.storage.image.store.lifecycle.ImageDataStoreLifeCycle;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
|
||||
@Component
|
||||
public class DefaultImageDataStoreProvider implements ImageDataStoreProvider {
|
||||
private final String name = "default image data store";
|
||||
protected ImageDataStoreLifeCycle lifeCycle;
|
||||
protected ImageDataStoreDriver driver;
|
||||
@Inject
|
||||
ImageDataStoreManager storeMgr;
|
||||
long id;
|
||||
String uuid;
|
||||
@Override
|
||||
public DataStoreLifeCycle getLifeCycle() {
|
||||
return lifeCycle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(Map<String, Object> params) {
|
||||
lifeCycle = ComponentContext.inject(DefaultImageDataStoreLifeCycle.class);
|
||||
driver = ComponentContext.inject(DefaultImageDataStoreDriverImpl.class);
|
||||
uuid = (String)params.get("uuid");
|
||||
id = (Long)params.get("id");
|
||||
storeMgr.registerDriver(uuid, driver);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@ -18,18 +18,26 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image.store;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
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.DataStoreRole;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
|
||||
import org.apache.cloudstack.storage.EndPoint;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
|
||||
import org.apache.cloudstack.storage.image.ImageDataStoreDriver;
|
||||
import org.apache.cloudstack.storage.image.TemplateInfo;
|
||||
import org.apache.cloudstack.storage.image.TemplateObject;
|
||||
import org.apache.cloudstack.storage.image.datastore.ImageDataStore;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreVO;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataVO;
|
||||
import org.apache.cloudstack.storage.image.driver.ImageDataStoreDriver;
|
||||
import org.apache.cloudstack.storage.snapshot.SnapshotInfo;
|
||||
|
||||
|
||||
public class ImageDataStoreImpl implements ImageDataStore {
|
||||
@Inject
|
||||
ImageDataDao imageDao;
|
||||
@ -37,102 +45,36 @@ public class ImageDataStoreImpl implements ImageDataStore {
|
||||
ImageDataStoreVO imageDataStoreVO;
|
||||
boolean needDownloadToCacheStorage = false;
|
||||
|
||||
public ImageDataStoreImpl(ImageDataStoreVO dataStoreVO, ImageDataStoreDriver driver, boolean needDownloadToCacheStorage) {
|
||||
this.driver = driver;
|
||||
this.needDownloadToCacheStorage = needDownloadToCacheStorage;
|
||||
public ImageDataStoreImpl(ImageDataStoreVO dataStoreVO, ImageDataStoreDriver imageDataStoreDriver) {
|
||||
this.driver = imageDataStoreDriver;
|
||||
this.imageDataStoreVO = dataStoreVO;
|
||||
}
|
||||
|
||||
/*
|
||||
* @Override public TemplateInfo registerTemplate(long templateId) {
|
||||
* ImageDataVO idv = imageDao.findById(templateId); TemplateInfo template =
|
||||
* new TemplateInfo(this, idv); if (driver.registerTemplate(template)) {
|
||||
* template.setImageDataStoreId(imageDataStoreVO.getId()); return template;
|
||||
* } else { return null; } }
|
||||
*/
|
||||
|
||||
|
||||
@Override
|
||||
public boolean deleteTemplate(long templateId) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needDownloadToCacheStorage() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getImageDataStoreId() {
|
||||
return imageDataStoreVO.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateObject registerTemplate(long templateId) {
|
||||
ImageDataVO image = imageDao.findById(templateId);
|
||||
image.setImageDataStoreId(this.getImageDataStoreId());
|
||||
imageDao.update(templateId, image);
|
||||
return getTemplate(templateId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateObject getTemplate(long templateId) {
|
||||
ImageDataVO image = imageDao.findById(templateId);
|
||||
TemplateObject to = new TemplateObject(image, this);
|
||||
return to;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
public Set<TemplateInfo> listTemplates() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String getUri() {
|
||||
public DataStoreDriver getDriver() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String grantAccess(VolumeInfo volume, EndPoint ep) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean revokeAccess(VolumeInfo volume, EndPoint ep) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String grantAccess(TemplateInfo template, EndPoint ep) {
|
||||
return this.driver.grantAccess((TemplateObject)template, ep);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean revokeAccess(TemplateInfo template, EndPoint ep) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String grantAccess(SnapshotInfo snapshot, EndPoint ep) {
|
||||
public DataStoreRole getRole() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean revokeAccess(SnapshotInfo snapshot, EndPoint ep) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRole() {
|
||||
return "imageStore";
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
@ -140,4 +82,51 @@ public class ImageDataStoreImpl implements ImageDataStore {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String getUri() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Scope getScope() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public TemplateInfo getTemplate(long templateId) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public VolumeInfo getVolume(long volumeId) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public SnapshotInfo getSnapshot(long snapshotId) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean exists(DataObject object) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image.store;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectType;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.DiskFormat;
|
||||
import org.apache.cloudstack.storage.image.TemplateEvent;
|
||||
import org.apache.cloudstack.storage.image.TemplateInfo;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataVO;
|
||||
import org.apache.cloudstack.storage.image.manager.ImageDataManager;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
import com.cloud.utils.fsm.NoTransitionException;
|
||||
|
||||
public class TemplateObject implements TemplateInfo {
|
||||
private static final Logger s_logger = Logger.getLogger(TemplateObject.class);
|
||||
private ImageDataVO imageVO;
|
||||
private DataStore dataStore;
|
||||
@Inject
|
||||
ImageDataManager imageMgr;
|
||||
@Inject
|
||||
ImageDataDao imageDao;
|
||||
|
||||
public TemplateObject(ImageDataVO template, DataStore dataStore) {
|
||||
this.imageVO = template;
|
||||
this.dataStore = dataStore;
|
||||
}
|
||||
|
||||
public static TemplateObject getTemplate(ImageDataVO vo, DataStore store) {
|
||||
TemplateObject to = new TemplateObject(vo, store);
|
||||
return ComponentContext.inject(to);
|
||||
}
|
||||
|
||||
public void setImageStoreId(long id) {
|
||||
this.imageVO.setImageDataStoreId(id);
|
||||
}
|
||||
|
||||
public ImageDataVO getImage() {
|
||||
return this.imageVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataStore getDataStore() {
|
||||
return this.dataStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return this.imageVO.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
//TODO: add installation path if it's downloaded to cache storage already
|
||||
return this.imageVO.getUrl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUuid() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUri() {
|
||||
return this.dataStore.getUri() + "template/" + this.getPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSize() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataObjectType getType() {
|
||||
return DataObjectType.TEMPLATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiskFormat getFormat() {
|
||||
return DiskFormat.getFormat(this.imageVO.getFormat());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stateTransit(TemplateEvent e) throws NoTransitionException {
|
||||
return imageMgr.getStateMachine().transitTo(this.imageVO, e, null, imageDao);
|
||||
}
|
||||
}
|
||||
@ -20,35 +20,72 @@ 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.ZoneScope;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreProviderVO;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataStoreVO;
|
||||
import org.apache.cloudstack.storage.image.provider.ImageDataStoreProvider;
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStore;
|
||||
|
||||
public class DefaultImageDataStoreLifeCycle implements ImageDataStoreLifeCycle {
|
||||
protected ImageDataStoreProvider provider;
|
||||
protected ImageDataStoreProviderVO providerVO;
|
||||
@Inject
|
||||
protected ImageDataStoreDao imageStoreDao;
|
||||
@Override
|
||||
public ImageDataStore registerDataStore(String name,
|
||||
Map<String, String> params) {
|
||||
ImageDataStoreVO dataStore = imageStoreDao.findByName(name);
|
||||
if (dataStore == null) {
|
||||
dataStore = new ImageDataStoreVO();
|
||||
dataStore.setName(name);
|
||||
dataStore.setProvider(providerVO.getId());
|
||||
dataStore = imageStoreDao.persist(dataStore);
|
||||
}
|
||||
return provider.getImageDataStore(dataStore.getId());
|
||||
}
|
||||
|
||||
public DefaultImageDataStoreLifeCycle(ImageDataStoreProvider provider,
|
||||
ImageDataStoreProviderVO providerVO,
|
||||
ImageDataStoreDao dao) {
|
||||
this.provider = provider;
|
||||
this.providerVO = providerVO;
|
||||
this.imageStoreDao = dao;
|
||||
public DefaultImageDataStoreLifeCycle() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean initialize(DataStore store, Map<String, String> dsInfos) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean attachCluster(DataStore store, ClusterScope scope) {
|
||||
// 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() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean cancelMaintain() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean deleteDataStore() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -18,10 +18,7 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image.store.lifecycle;
|
||||
|
||||
import java.util.Map;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle;
|
||||
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStore;
|
||||
|
||||
public interface ImageDataStoreLifeCycle {
|
||||
public ImageDataStore registerDataStore(String name, Map<String, String> params);
|
||||
public interface ImageDataStoreLifeCycle extends DataStoreLifeCycle {
|
||||
}
|
||||
|
||||
@ -18,32 +18,29 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image.motion;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreRole;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
|
||||
import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
|
||||
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
||||
import org.apache.cloudstack.framework.async.AsyncRpcConext;
|
||||
import org.apache.cloudstack.storage.EndPoint;
|
||||
import org.apache.cloudstack.storage.command.CommandResult;
|
||||
import org.apache.cloudstack.storage.command.CopyCmd;
|
||||
import org.apache.cloudstack.storage.command.CopyTemplateToPrimaryStorageAnswer;
|
||||
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
|
||||
import org.apache.cloudstack.storage.image.TemplateInfo;
|
||||
import org.apache.cloudstack.storage.to.ImageOnPrimayDataStoreTO;
|
||||
import org.apache.cloudstack.storage.command.CopyCmdAnswer;
|
||||
import org.apache.cloudstack.storage.endpoint.EndPointSelector;
|
||||
import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
|
||||
//At least one of datastore is coming from image store or image cache store
|
||||
@Component
|
||||
public class DefaultImageMotionStrategy implements ImageMotionStrategy {
|
||||
|
||||
@Override
|
||||
public boolean canHandle(TemplateInfo templateStore) {
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Inject
|
||||
EndPointSelector selector;
|
||||
private class CreateTemplateContext<T> extends AsyncRpcConext<T> {
|
||||
private final TemplateOnPrimaryDataStoreInfo template;
|
||||
public CreateTemplateContext(AsyncCompletionCallback<T> callback, TemplateOnPrimaryDataStoreInfo template) {
|
||||
@ -56,7 +53,7 @@ public class DefaultImageMotionStrategy implements ImageMotionStrategy {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public void copyTemplateAsync(String destUri, String srcUri, EndPoint ep, AsyncCompletionCallback<CommandResult> callback) {
|
||||
|
||||
@ -85,12 +82,59 @@ public class DefaultImageMotionStrategy implements ImageMotionStrategy {
|
||||
|
||||
parentCall.complete(result);
|
||||
return null;
|
||||
}*/
|
||||
|
||||
@Override
|
||||
public boolean canHandle(DataObject srcData, DataObject destData) {
|
||||
DataStore destStore = destData.getDataStore();
|
||||
DataStore srcStore = srcData.getDataStore();
|
||||
if (destStore.getRole() == DataStoreRole.Image || destStore.getRole() == DataStoreRole.ImageCache
|
||||
|| srcStore.getRole() == DataStoreRole.Image
|
||||
|| srcStore.getRole() == DataStoreRole.ImageCache) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EndPoint getEndPoint(TemplateInfo destTemplate,
|
||||
TemplateInfo srcTemplate) {
|
||||
public Void copyAsync(DataObject srcData, DataObject destData,
|
||||
AsyncCompletionCallback<CopyCommandResult> callback) {
|
||||
DataStore destStore = destData.getDataStore();
|
||||
DataStore srcStore = srcData.getDataStore();
|
||||
EndPoint ep = selector.select(srcData, destData);
|
||||
CopyCommandResult result = new CopyCommandResult("");
|
||||
if (ep == null) {
|
||||
result.setResult("can't find end point");
|
||||
callback.complete(result);
|
||||
return null;
|
||||
}
|
||||
|
||||
String srcUri = srcStore.getDriver().grantAccess(srcData, ep);
|
||||
String destUri = destStore.getDriver().grantAccess(destData, ep);
|
||||
CopyCmd cmd = new CopyCmd(srcUri, destUri);
|
||||
|
||||
CreateTemplateContext<CopyCommandResult> context = new CreateTemplateContext<CopyCommandResult>(callback, null);
|
||||
AsyncCallbackDispatcher<DefaultImageMotionStrategy, Answer> caller = AsyncCallbackDispatcher.create(this);
|
||||
caller.setCallback(caller.getTarget().copyAsyncCallback(null, null))
|
||||
.setContext(context);
|
||||
|
||||
ep.sendMessageAsync(cmd, caller);
|
||||
return null;
|
||||
}
|
||||
|
||||
protected Void copyAsyncCallback(AsyncCallbackDispatcher<DefaultImageMotionStrategy, Answer> callback, CreateTemplateContext<CopyCommandResult> context) {
|
||||
AsyncCompletionCallback<CopyCommandResult> parentCall = context.getParentCallback();
|
||||
CopyCmdAnswer answer = (CopyCmdAnswer)callback.getResult();
|
||||
if (!answer.getResult()) {
|
||||
CopyCommandResult result = new CopyCommandResult("");
|
||||
result.setResult(answer.getDetails());
|
||||
parentCall.complete(result);
|
||||
} else {
|
||||
CopyCommandResult result = new CopyCommandResult(answer.getPath());
|
||||
parentCall.complete(result);
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -22,9 +22,9 @@ import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.CommandResult;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
|
||||
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
||||
import org.apache.cloudstack.storage.EndPoint;
|
||||
import org.apache.cloudstack.storage.command.CommandResult;
|
||||
import org.apache.cloudstack.storage.db.ObjectInDataStoreVO;
|
||||
import org.apache.cloudstack.storage.image.ImageService;
|
||||
import org.apache.cloudstack.storage.image.TemplateInfo;
|
||||
@ -53,7 +53,7 @@ public class ImageMotionServiceImpl implements ImageMotionService {
|
||||
|
||||
@Override
|
||||
public void copyTemplateAsync(TemplateInfo destTemplate, TemplateInfo srcTemplate, AsyncCompletionCallback<CommandResult> callback) {
|
||||
ImageMotionStrategy ims = null;
|
||||
/* ImageMotionStrategy ims = null;
|
||||
for (ImageMotionStrategy strategy : motionStrategies) {
|
||||
if (strategy.canHandle(srcTemplate)) {
|
||||
ims = strategy;
|
||||
@ -69,7 +69,7 @@ public class ImageMotionServiceImpl implements ImageMotionService {
|
||||
String srcUri = srcTemplate.getDataStore().grantAccess(srcTemplate, ep);
|
||||
String destUri = destTemplate.getDataStore().grantAccess(destTemplate, ep);
|
||||
|
||||
ims.copyTemplateAsync(destUri, srcUri, ep, callback);
|
||||
ims.copyTemplateAsync(destUri, srcUri, ep, callback);*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -18,15 +18,7 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image.motion;
|
||||
|
||||
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
||||
import org.apache.cloudstack.storage.EndPoint;
|
||||
import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;
|
||||
import org.apache.cloudstack.storage.command.CommandResult;
|
||||
import org.apache.cloudstack.storage.datastore.DataStore;
|
||||
import org.apache.cloudstack.storage.image.TemplateInfo;
|
||||
import org.apache.cloudstack.storage.motion.DataMotionStrategy;
|
||||
|
||||
public interface ImageMotionStrategy {
|
||||
public boolean canHandle(TemplateInfo templateStore);
|
||||
public EndPoint getEndPoint(TemplateInfo destTemplate, TemplateInfo srcTemplate);
|
||||
public void copyTemplateAsync(String destUri, String sourceUri, EndPoint ep, AsyncCompletionCallback<CommandResult> callback);
|
||||
public interface ImageMotionStrategy extends DataMotionStrategy {
|
||||
}
|
||||
|
||||
@ -18,33 +18,25 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.test;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.storage.command.CopyTemplateToPrimaryStorageCmd;
|
||||
import org.apache.cloudstack.storage.to.ImageDataStoreTO;
|
||||
import org.apache.cloudstack.storage.to.ImageOnPrimayDataStoreTO;
|
||||
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
||||
import org.apache.cloudstack.storage.to.TemplateTO;
|
||||
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Parameters;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.ReadyCommand;
|
||||
import com.cloud.dc.ClusterVO;
|
||||
import com.cloud.dc.DataCenter.NetworkType;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.HostPodVO;
|
||||
import com.cloud.dc.DataCenter.NetworkType;
|
||||
import com.cloud.dc.dao.ClusterDao;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.dc.dao.HostPodDao;
|
||||
@ -57,8 +49,6 @@ import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.org.Cluster.ClusterType;
|
||||
import com.cloud.org.Managed.ManagedState;
|
||||
import com.cloud.resource.ResourceState;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
|
||||
@ContextConfiguration(locations="classpath:/storageContext.xml")
|
||||
public class DirectAgentTest extends CloudStackTestNGBase {
|
||||
@ -149,7 +139,8 @@ public class DirectAgentTest extends CloudStackTestNGBase {
|
||||
Mockito.when(template.getImageDataStore()).thenReturn(imageStore);
|
||||
|
||||
Mockito.when(image.getTemplate()).thenReturn(template);
|
||||
CopyTemplateToPrimaryStorageCmd cmd = new CopyTemplateToPrimaryStorageCmd(image);
|
||||
//CopyTemplateToPrimaryStorageCmd cmd = new CopyTemplateToPrimaryStorageCmd(image);
|
||||
Command cmd = null;
|
||||
try {
|
||||
agentMgr.send(hostId, cmd);
|
||||
} catch (AgentUnavailableException e) {
|
||||
|
||||
@ -24,12 +24,9 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
||||
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
||||
|
||||
import org.apache.cloudstack.storage.HostEndpointRpcServer;
|
||||
import org.apache.cloudstack.storage.HypervisorHostEndPoint;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
@ -37,9 +34,7 @@ import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.exception.AgentUnavailableException;
|
||||
import com.cloud.exception.OperationTimedoutException;
|
||||
import com.cloud.utils.component.ComponentInject;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
|
||||
|
||||
public class MockHostEndpointRpcServerDirectCallResource implements HostEndpointRpcServer {
|
||||
@ -53,7 +48,7 @@ public class MockHostEndpointRpcServerDirectCallResource implements HostEndpoint
|
||||
|
||||
public void sendCommandAsync(HypervisorHostEndPoint host, final Command command, final AsyncCompletionCallback<Answer> callback) {
|
||||
// new MockRpcCallBack(host.getHostId(), command, callback);
|
||||
MockRpcCallBack run = ComponentInject.inject(MockRpcCallBack.class);
|
||||
MockRpcCallBack run = ComponentContext.inject(MockRpcCallBack.class);
|
||||
run.setCallback(callback);
|
||||
run.setCmd(command);
|
||||
run.setHostId(host.getHostId());
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.test;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -26,10 +25,6 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
||||
import org.apache.cloudstack.storage.HostEndpointRpcServer;
|
||||
import org.apache.cloudstack.storage.HypervisorHostEndPoint;
|
||||
import org.apache.cloudstack.storage.command.CopyTemplateToPrimaryStorageCmd;
|
||||
import org.apache.cloudstack.storage.command.CopyTemplateToPrimaryStorageAnswer;
|
||||
import org.apache.cloudstack.storage.command.CreateVolumeAnswer;
|
||||
import org.apache.cloudstack.storage.command.CreateVolumeFromBaseImageCommand;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
@ -51,11 +46,11 @@ public class MockHypervsiorHostEndPointRpcServer implements HostEndpointRpcServe
|
||||
public void run() {
|
||||
try {
|
||||
Answer answer = new Answer(cmd, false, "unknown command");
|
||||
if (cmd instanceof CopyTemplateToPrimaryStorageCmd) {
|
||||
/*if (cmd instanceof CopyTemplateToPrimaryStorageCmd) {
|
||||
answer = new CopyTemplateToPrimaryStorageAnswer(cmd, UUID.randomUUID().toString());
|
||||
} else if (cmd instanceof CreateVolumeFromBaseImageCommand) {
|
||||
answer = new CreateVolumeAnswer(cmd, UUID.randomUUID().toString());
|
||||
}
|
||||
}*/
|
||||
|
||||
callback.complete(answer);
|
||||
} catch (Exception e) {
|
||||
|
||||
@ -18,75 +18,39 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.test;
|
||||
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.AssertJUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity;
|
||||
import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.QCOW2;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VHD;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VMDK;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskTypeHelper;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.type.RootDisk;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeTypeHelper;
|
||||
import org.apache.cloudstack.storage.command.CreateVolumeAnswer;
|
||||
import org.apache.cloudstack.storage.command.CreateVolumeFromBaseImageCommand;
|
||||
import org.apache.cloudstack.storage.datastore.DefaultPrimaryDataStore;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreVO;
|
||||
import org.apache.cloudstack.storage.datastore.provider.PrimaryDataStoreProviderManager;
|
||||
import org.apache.cloudstack.storage.image.ImageService;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataDao;
|
||||
import org.apache.cloudstack.storage.image.db.ImageDataVO;
|
||||
import org.apache.cloudstack.storage.image.format.ISO;
|
||||
import org.apache.cloudstack.storage.image.format.ImageFormat;
|
||||
import org.apache.cloudstack.storage.image.format.ImageFormatHelper;
|
||||
import org.apache.cloudstack.storage.image.format.OVA;
|
||||
import org.apache.cloudstack.storage.image.format.Unknown;
|
||||
import org.apache.cloudstack.storage.image.provider.ImageDataStoreProvider;
|
||||
import org.apache.cloudstack.storage.image.provider.ImageDataStoreProviderManager;
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStore;
|
||||
import org.apache.cloudstack.storage.image.store.lifecycle.ImageDataStoreLifeCycle;
|
||||
import org.apache.cloudstack.storage.volume.VolumeService;
|
||||
import org.apache.cloudstack.storage.volume.db.VolumeDao2;
|
||||
import org.apache.cloudstack.storage.volume.db.VolumeVO;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.Mockito.*;
|
||||
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.dc.ClusterVO;
|
||||
import com.cloud.dc.DataCenter.NetworkType;
|
||||
import com.cloud.dc.DataCenterVO;
|
||||
import com.cloud.dc.HostPodVO;
|
||||
import com.cloud.dc.DataCenter.NetworkType;
|
||||
import com.cloud.dc.dao.ClusterDao;
|
||||
import com.cloud.dc.dao.DataCenterDao;
|
||||
import com.cloud.dc.dao.HostPodDao;
|
||||
import com.cloud.exception.AgentUnavailableException;
|
||||
import com.cloud.exception.OperationTimedoutException;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Status;
|
||||
import com.cloud.host.Status.Event;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.org.Cluster.ClusterType;
|
||||
@ -96,8 +60,8 @@ import com.cloud.storage.Storage.TemplateType;
|
||||
|
||||
@ContextConfiguration(locations="classpath:/storageContext.xml")
|
||||
public class volumeServiceTest extends CloudStackTestNGBase {
|
||||
@Inject
|
||||
ImageDataStoreProviderManager imageProviderMgr;
|
||||
//@Inject
|
||||
//ImageDataStoreProviderManager imageProviderMgr;
|
||||
@Inject
|
||||
ImageService imageService;
|
||||
@Inject
|
||||
@ -116,8 +80,8 @@ public class volumeServiceTest extends CloudStackTestNGBase {
|
||||
DataCenterDao dcDao;
|
||||
@Inject
|
||||
PrimaryDataStoreDao primaryStoreDao;
|
||||
@Inject
|
||||
PrimaryDataStoreProviderManager primaryDataStoreProviderMgr;
|
||||
//@Inject
|
||||
//PrimaryDataStoreProviderManager primaryDataStoreProviderMgr;
|
||||
@Inject
|
||||
AgentManager agentMgr;
|
||||
Long dcId;
|
||||
@ -210,7 +174,7 @@ public class volumeServiceTest extends CloudStackTestNGBase {
|
||||
image.setFeatured(true);
|
||||
image.setRequireHvm(true);
|
||||
image.setBits(64);
|
||||
image.setFormat(new VHD().toString());
|
||||
//image.setFormat(new VHD().toString());
|
||||
image.setAccountId(1);
|
||||
image.setEnablePassword(true);
|
||||
image.setEnableSshKey(true);
|
||||
@ -225,15 +189,16 @@ public class volumeServiceTest extends CloudStackTestNGBase {
|
||||
|
||||
private TemplateEntity createTemplate() {
|
||||
try {
|
||||
imageProviderMgr.configure("image Provider", new HashMap<String, Object>());
|
||||
/*imageProviderMgr.configure("image Provider", new HashMap<String, Object>());
|
||||
ImageDataVO image = createImageData();
|
||||
ImageDataStoreProvider defaultProvider = imageProviderMgr.getProvider("DefaultProvider");
|
||||
ImageDataStoreLifeCycle lifeCycle = defaultProvider.getLifeCycle();
|
||||
ImageDataStore store = lifeCycle.registerDataStore("defaultHttpStore", new HashMap<String, String>());
|
||||
imageService.registerTemplate(image.getId(), store.getImageDataStoreId());
|
||||
TemplateEntity te = imageService.getTemplateEntity(image.getId());
|
||||
return te;
|
||||
} catch (ConfigurationException e) {
|
||||
return te;*/
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -244,6 +209,7 @@ public class volumeServiceTest extends CloudStackTestNGBase {
|
||||
|
||||
private PrimaryDataStoreInfo createPrimaryDataStore() {
|
||||
try {
|
||||
/*
|
||||
PrimaryDataStoreProvider provider = primaryDataStoreProviderMgr.getDataStoreProvider("default primary data store provider");
|
||||
primaryDataStoreProviderMgr.configure("primary data store mgr", new HashMap<String, Object>());
|
||||
|
||||
@ -266,7 +232,9 @@ public class volumeServiceTest extends CloudStackTestNGBase {
|
||||
ClusterScope scope = new ClusterScope(clusterId, podId, dcId);
|
||||
lc.attachCluster(scope);
|
||||
return primaryDataStoreInfo;
|
||||
} catch (ConfigurationException e) {
|
||||
*/
|
||||
return null;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -284,7 +252,7 @@ public class volumeServiceTest extends CloudStackTestNGBase {
|
||||
TemplateEntity te = createTemplate();
|
||||
VolumeVO volume = createVolume(te.getId(), primaryStore.getId());
|
||||
VolumeEntity ve = volumeService.getVolumeEntity(volume.getId());
|
||||
ve.createVolumeFromTemplate(primaryStore.getId(), new VHD(), te);
|
||||
//ve.createVolumeFromTemplate(primaryStore.getId(), new VHD(), te);
|
||||
ve.destroy();
|
||||
}
|
||||
|
||||
@ -293,7 +261,7 @@ public class volumeServiceTest extends CloudStackTestNGBase {
|
||||
primaryStore = createPrimaryDataStore();
|
||||
VolumeVO volume = createVolume(null, primaryStore.getId());
|
||||
VolumeEntity ve = volumeService.getVolumeEntity(volume.getId());
|
||||
ve.createVolume(primaryStore.getId(), new VHD());
|
||||
//ve.createVolume(primaryStore.getId(), new VHD());
|
||||
ve.destroy();
|
||||
}
|
||||
|
||||
@ -311,7 +279,7 @@ public class volumeServiceTest extends CloudStackTestNGBase {
|
||||
//@Test
|
||||
@Test
|
||||
public void test1() {
|
||||
System.out.println(VolumeTypeHelper.getType("Root"));
|
||||
/*System.out.println(VolumeTypeHelper.getType("Root"));
|
||||
System.out.println(VolumeDiskTypeHelper.getDiskType("vmdk"));
|
||||
System.out.println(ImageFormatHelper.getFormat("ova"));
|
||||
AssertJUnit.assertFalse(new VMDK().equals(new VHD()));
|
||||
@ -329,7 +297,7 @@ public class volumeServiceTest extends CloudStackTestNGBase {
|
||||
VolumeDiskType qcow2 = new QCOW2();
|
||||
ImageFormat qcow2format = new org.apache.cloudstack.storage.image.format.QCOW2();
|
||||
AssertJUnit.assertFalse(qcow2.equals(qcow2format));
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.snapshot;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectType;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.storage.datastore.DataStoreManager;
|
||||
import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
|
||||
import org.apache.cloudstack.storage.db.ObjectInDataStoreVO;
|
||||
import org.apache.cloudstack.storage.snapshot.db.SnapshotDao2;
|
||||
import org.apache.cloudstack.storage.snapshot.db.SnapshotVO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class SnapshotDataFactoryImpl implements SnapshotDataFactory {
|
||||
@Inject
|
||||
SnapshotDao2 snapshotDao;
|
||||
@Inject
|
||||
ObjectInDataStoreManager objMap;
|
||||
@Inject
|
||||
DataStoreManager storeMgr;
|
||||
@Override
|
||||
public SnapshotInfo getSnapshot(long snapshotId, DataStore store) {
|
||||
SnapshotVO snapshot = snapshotDao.findById(snapshotId);
|
||||
ObjectInDataStoreVO obj = objMap.findObject(snapshotId, DataObjectType.SNAPSHOT, store.getId(), store.getRole());
|
||||
SnapshotObject so = new SnapshotObject(snapshot, store);
|
||||
return so;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.snapshot;
|
||||
|
||||
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.VolumeInfo;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.DiskFormat;
|
||||
import org.apache.cloudstack.storage.snapshot.db.SnapshotVO;
|
||||
|
||||
public class SnapshotObject implements SnapshotInfo {
|
||||
private SnapshotVO snapshot;
|
||||
private DataStore store;
|
||||
|
||||
public SnapshotObject(SnapshotVO snapshot, DataStore store) {
|
||||
this.snapshot = snapshot;
|
||||
this.store = store;
|
||||
}
|
||||
|
||||
public DataStore getStore() {
|
||||
return this.store;
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.snapshot.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SnapshotInfo getParent() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SnapshotInfo getChild() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VolumeInfo getBaseVolume() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUri() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataStore getDataStore() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getSize() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataObjectType getType() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiskFormat getFormat() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.snapshot.db;
|
||||
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface SnapshotDao2 extends GenericDao<SnapshotVO, Long> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.snapshot.db;
|
||||
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
|
||||
public class SnapshotDao2Impl extends GenericDaoBase<SnapshotVO, Long> implements SnapshotDao2 {
|
||||
|
||||
}
|
||||
@ -0,0 +1,296 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.storage.snapshot.db;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.storage.Snapshot.Status;
|
||||
import com.cloud.storage.Snapshot.Type;
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
import com.google.gson.annotations.Expose;
|
||||
|
||||
@Entity
|
||||
@Table(name="snapshots")
|
||||
public class SnapshotVO {
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
@Column(name="id")
|
||||
private final long id = -1;
|
||||
|
||||
@Column(name="data_center_id")
|
||||
long dataCenterId;
|
||||
|
||||
@Column(name="account_id")
|
||||
long accountId;
|
||||
|
||||
@Column(name="domain_id")
|
||||
long domainId;
|
||||
|
||||
@Column(name="volume_id")
|
||||
Long volumeId;
|
||||
|
||||
@Column(name="disk_offering_id")
|
||||
Long diskOfferingId;
|
||||
|
||||
@Expose
|
||||
@Column(name="path")
|
||||
String path;
|
||||
|
||||
@Expose
|
||||
@Column(name="name")
|
||||
String name;
|
||||
|
||||
@Expose
|
||||
@Column(name="status", updatable = true, nullable=false)
|
||||
@Enumerated(value=EnumType.STRING)
|
||||
private Status status;
|
||||
|
||||
@Column(name="snapshot_type")
|
||||
short snapshotType;
|
||||
|
||||
@Column(name="type_description")
|
||||
String typeDescription;
|
||||
|
||||
@Column(name="size")
|
||||
long size;
|
||||
|
||||
@Column(name=GenericDao.CREATED_COLUMN)
|
||||
Date created;
|
||||
|
||||
@Column(name=GenericDao.REMOVED_COLUMN)
|
||||
Date removed;
|
||||
|
||||
@Column(name="backup_snap_id")
|
||||
String backupSnapshotId;
|
||||
|
||||
@Column(name="swift_id")
|
||||
Long swiftId;
|
||||
|
||||
@Column(name="s3_id")
|
||||
Long s3Id;
|
||||
|
||||
@Column(name="sechost_id")
|
||||
Long secHostId;
|
||||
|
||||
@Column(name="prev_snap_id")
|
||||
long prevSnapshotId;
|
||||
|
||||
@Column(name="hypervisor_type")
|
||||
@Enumerated(value=EnumType.STRING)
|
||||
HypervisorType hypervisorType;
|
||||
|
||||
@Expose
|
||||
@Column(name="version")
|
||||
String version;
|
||||
|
||||
@Column(name="uuid")
|
||||
String uuid;
|
||||
|
||||
public SnapshotVO() {
|
||||
this.uuid = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
public SnapshotVO(long dcId, long accountId, long domainId, Long volumeId, Long diskOfferingId, String path, String name, short snapshotType, String typeDescription, long size, HypervisorType hypervisorType ) {
|
||||
this.dataCenterId = dcId;
|
||||
this.accountId = accountId;
|
||||
this.domainId = domainId;
|
||||
this.volumeId = volumeId;
|
||||
this.diskOfferingId = diskOfferingId;
|
||||
this.path = path;
|
||||
this.name = name;
|
||||
this.snapshotType = snapshotType;
|
||||
this.typeDescription = typeDescription;
|
||||
this.size = size;
|
||||
this.status = Status.Creating;
|
||||
this.prevSnapshotId = 0;
|
||||
this.hypervisorType = hypervisorType;
|
||||
this.version = "2.2";
|
||||
this.uuid = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public long getDataCenterId() {
|
||||
return dataCenterId;
|
||||
}
|
||||
|
||||
|
||||
public long getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
|
||||
public long getDomainId() {
|
||||
return domainId;
|
||||
}
|
||||
|
||||
public long getVolumeId() {
|
||||
return volumeId;
|
||||
}
|
||||
|
||||
public long getDiskOfferingId() {
|
||||
return diskOfferingId;
|
||||
}
|
||||
|
||||
public void setVolumeId(Long volumeId) {
|
||||
this.volumeId = volumeId;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
public void setPath(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public short getsnapshotType() {
|
||||
return snapshotType;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
if (snapshotType < 0 || snapshotType >= Type.values().length) {
|
||||
return null;
|
||||
}
|
||||
return Type.values()[snapshotType];
|
||||
}
|
||||
|
||||
public Long getSwiftId() {
|
||||
return swiftId;
|
||||
}
|
||||
|
||||
public void setSwiftId(Long swiftId) {
|
||||
this.swiftId = swiftId;
|
||||
}
|
||||
|
||||
public Long getSecHostId() {
|
||||
return secHostId;
|
||||
}
|
||||
|
||||
public void setSecHostId(Long secHostId) {
|
||||
this.secHostId = secHostId;
|
||||
}
|
||||
|
||||
public HypervisorType getHypervisorType() {
|
||||
return hypervisorType;
|
||||
}
|
||||
|
||||
public void setSnapshotType(short snapshotType) {
|
||||
this.snapshotType = snapshotType;
|
||||
}
|
||||
|
||||
public boolean isRecursive(){
|
||||
if ( snapshotType >= Type.HOURLY.ordinal() && snapshotType <= Type.MONTHLY.ordinal() ) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public long getSize() {
|
||||
return size;
|
||||
}
|
||||
|
||||
public String getTypeDescription() {
|
||||
return typeDescription;
|
||||
}
|
||||
public void setTypeDescription(String typeDescription) {
|
||||
this.typeDescription = typeDescription;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public Date getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public Date getRemoved() {
|
||||
return removed;
|
||||
}
|
||||
|
||||
public Status getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(Status status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public String getBackupSnapshotId(){
|
||||
return backupSnapshotId;
|
||||
}
|
||||
|
||||
public long getPrevSnapshotId(){
|
||||
return prevSnapshotId;
|
||||
}
|
||||
|
||||
public void setBackupSnapshotId(String backUpSnapshotId){
|
||||
this.backupSnapshotId = backUpSnapshotId;
|
||||
}
|
||||
|
||||
public void setPrevSnapshotId(long prevSnapshotId){
|
||||
this.prevSnapshotId = prevSnapshotId;
|
||||
}
|
||||
|
||||
public static Type getSnapshotType(String snapshotType) {
|
||||
for ( Type type : Type.values()) {
|
||||
if ( type.equals(snapshotType)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public Long getS3Id() {
|
||||
return s3Id;
|
||||
}
|
||||
|
||||
public void setS3Id(Long s3Id) {
|
||||
this.s3Id = s3Id;
|
||||
}
|
||||
|
||||
}
|
||||
@ -14,14 +14,3 @@
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.storage;
|
||||
|
||||
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
|
||||
public interface EndPoint {
|
||||
public Answer sendMessage(Command cmd);
|
||||
public void sendMessageAsync(Command cmd, AsyncCompletionCallback<Answer> callback);
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ package org.apache.cloudstack.storage;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
|
||||
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
||||
@ -18,17 +18,15 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.command;
|
||||
|
||||
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
||||
|
||||
import com.cloud.agent.api.Command;
|
||||
|
||||
public class AttachPrimaryDataStoreCmd extends Command implements StorageSubSystemCommand {
|
||||
private final PrimaryDataStoreTO dataStore;
|
||||
public AttachPrimaryDataStoreCmd(PrimaryDataStoreTO dataStore) {
|
||||
this.dataStore = dataStore;
|
||||
private final String dataStore;
|
||||
public AttachPrimaryDataStoreCmd(String uri) {
|
||||
this.dataStore = uri;
|
||||
}
|
||||
|
||||
public PrimaryDataStoreTO getDataStore() {
|
||||
public String getDataStore() {
|
||||
return this.dataStore;
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
package org.apache.cloudstack.storage.command;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
|
||||
public class CopyCmdAnswer extends Answer {
|
||||
private final String path;
|
||||
|
||||
public CopyCmdAnswer(Command cmd, String path) {
|
||||
super(cmd);
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
}
|
||||
@ -14,20 +14,3 @@
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package org.apache.cloudstack.storage.command;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
|
||||
public class CopyTemplateToPrimaryStorageAnswer extends Answer {
|
||||
private final String path;
|
||||
|
||||
public CopyTemplateToPrimaryStorageAnswer(Command cmd, String path) {
|
||||
super(cmd);
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return this.path;
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,16 +18,14 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.command;
|
||||
|
||||
import org.apache.cloudstack.storage.to.VolumeTO;
|
||||
|
||||
import com.cloud.agent.api.Command;
|
||||
|
||||
public class CreateVolumeCommand extends Command implements StorageSubSystemCommand {
|
||||
protected VolumeTO volumeTO;
|
||||
protected String volumeUri;
|
||||
|
||||
public CreateVolumeCommand(VolumeTO volumeTO) {
|
||||
public CreateVolumeCommand(String volumeUri) {
|
||||
super();
|
||||
this.volumeTO = volumeTO;
|
||||
this.volumeUri = volumeUri;
|
||||
}
|
||||
|
||||
protected CreateVolumeCommand() {
|
||||
@ -40,8 +38,8 @@ public class CreateVolumeCommand extends Command implements StorageSubSystemComm
|
||||
return false;
|
||||
}
|
||||
|
||||
public VolumeTO getVolume() {
|
||||
return this.volumeTO;
|
||||
public String getVolume() {
|
||||
return this.volumeUri;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -22,13 +22,13 @@ import org.apache.cloudstack.storage.to.VolumeTO;
|
||||
|
||||
import com.cloud.agent.api.Command;
|
||||
|
||||
public class DeleteVolumeCommand extends Command implements StorageSubSystemCommand {
|
||||
private VolumeTO volume;
|
||||
public DeleteVolumeCommand(VolumeTO volume) {
|
||||
this.volume = volume;
|
||||
public class DeleteCommand extends Command implements StorageSubSystemCommand {
|
||||
private String uri;
|
||||
public DeleteCommand(String uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
protected DeleteVolumeCommand() {
|
||||
protected DeleteCommand() {
|
||||
|
||||
}
|
||||
@Override
|
||||
@ -37,8 +37,8 @@ public class DeleteVolumeCommand extends Command implements StorageSubSystemComm
|
||||
return false;
|
||||
}
|
||||
|
||||
public VolumeTO getVolume() {
|
||||
return this.volume;
|
||||
public String getUri() {
|
||||
return this.uri;
|
||||
}
|
||||
|
||||
}
|
||||
@ -14,20 +14,3 @@
|
||||
// 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;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
|
||||
import org.apache.cloudstack.storage.EndPoint;
|
||||
import org.apache.cloudstack.storage.image.TemplateInfo;
|
||||
import org.apache.cloudstack.storage.snapshot.SnapshotInfo;
|
||||
|
||||
public interface DataStore {
|
||||
String grantAccess(VolumeInfo volume, EndPoint ep);
|
||||
boolean revokeAccess(VolumeInfo volume, EndPoint ep);
|
||||
String grantAccess(TemplateInfo template, EndPoint ep);
|
||||
boolean revokeAccess(TemplateInfo template, EndPoint ep);
|
||||
String grantAccess(SnapshotInfo snapshot, EndPoint ep);
|
||||
boolean revokeAccess(SnapshotInfo snapshot, EndPoint ep);
|
||||
String getRole();
|
||||
long getId();
|
||||
}
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.datastore;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreRole;
|
||||
|
||||
public interface DataStoreManager {
|
||||
public DataStore getDataStore(long storeId, DataStoreRole role);
|
||||
public DataStore registerDataStore(Map<String, String> params, String providerUuid);
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.datastore;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreRole;
|
||||
import org.apache.cloudstack.storage.image.datastore.ImageDataStoreManager;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
@Component
|
||||
public class DataStoreManagerImpl implements DataStoreManager {
|
||||
@Inject
|
||||
PrimaryDataStoreProviderManager primaryStorMgr;
|
||||
@Inject
|
||||
ImageDataStoreManager imageDataStoreMgr;
|
||||
@Override
|
||||
public DataStore getDataStore(long storeId, DataStoreRole role) {
|
||||
if (role == DataStoreRole.Primary) {
|
||||
return primaryStorMgr.getPrimaryDataStore(storeId);
|
||||
} else if (role == DataStoreRole.Image) {
|
||||
return imageDataStoreMgr.getImageDataStore(storeId);
|
||||
}
|
||||
throw new CloudRuntimeException("un recognized type" + role);
|
||||
}
|
||||
@Override
|
||||
public DataStore registerDataStore(Map<String, String> params,
|
||||
String providerUuid) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,109 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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.DataStoreLifeCycle;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreRole;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
|
||||
import org.apache.cloudstack.storage.image.datastore.ImageDataStoreHelper;
|
||||
import org.apache.cloudstack.storage.volume.datastore.PrimaryDataStoreHelper;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import edu.emory.mathcs.backport.java.util.Arrays;
|
||||
|
||||
public class DefaultDatastoreLifeCyle implements DataStoreLifeCycle {
|
||||
@Inject
|
||||
PrimaryDataStoreHelper primaryStoreHelper;
|
||||
@Inject
|
||||
ImageDataStoreHelper imageStoreHelper;
|
||||
@Override
|
||||
public boolean initialize(DataStore store, Map<String, String> dsInfos) {
|
||||
String roles = dsInfos.get("roles");
|
||||
List<String> roleArry = Arrays.asList(roles.split(";"));
|
||||
List<DataStoreRole> storeRoles = new ArrayList<DataStoreRole>();
|
||||
for (String role : roleArry) {
|
||||
storeRoles.add(DataStoreRole.getRole(role));
|
||||
}
|
||||
|
||||
if (storeRoles.contains(DataStoreRole.Primary)) {
|
||||
primaryStoreHelper.createPrimaryDataStore(dsInfos);
|
||||
}
|
||||
|
||||
if (storeRoles.contains(DataStoreRole.Image)) {
|
||||
imageStoreHelper.createImageDataStore(dsInfos);
|
||||
}
|
||||
|
||||
//TODO: add more roles
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean attachCluster(DataStore dataStore, ClusterScope scope) {
|
||||
if (dataStore.getRole() == DataStoreRole.Primary) {
|
||||
primaryStoreHelper.attachCluster(dataStore);
|
||||
}
|
||||
// TODO Auto-generated method stub
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean attachZone(DataStore dataStore, ZoneScope scope) {
|
||||
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() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cancelMaintain() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteDataStore() {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@ -16,18 +16,24 @@
|
||||
// under the License.
|
||||
package org.apache.cloudstack.storage.datastore;
|
||||
|
||||
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.DataStoreRole;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
|
||||
import org.apache.cloudstack.storage.db.ObjectInDataStoreVO;
|
||||
import org.apache.cloudstack.storage.image.TemplateInfo;
|
||||
import org.apache.cloudstack.storage.snapshot.SnapshotInfo;
|
||||
import org.apache.cloudstack.storage.volume.ObjectInDataStoreStateMachine;
|
||||
import org.apache.cloudstack.storage.volume.ObjectInDataStoreStateMachine.Event;
|
||||
|
||||
import com.cloud.utils.fsm.NoTransitionException;
|
||||
|
||||
public interface ObjectInDataStoreManager {
|
||||
public TemplateInfo create(TemplateInfo template, DataStore dataStore);
|
||||
public ObjectInDataStoreVO create(VolumeInfo volume, DataStore dataStore);
|
||||
public ObjectInDataStoreVO create(SnapshotInfo snapshot, DataStore dataStore);
|
||||
public TemplateInfo findTemplate(TemplateInfo template, DataStore dataStore);
|
||||
public VolumeInfo findVolume(VolumeInfo volume, DataStore dataStore);
|
||||
public SnapshotInfo findSnapshot(SnapshotInfo snapshot, DataStore dataStore);
|
||||
public boolean update(TemplateInfo vo, ObjectInDataStoreStateMachine.Event event);
|
||||
public VolumeInfo create(VolumeInfo volume, DataStore dataStore);
|
||||
public SnapshotInfo create(SnapshotInfo snapshot, DataStore dataStore);
|
||||
public ObjectInDataStoreVO findObject(long objectId, DataObjectType type,
|
||||
long dataStoreId, DataStoreRole role);
|
||||
public boolean update(DataObject vo, Event event) throws NoTransitionException;
|
||||
}
|
||||
|
||||
@ -18,66 +18,131 @@ package org.apache.cloudstack.storage.datastore;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
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.DataStoreRole;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
|
||||
import org.apache.cloudstack.storage.db.ObjectInDataStoreDao;
|
||||
import org.apache.cloudstack.storage.db.ObjectInDataStoreVO;
|
||||
import org.apache.cloudstack.storage.image.ImageDataFactory;
|
||||
import org.apache.cloudstack.storage.image.TemplateInfo;
|
||||
import org.apache.cloudstack.storage.snapshot.SnapshotInfo;
|
||||
import org.apache.cloudstack.storage.volume.ObjectInDataStoreStateMachine;
|
||||
import org.apache.cloudstack.storage.volume.ObjectInDataStoreStateMachine.Event;
|
||||
import org.apache.cloudstack.storage.volume.ObjectInDataStoreStateMachine.State;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
import com.cloud.utils.db.SearchCriteria2;
|
||||
import com.cloud.utils.db.SearchCriteriaService;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.fsm.NoTransitionException;
|
||||
import com.cloud.utils.fsm.StateMachine2;
|
||||
|
||||
@Component
|
||||
public class ObjectInDataStoreManagerImpl implements ObjectInDataStoreManager {
|
||||
public class ObjectInDataStoreManagerImpl implements ObjectInDataStoreManager {
|
||||
@Inject
|
||||
ImageDataFactory imageFactory;
|
||||
@Inject
|
||||
VolumeDataFactory volumeFactory;
|
||||
@Inject
|
||||
ObjectInDataStoreDao objectDataStoreDao;
|
||||
protected StateMachine2<State, Event, ObjectInDataStoreVO> stateMachines;
|
||||
|
||||
public ObjectInDataStoreManagerImpl() {
|
||||
stateMachines = new StateMachine2<State, Event, ObjectInDataStoreVO>();
|
||||
stateMachines.addTransition(State.Allocated, Event.CreateRequested,
|
||||
State.Creating);
|
||||
stateMachines.addTransition(State.Creating, Event.OperationSuccessed,
|
||||
State.Created);
|
||||
stateMachines.addTransition(State.Creating, Event.OperationFailed,
|
||||
State.Failed);
|
||||
stateMachines.addTransition(State.Failed, Event.CreateRequested,
|
||||
State.Creating);
|
||||
stateMachines.addTransition(State.Ready, Event.DestroyRequested,
|
||||
State.Destroying);
|
||||
stateMachines.addTransition(State.Destroying, Event.OperationSuccessed,
|
||||
State.Destroyed);
|
||||
stateMachines.addTransition(State.Destroying, Event.OperationFailed,
|
||||
State.Destroying);
|
||||
stateMachines.addTransition(State.Destroying, Event.DestroyRequested,
|
||||
State.Destroying);
|
||||
stateMachines.addTransition(State.Created, Event.CopyingRequested,
|
||||
State.Copying);
|
||||
stateMachines.addTransition(State.Copying, Event.OperationFailed,
|
||||
State.Created);
|
||||
stateMachines.addTransition(State.Copying, Event.OperationSuccessed,
|
||||
State.Ready);
|
||||
stateMachines.addTransition(State.Allocated, Event.CreateOnlyRequested,
|
||||
State.Creating2);
|
||||
stateMachines.addTransition(State.Creating2, Event.OperationFailed,
|
||||
State.Failed);
|
||||
stateMachines.addTransition(State.Creating2, Event.OperationSuccessed,
|
||||
State.Ready);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateInfo create(TemplateInfo template, DataStore dataStore) {
|
||||
ObjectInDataStoreVO vo = new ObjectInDataStoreVO();
|
||||
vo.setDataStoreId(dataStore.getId());
|
||||
vo.setDataStoreType(dataStore.getRole());
|
||||
vo.setDataStoreRole(dataStore.getRole());
|
||||
vo.setObjectId(template.getId());
|
||||
vo.setObjectType("template");
|
||||
|
||||
vo.setObjectType(template.getType());
|
||||
vo = objectDataStoreDao.persist(vo);
|
||||
TemplateInDataStore tmpl = new TemplateInDataStore(template, dataStore, vo);
|
||||
return tmpl;
|
||||
|
||||
return imageFactory.getTemplate(template.getId(), dataStore);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectInDataStoreVO create(VolumeInfo volume, DataStore dataStore) {
|
||||
public VolumeInfo create(VolumeInfo volume, DataStore dataStore) {
|
||||
ObjectInDataStoreVO vo = new ObjectInDataStoreVO();
|
||||
vo.setDataStoreId(dataStore.getId());
|
||||
vo.setDataStoreRole(dataStore.getRole());
|
||||
vo.setObjectId(volume.getId());
|
||||
vo.setObjectType(volume.getType());
|
||||
vo = objectDataStoreDao.persist(vo);
|
||||
|
||||
return volumeFactory.getVolume(volume.getId(), dataStore);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SnapshotInfo create(SnapshotInfo snapshot, DataStore dataStore) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectInDataStoreVO create(SnapshotInfo snapshot, DataStore dataStore) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
public ObjectInDataStoreVO findObject(long objectId, DataObjectType type,
|
||||
long dataStoreId, DataStoreRole role) {
|
||||
SearchCriteriaService<ObjectInDataStoreVO, ObjectInDataStoreVO> sc = SearchCriteria2
|
||||
.create(ObjectInDataStoreVO.class);
|
||||
sc.addAnd(sc.getEntity().getObjectId(), Op.EQ, objectId);
|
||||
sc.addAnd(sc.getEntity().getDataStoreId(), Op.EQ, dataStoreId);
|
||||
sc.addAnd(sc.getEntity().getObjectType(), Op.EQ, type);
|
||||
sc.addAnd(sc.getEntity().getDataStoreRole(), Op.EQ, role);
|
||||
sc.addAnd(sc.getEntity().getState(), Op.NIN,
|
||||
ObjectInDataStoreStateMachine.State.Destroyed,
|
||||
ObjectInDataStoreStateMachine.State.Failed);
|
||||
ObjectInDataStoreVO objectStoreVO = sc.find();
|
||||
return objectStoreVO;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TemplateInfo findTemplate(TemplateInfo template, DataStore dataStore) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
public boolean update(DataObject data, Event event)
|
||||
throws NoTransitionException {
|
||||
ObjectInDataStoreVO obj = this.findObject(data.getId(), data.getType(),
|
||||
data.getDataStore().getId(), data.getDataStore().getRole());
|
||||
if (obj == null) {
|
||||
throw new CloudRuntimeException(
|
||||
"can't find mapping in ObjectInDataStore table for: "
|
||||
+ data);
|
||||
}
|
||||
return this.stateMachines.transitTo(obj, event, null,
|
||||
objectDataStoreDao);
|
||||
|
||||
@Override
|
||||
public VolumeInfo findVolume(VolumeInfo volume, DataStore dataStore) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SnapshotInfo findSnapshot(SnapshotInfo snapshot, DataStore dataStore) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(TemplateInfo vo, Event event) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -20,15 +20,17 @@ package org.apache.cloudstack.storage.datastore;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.CommandResult;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.DiskFormat;
|
||||
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
||||
import org.apache.cloudstack.storage.EndPoint;
|
||||
import org.apache.cloudstack.storage.command.CommandResult;
|
||||
import org.apache.cloudstack.storage.image.TemplateInfo;
|
||||
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
||||
import org.apache.cloudstack.storage.to.VolumeTO;
|
||||
import org.apache.cloudstack.storage.snapshot.SnapshotInfo;
|
||||
import org.apache.cloudstack.storage.volume.PrimaryDataStoreDriver;
|
||||
import org.apache.cloudstack.storage.volume.TemplateOnPrimaryDataStoreInfo;
|
||||
|
||||
public interface PrimaryDataStore extends DataStore, PrimaryDataStoreInfo {
|
||||
@ -36,27 +38,28 @@ public interface PrimaryDataStore extends DataStore, PrimaryDataStoreInfo {
|
||||
|
||||
List<VolumeInfo> getVolumes();
|
||||
|
||||
void deleteVolumeAsync(VolumeInfo volume, AsyncCompletionCallback<CommandResult> callback);
|
||||
/* void deleteVolumeAsync(VolumeInfo volume, AsyncCompletionCallback<CommandResult> callback);
|
||||
|
||||
void createVolumeAsync(VolumeInfo vo, VolumeDiskType diskType, AsyncCompletionCallback<CommandResult> callback);
|
||||
|
||||
VolumeInfo createVoluemFromBaseImage(VolumeInfo volume, TemplateOnPrimaryDataStoreInfo templateStore);
|
||||
|
||||
void createVoluemFromBaseImageAsync(VolumeInfo volume, TemplateInfo templateStore, AsyncCompletionCallback<CommandResult> callback);
|
||||
*/
|
||||
|
||||
boolean exists(DataObject data);
|
||||
|
||||
TemplateInfo getTemplate(long templateId);
|
||||
|
||||
List<EndPoint> getEndPoints();
|
||||
SnapshotInfo getSnapshot(long snapshotId);
|
||||
|
||||
boolean exists(VolumeInfo vi);
|
||||
|
||||
boolean templateExists(TemplateInfo template);
|
||||
DiskFormat getDefaultDiskType();
|
||||
|
||||
TemplateOnPrimaryDataStoreInfo getTemplate(TemplateInfo template);
|
||||
/* void takeSnapshot(SnapshotInfo snapshot,
|
||||
AsyncCompletionCallback<CommandResult> callback);
|
||||
|
||||
boolean installTemplate(TemplateOnPrimaryDataStoreInfo template);
|
||||
void revertSnapshot(SnapshotInfo snapshot,
|
||||
AsyncCompletionCallback<CommandResult> callback);
|
||||
|
||||
VolumeDiskType getDefaultDiskType();
|
||||
|
||||
PrimaryDataStoreTO getDataStoreTO();
|
||||
|
||||
VolumeTO getVolumeTO(VolumeInfo volume);
|
||||
void deleteSnapshot(SnapshotInfo snapshot,
|
||||
AsyncCompletionCallback<CommandResult> callback);*/
|
||||
}
|
||||
|
||||
@ -16,12 +16,13 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.datastore.manager;
|
||||
package org.apache.cloudstack.storage.datastore;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle;
|
||||
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
|
||||
import org.apache.cloudstack.storage.volume.PrimaryDataStoreDriver;
|
||||
|
||||
public interface PrimaryDataStoreManager {
|
||||
|
||||
public interface PrimaryDataStoreProviderManager {
|
||||
public PrimaryDataStore getPrimaryDataStore(long dataStoreId);
|
||||
|
||||
boolean registerDriver(String uuid, PrimaryDataStoreDriver driver);
|
||||
}
|
||||
@ -14,45 +14,3 @@
|
||||
// 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;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
|
||||
import org.apache.cloudstack.storage.db.ObjectInDataStoreVO;
|
||||
import org.apache.cloudstack.storage.image.TemplateInfo;
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStoreInfo;
|
||||
|
||||
public class TemplateInDataStore implements TemplateInfo {
|
||||
public TemplateInDataStore(TemplateInfo template, DataStore dataStore, ObjectInDataStoreVO obj) {
|
||||
|
||||
}
|
||||
@Override
|
||||
public ImageDataStoreInfo getDataStore() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VolumeDiskType getDiskType() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPath() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUuid() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.datastore;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
|
||||
|
||||
public interface VolumeDataFactory {
|
||||
VolumeInfo getVolume(long volumeId, DataStore store);
|
||||
}
|
||||
@ -20,6 +20,6 @@ package org.apache.cloudstack.storage.datastore.db;
|
||||
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
|
||||
public interface PrimaryDataStoreProviderDao extends GenericDao<PrimaryDataStoreProviderVO, Long> {
|
||||
public PrimaryDataStoreProviderVO findByName(String name);
|
||||
public interface DataStoreProviderDao extends GenericDao<DataStoreProviderVO, Long> {
|
||||
public DataStoreProviderVO findByName(String name);
|
||||
}
|
||||
@ -26,11 +26,11 @@ import com.cloud.utils.db.SearchCriteriaService;
|
||||
import com.cloud.utils.db.SearchCriteria.Op;
|
||||
|
||||
@Component
|
||||
class PrimaryDataStoreProviderDaoImpl extends GenericDaoBase<PrimaryDataStoreProviderVO, Long> implements PrimaryDataStoreProviderDao {
|
||||
class DataStoreProviderDaoImpl extends GenericDaoBase<DataStoreProviderVO, Long> implements DataStoreProviderDao {
|
||||
|
||||
@Override
|
||||
public PrimaryDataStoreProviderVO findByName(String name) {
|
||||
SearchCriteriaService<PrimaryDataStoreProviderVO, PrimaryDataStoreProviderVO> sc = SearchCriteria2.create(PrimaryDataStoreProviderVO.class);
|
||||
public DataStoreProviderVO findByName(String name) {
|
||||
SearchCriteriaService<DataStoreProviderVO, DataStoreProviderVO> sc = SearchCriteria2.create(DataStoreProviderVO.class);
|
||||
sc.addAnd(sc.getEntity().getName(), Op.EQ, name);
|
||||
return sc.find();
|
||||
}
|
||||
@ -25,8 +25,8 @@ import javax.persistence.Table;
|
||||
import javax.persistence.TableGenerator;
|
||||
|
||||
@Entity
|
||||
@Table(name = "primary_data_store_provider")
|
||||
public class PrimaryDataStoreProviderVO {
|
||||
@Table(name = "data_store_provider")
|
||||
public class DataStoreProviderVO {
|
||||
@Id
|
||||
@TableGenerator(name = "data_store_provider_sq", table = "sequence", pkColumnName = "name", valueColumnName = "value", pkColumnValue = "data_store_provider_seq", allocationSize = 1)
|
||||
@Column(name = "id", updatable = false, nullable = false)
|
||||
@ -35,6 +35,9 @@ public class PrimaryDataStoreProviderVO {
|
||||
@Column(name = "name", nullable = false)
|
||||
private String name;
|
||||
|
||||
@Column(name = "uuid", nullable = false)
|
||||
private String uuid;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
@ -46,4 +49,12 @@ public class PrimaryDataStoreProviderVO {
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
}
|
||||
@ -26,7 +26,6 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.DataStoreStatus;
|
||||
@ -50,7 +49,7 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<PrimaryDataStoreVO,
|
||||
protected final SearchBuilder<PrimaryDataStoreVO> DeleteLvmSearch;
|
||||
protected final GenericSearchBuilder<PrimaryDataStoreVO, Long> StatusCountSearch;
|
||||
|
||||
@Inject protected PrimaryDataStoreDetailsDao _detailsDao;
|
||||
protected final PrimaryDataStoreDetailsDao _detailsDao = null;
|
||||
|
||||
private final String DetailsSqlPrefix = "SELECT storage_pool.* from storage_pool LEFT JOIN storage_pool_details ON storage_pool.id = storage_pool_details.pool_id WHERE storage_pool.removed is null and storage_pool.data_center_id = ? and (storage_pool.pod_id = ? or storage_pool.pod_id is null) and (";
|
||||
private final String DetailsSqlSuffix = ") GROUP BY storage_pool_details.pool_id HAVING COUNT(storage_pool_details.name) >= ?";
|
||||
@ -96,7 +95,9 @@ public class PrimaryDataStoreDaoImpl extends GenericDaoBase<PrimaryDataStoreVO,
|
||||
StatusCountSearch.and("status", StatusCountSearch.entity().getStatus(), SearchCriteria.Op.IN);
|
||||
StatusCountSearch.select(null, Func.COUNT, null);
|
||||
StatusCountSearch.done();
|
||||
}
|
||||
|
||||
// _detailsDao = ComponentInject.inject(PrimaryDataStoreDetailsDaoImpl.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PrimaryDataStoreVO> findPoolByName(String name) {
|
||||
@ -31,6 +31,7 @@ import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
import org.apache.cloudstack.api.Identity;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ScopeType;
|
||||
import org.apache.cloudstack.storage.datastore.DataStoreStatus;
|
||||
|
||||
import com.cloud.utils.db.GenericDao;
|
||||
@ -96,8 +97,8 @@ public class PrimaryDataStoreVO implements Identity {
|
||||
@Column(name = "cluster_id")
|
||||
private Long clusterId;
|
||||
|
||||
@Column(name = "configurator_key")
|
||||
private String key;
|
||||
@Column(name = "scope")
|
||||
private ScopeType scope;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
@ -236,12 +237,12 @@ public class PrimaryDataStoreVO implements Identity {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setKey(String key) {
|
||||
this.key = key;
|
||||
public void setScope(ScopeType scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
public ScopeType getScope() {
|
||||
return this.scope;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -16,19 +16,17 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image.provider;
|
||||
package org.apache.cloudstack.storage.datastore.provider;
|
||||
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStore;
|
||||
import org.apache.cloudstack.storage.image.store.lifecycle.ImageDataStoreLifeCycle;
|
||||
import java.util.Map;
|
||||
|
||||
public interface ImageDataStoreProvider {
|
||||
ImageDataStore getImageDataStore(long imageStoreId);
|
||||
boolean register(long providerId);
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreLifeCycle;
|
||||
|
||||
public interface DataStoreProvider {
|
||||
public DataStoreLifeCycle getLifeCycle();
|
||||
public String getName();
|
||||
ImageDataStoreLifeCycle getLifeCycle();
|
||||
/**
|
||||
* @param providerId
|
||||
* @return
|
||||
*/
|
||||
boolean init();
|
||||
public String getUuid();
|
||||
public long getId();
|
||||
public boolean configure(Map<String, Object> params);
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.datastore.provider;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.cloud.utils.component.Manager;
|
||||
|
||||
public interface DataStoreProviderManager extends Manager {
|
||||
public DataStoreProvider getDataStoreProviderByUuid(String uuid);
|
||||
public DataStoreProvider getDataStoreProviderById(long id);
|
||||
public DataStoreProvider getDataStoreProvider(String name);
|
||||
public List<DataStoreProvider> getDataStoreProviders();
|
||||
}
|
||||
@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.db.DataStoreProviderDao;
|
||||
import org.apache.cloudstack.storage.datastore.db.DataStoreProviderVO;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class DataStoreProviderManagerImpl implements DataStoreProviderManager {
|
||||
@Inject
|
||||
List<DataStoreProvider> providers;
|
||||
@Inject
|
||||
DataStoreProviderDao providerDao;
|
||||
protected Map<String, DataStoreProvider> providerMap = new HashMap<String, DataStoreProvider>();
|
||||
@Override
|
||||
public DataStoreProvider getDataStoreProviderByUuid(String uuid) {
|
||||
return providerMap.get(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataStoreProvider getDataStoreProvider(String name) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DataStoreProvider> getDataStoreProviders() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params)
|
||||
throws ConfigurationException {
|
||||
//TODO: hold global lock
|
||||
List<DataStoreProviderVO> providerVos = providerDao.listAll();
|
||||
for (DataStoreProvider provider : providers) {
|
||||
boolean existingProvider = false;
|
||||
DataStoreProviderVO providerVO = null;
|
||||
for (DataStoreProviderVO prov : providerVos) {
|
||||
if (prov.getName().equalsIgnoreCase(provider.getName())) {
|
||||
existingProvider = true;
|
||||
providerVO = prov;
|
||||
break;
|
||||
}
|
||||
}
|
||||
String uuid = provider.getUuid();
|
||||
if (!existingProvider) {
|
||||
uuid = UUID.nameUUIDFromBytes(provider.getName().getBytes()).toString();
|
||||
providerVO = new DataStoreProviderVO();
|
||||
providerVO.setName(provider.getName());
|
||||
providerVO.setUuid(uuid);
|
||||
providerVO = providerDao.persist(providerVO);
|
||||
}
|
||||
params.put("uuid", uuid);
|
||||
params.put("id", providerVO.getId());
|
||||
provider.configure(params);
|
||||
providerMap.put(uuid, provider);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Data store provider manager";
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataStoreProvider getDataStoreProviderById(long id) {
|
||||
DataStoreProviderVO provider = providerDao.findById(id);
|
||||
return providerMap.get(provider.getUuid());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.datastore.provider;
|
||||
|
||||
public interface ImageDataStoreProvider extends DataStoreProvider {
|
||||
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package org.apache.cloudstack.storage.datastore.provider;
|
||||
|
||||
|
||||
public interface PrimaryDataStoreProvider extends DataStoreProvider {
|
||||
}
|
||||
@ -29,12 +29,17 @@ import javax.persistence.Table;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObjectType;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreRole;
|
||||
import org.apache.cloudstack.storage.volume.ObjectInDataStoreStateMachine;
|
||||
|
||||
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.fsm.StateObject;
|
||||
|
||||
@Entity
|
||||
@Table(name = "object_datastore_ref")
|
||||
public class ObjectInDataStoreVO {
|
||||
public class ObjectInDataStoreVO implements StateObject<ObjectInDataStoreStateMachine.State> {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
long id;
|
||||
@ -42,14 +47,16 @@ public class ObjectInDataStoreVO {
|
||||
@Column(name = "datastore_id")
|
||||
private long dataStoreId;
|
||||
|
||||
@Column(name = "datastore_type")
|
||||
private String dataStoreType;
|
||||
@Column(name = "datastore_role")
|
||||
@Enumerated(EnumType.STRING)
|
||||
private DataStoreRole dataStoreRole;
|
||||
|
||||
@Column(name = "ojbect_id")
|
||||
long objectId;
|
||||
|
||||
@Column(name = "object_type")
|
||||
String objectType;
|
||||
@Enumerated(EnumType.STRING)
|
||||
DataObjectType objectType;
|
||||
|
||||
@Column(name = GenericDaoBase.CREATED_COLUMN)
|
||||
Date created = null;
|
||||
@ -81,11 +88,16 @@ public class ObjectInDataStoreVO {
|
||||
long size;
|
||||
|
||||
@Column(name = "state")
|
||||
String state;
|
||||
@Enumerated(EnumType.STRING)
|
||||
ObjectInDataStoreStateMachine.State state;
|
||||
|
||||
@Column(name="update_count", updatable = true, nullable=false)
|
||||
protected long updatedCount;
|
||||
|
||||
public ObjectInDataStoreVO() {
|
||||
this.state = ObjectInDataStoreStateMachine.State.Allocated;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return this.id;
|
||||
}
|
||||
@ -98,12 +110,12 @@ public class ObjectInDataStoreVO {
|
||||
this.dataStoreId = id;
|
||||
}
|
||||
|
||||
public String getDataStoreType() {
|
||||
return this.dataStoreType;
|
||||
public DataStoreRole getDataStoreRole() {
|
||||
return this.dataStoreRole;
|
||||
}
|
||||
|
||||
public void setDataStoreType(String type) {
|
||||
this.dataStoreType = type;
|
||||
public void setDataStoreRole(DataStoreRole role) {
|
||||
this.dataStoreRole = role;
|
||||
}
|
||||
|
||||
public long getObjectId() {
|
||||
@ -114,11 +126,24 @@ public class ObjectInDataStoreVO {
|
||||
this.objectId = id;
|
||||
}
|
||||
|
||||
public String getObjectType() {
|
||||
public DataObjectType getObjectType() {
|
||||
return this.objectType;
|
||||
}
|
||||
|
||||
public void setObjectType(String type) {
|
||||
public void setObjectType(DataObjectType type) {
|
||||
this.objectType = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectInDataStoreStateMachine.State getState() {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
public void setInstallPath(String path) {
|
||||
this.installPath = path;
|
||||
}
|
||||
|
||||
public String getInstallPath() {
|
||||
return this.installPath;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,149 @@
|
||||
/*
|
||||
* 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.endpoint;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreRole;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.ScopeType;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.DiskFormat;
|
||||
import org.apache.cloudstack.storage.HypervisorHostEndPoint;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
|
||||
@Component
|
||||
public class DefaultEndPointSelector implements EndPointSelector {
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(DefaultEndPointSelector.class);
|
||||
@Inject
|
||||
HostDao hostDao;
|
||||
private String findOneHostInaScope = "select id from host where "
|
||||
+ " status == 'Up' and hypervisor_type != 'VMware' and type in ('Routing', 'SecondaryStorageVM') ";
|
||||
|
||||
protected boolean moveBetweenPrimaryImage(DataStore srcStore,
|
||||
DataStore destStore) {
|
||||
DataStoreRole srcRole = srcStore.getRole();
|
||||
DataStoreRole destRole = destStore.getRole();
|
||||
if ((srcRole == DataStoreRole.Primary && destRole.isImageStore())
|
||||
|| (srcRole.isImageStore() && destRole == DataStoreRole.Primary)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@DB
|
||||
protected EndPoint findEndPointInScope(Scope scope) {
|
||||
StringBuilder sbuilder = new StringBuilder();
|
||||
sbuilder.append(findOneHostInaScope);
|
||||
|
||||
if (scope.getScopeType() == ScopeType.HOST) {
|
||||
sbuilder.append(" and id = ");
|
||||
sbuilder.append(scope.getScopeId());
|
||||
} else if (scope.getScopeType() == ScopeType.CLUSTER) {
|
||||
sbuilder.append(" and cluster_id = ");
|
||||
sbuilder.append(scope.getScopeId());
|
||||
} else if (scope.getScopeType() == ScopeType.ZONE) {
|
||||
sbuilder.append(" and data_center_id = ");
|
||||
sbuilder.append(scope.getScopeId());
|
||||
}
|
||||
|
||||
sbuilder.append(" ORDER by rand() limit 1");
|
||||
String sql = sbuilder.toString();
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
HostVO host = null;
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
|
||||
try {
|
||||
pstmt = txn.prepareStatement(sql);
|
||||
rs = pstmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
long id = rs.getLong(1);
|
||||
host = hostDao.findById(id);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
s_logger.warn("can't find endpoint", e);
|
||||
} finally {
|
||||
try {
|
||||
if (rs != null) {
|
||||
rs.close();
|
||||
}
|
||||
if (pstmt != null) {
|
||||
pstmt.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
|
||||
if (host == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new HypervisorHostEndPoint(host.getId(),
|
||||
host.getPrivateIpAddress());
|
||||
}
|
||||
|
||||
protected EndPoint findEndPointForImageMove(DataStore srcStore,
|
||||
DataStore destStore) {
|
||||
// find any xen/kvm host in the scope
|
||||
Scope srcScope = srcStore.getScope();
|
||||
Scope destScope = destStore.getScope();
|
||||
Scope selectedScope = null;
|
||||
// assumption, at least one of scope should be zone, find the least
|
||||
// scope
|
||||
if (srcScope.getScopeType() != ScopeType.ZONE) {
|
||||
selectedScope = srcScope;
|
||||
} else if (destScope.getScopeType() != ScopeType.ZONE) {
|
||||
selectedScope = destScope;
|
||||
} else {
|
||||
// if both are zone scope
|
||||
selectedScope = srcScope;
|
||||
}
|
||||
return findEndPointInScope(selectedScope);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EndPoint select(DataObject srcData, DataObject destData) {
|
||||
DataStore srcStore = srcData.getDataStore();
|
||||
DataStore destStore = destData.getDataStore();
|
||||
if (srcData.getFormat() == DiskFormat.VMDK
|
||||
|| destData.getFormat() == DiskFormat.VMDK) {
|
||||
// If any of data is for vmware, data moving should go to ssvm
|
||||
|
||||
} else if (moveBetweenPrimaryImage(srcStore, destStore)) {
|
||||
return findEndPointForImageMove(srcStore, destStore);
|
||||
}
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.endpoint;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
|
||||
|
||||
public interface EndPointSelector {
|
||||
public EndPoint select(DataObject srcData, DataObject destData);
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
|
||||
public interface ImageDataFactory {
|
||||
TemplateInfo getTemplate(long templateId, DataStore store);
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver;
|
||||
|
||||
public interface ImageDataStoreDriver extends DataStoreDriver {
|
||||
}
|
||||
@ -18,25 +18,11 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image;
|
||||
|
||||
import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity;
|
||||
import org.apache.cloudstack.storage.EndPoint;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.CommandResult;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.framework.async.AsyncCallFuture;
|
||||
|
||||
public interface ImageService {
|
||||
TemplateEntity registerTemplate(long templateId, long imageStoreId);
|
||||
|
||||
boolean deleteTemplate(long templateId);
|
||||
|
||||
long registerIso(String isoUrl, long accountId);
|
||||
|
||||
boolean deleteIso(long isoId);
|
||||
|
||||
boolean grantTemplateAccess(TemplateInfo template, EndPoint endpointId);
|
||||
|
||||
boolean revokeTemplateAccess(long templateId, long endpointId);
|
||||
|
||||
String grantIsoAccess(long isoId, long endpointId);
|
||||
|
||||
boolean revokeIsoAccess(long isoId, long endpointId);
|
||||
|
||||
TemplateEntity getTemplateEntity(long templateId);
|
||||
AsyncCallFuture<CommandResult> createTemplateAsync(TemplateInfo template, DataStore store);
|
||||
AsyncCallFuture<CommandResult> deleteTemplateAsync(TemplateInfo template);
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity;
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStoreInfo;
|
||||
import org.apache.cloudstack.storage.image.datastore.ImageDataStoreInfo;
|
||||
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.storage.Storage.ImageFormat;
|
||||
|
||||
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image;
|
||||
|
||||
public enum TemplateEvent {
|
||||
CreateRequested,
|
||||
OperationFailed,
|
||||
OperationSucceeded,
|
||||
DestroyRequested;
|
||||
}
|
||||
@ -18,17 +18,19 @@
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStoreInfo;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
|
||||
public interface TemplateInfo {
|
||||
ImageDataStoreInfo getDataStore();
|
||||
import com.cloud.utils.fsm.NoTransitionException;
|
||||
|
||||
public interface TemplateInfo extends DataObject {
|
||||
DataStore getDataStore();
|
||||
|
||||
long getId();
|
||||
|
||||
VolumeDiskType getDiskType();
|
||||
|
||||
String getPath();
|
||||
|
||||
String getUuid();
|
||||
|
||||
boolean stateTransit(TemplateEvent e) throws NoTransitionException;
|
||||
}
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image;
|
||||
|
||||
public enum TemplateState {
|
||||
Allocated,
|
||||
Creating,
|
||||
Destroying,
|
||||
Destroyed,
|
||||
Ready;
|
||||
}
|
||||
@ -16,19 +16,20 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.datastore.configurator.validator;
|
||||
package org.apache.cloudstack.storage.image.datastore;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
|
||||
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
|
||||
import org.apache.cloudstack.storage.to.VolumeTO;
|
||||
import org.apache.cloudstack.storage.image.TemplateInfo;
|
||||
import org.apache.cloudstack.storage.snapshot.SnapshotInfo;
|
||||
|
||||
public interface StorageProtocolTransformer {
|
||||
public boolean normalizeUserInput(Map<String, String> params);
|
||||
public PrimaryDataStoreTO getDataStoreTO(PrimaryDataStoreInfo dataStore);
|
||||
public VolumeTO getVolumeTO(VolumeInfo volume);
|
||||
public List<String> getInputParamNames();
|
||||
public interface ImageDataStore extends DataStore {
|
||||
TemplateInfo getTemplate(long templateId);
|
||||
VolumeInfo getVolume(long volumeId);
|
||||
SnapshotInfo getSnapshot(long snapshotId);
|
||||
boolean exists(DataObject object);
|
||||
Set<TemplateInfo> listTemplates();
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.utils.exception.CloudRuntimeException;
|
||||
|
||||
@Component
|
||||
public class ImageDataStoreHelper {
|
||||
@Inject
|
||||
ImageDataStoreDao imageStoreDao;
|
||||
public ImageDataStoreVO createImageDataStore(Map<String, String> params) {
|
||||
ImageDataStoreVO store = new ImageDataStoreVO();
|
||||
store.setName(params.get("name"));
|
||||
store.setProtocol(params.get("protocol"));
|
||||
store.setProvider(Long.parseLong(params.get("provider")));
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -16,12 +16,11 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image.store;
|
||||
package org.apache.cloudstack.storage.image.datastore;
|
||||
|
||||
import org.apache.cloudstack.storage.datastore.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
|
||||
public interface ImageDataStoreInfo extends DataStore {
|
||||
public long getImageDataStoreId();
|
||||
public String getType();
|
||||
public String getUri();
|
||||
}
|
||||
@ -16,10 +16,11 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.cloudstack.storage.image.manager;
|
||||
package org.apache.cloudstack.storage.image.datastore;
|
||||
|
||||
import org.apache.cloudstack.storage.image.store.ImageDataStore;
|
||||
import org.apache.cloudstack.storage.image.ImageDataStoreDriver;
|
||||
|
||||
public interface ImageDataStoreManager {
|
||||
ImageDataStore getImageDataStore(long dataStoreId);
|
||||
boolean registerDriver(String uuid, ImageDataStoreDriver driver);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user