Don't use cast to PrimarydataStoreTO on the resource code

This commit is contained in:
Edison Su 2013-11-01 15:13:16 -07:00
parent b6576d7c98
commit 7c99b88926
13 changed files with 41 additions and 38 deletions

View File

@ -21,6 +21,7 @@ package com.cloud.agent.api.to;
import com.cloud.storage.DataStoreRole; import com.cloud.storage.DataStoreRole;
public interface DataStoreTO { public interface DataStoreTO {
public DataStoreRole getRole(); DataStoreRole getRole();
public String getUuid(); String getUuid();
String getUrl();
} }

View File

@ -39,6 +39,7 @@ public class NfsTO implements DataStoreTO {
} }
@Override
public String getUrl() { public String getUrl() {
return _url; return _url;
} }

View File

@ -83,6 +83,11 @@ public class ImageStoreTO implements DataStoreTO {
return uuid; return uuid;
} }
@Override
public String getUrl() {
return getUri();
}
public void setUuid(String uuid) { public void setUuid(String uuid) {
this.uuid = uuid; this.uuid = uuid;
} }

View File

@ -16,6 +16,7 @@
// under the License. // under the License.
package org.apache.cloudstack.storage.to; package org.apache.cloudstack.storage.to;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo; import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreInfo;
import com.cloud.agent.api.to.DataStoreTO; import com.cloud.agent.api.to.DataStoreTO;
@ -31,8 +32,9 @@ public class PrimaryDataStoreTO implements DataStoreTO {
private String host; private String host;
private String path; private String path;
private int port; private int port;
private final String url;
public PrimaryDataStoreTO(PrimaryDataStoreInfo dataStore) { public PrimaryDataStoreTO(PrimaryDataStore dataStore) {
this.uuid = dataStore.getUuid(); this.uuid = dataStore.getUuid();
this.name = dataStore.getName(); this.name = dataStore.getName();
this.id = dataStore.getId(); this.id = dataStore.getId();
@ -40,6 +42,7 @@ public class PrimaryDataStoreTO implements DataStoreTO {
this.setHost(dataStore.getHostAddress()); this.setHost(dataStore.getHostAddress());
this.setPath(dataStore.getPath()); this.setPath(dataStore.getPath());
this.setPort(dataStore.getPort()); this.setPort(dataStore.getPort());
this.url = dataStore.getUri();
} }
public long getId() { public long getId() {
@ -51,6 +54,11 @@ public class PrimaryDataStoreTO implements DataStoreTO {
return this.uuid; return this.uuid;
} }
@Override
public String getUrl() {
return this.url;
}
public String getName() { public String getName() {
return this.name; return this.name;
} }

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
package org.apache.cloudstack.storage.datastore; package org.apache.cloudstack.engine.subsystem.api.storage;
import java.util.List; import java.util.List;

View File

@ -40,7 +40,7 @@ import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
import org.apache.cloudstack.framework.async.AsyncRpcContext; import org.apache.cloudstack.framework.async.AsyncRpcContext;
import org.apache.cloudstack.storage.command.CommandResult; import org.apache.cloudstack.storage.command.CommandResult;
import org.apache.cloudstack.storage.command.CopyCmdAnswer; import org.apache.cloudstack.storage.command.CopyCmdAnswer;
import org.apache.cloudstack.storage.datastore.PrimaryDataStore; import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao; import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO; import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreVO;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;

View File

@ -19,6 +19,7 @@
package org.apache.cloudstack.storage.datastore; package org.apache.cloudstack.storage.datastore;
import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener; import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver; import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver;
public interface PrimaryDataStoreProviderManager { public interface PrimaryDataStoreProviderManager {

View File

@ -19,7 +19,7 @@
package org.apache.cloudstack.storage.volume; package org.apache.cloudstack.storage.volume;
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo; import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
import org.apache.cloudstack.storage.datastore.PrimaryDataStore; import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
public interface TemplateOnPrimaryDataStoreInfo { public interface TemplateOnPrimaryDataStoreInfo {
public String getPath(); public String getPath();

View File

@ -103,7 +103,7 @@
</display> </display>
</class> </class>
<interface id="9" corner="BOTTOM_RIGHT" language="java" <interface id="9" corner="BOTTOM_RIGHT" language="java"
name="org.apache.cloudstack.storage.datastore.PrimaryDataStore" project="cloud-engine-storage" name="org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore" project="cloud-engine-storage"
file="/cloud-engine-storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStore.java" binary="false"> file="/cloud-engine-storage/src/org/apache/cloudstack/storage/datastore/PrimaryDataStore.java" binary="false">
<position height="-1" width="-1" x="770" y="-4"/> <position height="-1" width="-1" x="770" y="-4"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" visibility="true"> <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" visibility="true">

View File

@ -23,23 +23,9 @@ import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import org.apache.cloudstack.engine.subsystem.api.storage.*;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.cloudstack.engine.subsystem.api.storage.ClusterScope;
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.DataStoreProvider;
import org.apache.cloudstack.engine.subsystem.api.storage.HostScope;
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCycle;
import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotDataFactory;
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateDataFactory;
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.ZoneScope;
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.DiskFormat; import org.apache.cloudstack.engine.subsystem.api.storage.disktype.DiskFormat;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;

View File

@ -29,7 +29,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProviderManag
import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener; import org.apache.cloudstack.engine.subsystem.api.storage.HypervisorHostListener;
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver; import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver;
import org.apache.cloudstack.storage.datastore.PrimaryDataStoreImpl; import org.apache.cloudstack.storage.datastore.PrimaryDataStoreImpl;
import org.apache.cloudstack.storage.datastore.PrimaryDataStore; import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
import org.apache.cloudstack.storage.datastore.PrimaryDataStoreProviderManager; import org.apache.cloudstack.storage.datastore.PrimaryDataStoreProviderManager;
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;

View File

@ -76,7 +76,7 @@ import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
import org.apache.cloudstack.storage.command.CommandResult; import org.apache.cloudstack.storage.command.CommandResult;
import org.apache.cloudstack.storage.command.CopyCmdAnswer; import org.apache.cloudstack.storage.command.CopyCmdAnswer;
import org.apache.cloudstack.storage.command.DeleteCommand; import org.apache.cloudstack.storage.command.DeleteCommand;
import org.apache.cloudstack.storage.datastore.PrimaryDataStore; import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore;
import org.apache.cloudstack.storage.datastore.PrimaryDataStoreProviderManager; import org.apache.cloudstack.storage.datastore.PrimaryDataStoreProviderManager;
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao; import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO; import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;

View File

@ -37,7 +37,6 @@ import org.apache.cloudstack.storage.command.DeleteCommand;
import org.apache.cloudstack.storage.command.DettachCommand; import org.apache.cloudstack.storage.command.DettachCommand;
import org.apache.cloudstack.storage.command.ForgetObjectCmd; import org.apache.cloudstack.storage.command.ForgetObjectCmd;
import org.apache.cloudstack.storage.command.IntroduceObjectCmd; import org.apache.cloudstack.storage.command.IntroduceObjectCmd;
import org.apache.cloudstack.storage.to.PrimaryDataStoreTO;
import org.apache.cloudstack.storage.to.SnapshotObjectTO; import org.apache.cloudstack.storage.to.SnapshotObjectTO;
import org.apache.cloudstack.storage.to.TemplateObjectTO; import org.apache.cloudstack.storage.to.TemplateObjectTO;
import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.cloudstack.storage.to.VolumeObjectTO;
@ -194,7 +193,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
NfsTO nfsImageStore = (NfsTO)srcStore; NfsTO nfsImageStore = (NfsTO)srcStore;
DataTO destData = cmd.getDestTO(); DataTO destData = cmd.getDestTO();
DataStoreTO destStore = destData.getDataStore(); DataStoreTO destStore = destData.getDataStore();
PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)destStore; DataStoreTO primaryStore = destStore;
String secondaryStorageUrl = nfsImageStore.getUrl(); String secondaryStorageUrl = nfsImageStore.getUrl();
assert (secondaryStorageUrl != null); assert (secondaryStorageUrl != null);
@ -310,8 +309,8 @@ public class VmwareStorageProcessor implements StorageProcessor {
TemplateObjectTO template = (TemplateObjectTO)srcData; TemplateObjectTO template = (TemplateObjectTO)srcData;
DataTO destData = cmd.getDestTO(); DataTO destData = cmd.getDestTO();
VolumeObjectTO volume = (VolumeObjectTO)destData; VolumeObjectTO volume = (VolumeObjectTO)destData;
PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)volume.getDataStore(); DataStoreTO primaryStore = volume.getDataStore();
PrimaryDataStoreTO srcStore = (PrimaryDataStoreTO)template.getDataStore(); DataStoreTO srcStore = template.getDataStore();
try { try {
VmwareContext context = hostService.getServiceContext(null); VmwareContext context = hostService.getServiceContext(null);
@ -450,20 +449,22 @@ public class VmwareStorageProcessor implements StorageProcessor {
try { try {
NfsTO srcStore = (NfsTO)srcVolume.getDataStore(); NfsTO srcStore = (NfsTO)srcVolume.getDataStore();
PrimaryDataStoreTO destStore = (PrimaryDataStoreTO)destVolume.getDataStore(); DataStoreTO destStore = destVolume.getDataStore();
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd); VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd);
String uuid = destStore.getUuid(); String uuid = destStore.getUuid();
ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, uuid); ManagedObjectReference morDatastore = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, uuid);
if (morDatastore == null) { if (morDatastore == null) {
URI uri = new URI(destStore.getUrl());
morDatastore = hyperHost.mountDatastore( morDatastore = hyperHost.mountDatastore(
false, false,
destStore.getHost(), 0, destStore.getPath(), uri.getHost(), 0, uri.getPath(),
destStore.getUuid().replace("-", "")); destStore.getUuid().replace("-", ""));
if (morDatastore == null) { if (morDatastore == null) {
throw new Exception("Unable to mount storage pool on host. storeUrl: " + destStore.getHost() + ":/" + destStore.getPath()); throw new Exception("Unable to mount storage pool on host. storeUrl: " + uri.getHost() + ":/" + uri.getPath());
} }
} }
@ -551,7 +552,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
VmwareContext context = hostService.getServiceContext(cmd); VmwareContext context = hostService.getServiceContext(cmd);
try { try {
PrimaryDataStoreTO primaryStorage = (PrimaryDataStoreTO)srcVolume.getDataStore(); DataStoreTO primaryStorage = srcVolume.getDataStore();
NfsTO destStore = (NfsTO)destVolume.getDataStore(); NfsTO destStore = (NfsTO)destVolume.getDataStore();
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd); VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, cmd);
@ -998,7 +999,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
@Override @Override
public Answer backupSnapshot(CopyCommand cmd) { public Answer backupSnapshot(CopyCommand cmd) {
SnapshotObjectTO srcSnapshot = (SnapshotObjectTO)cmd.getSrcTO(); SnapshotObjectTO srcSnapshot = (SnapshotObjectTO)cmd.getSrcTO();
PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)srcSnapshot.getDataStore(); DataStoreTO primaryStore = srcSnapshot.getDataStore();
SnapshotObjectTO destSnapshot = (SnapshotObjectTO)cmd.getDestTO(); SnapshotObjectTO destSnapshot = (SnapshotObjectTO)cmd.getDestTO();
DataStoreTO destStore = destSnapshot.getDataStore(); DataStoreTO destStore = destSnapshot.getDataStore();
if (!(destStore instanceof NfsTO)) { if (!(destStore instanceof NfsTO)) {
@ -1180,7 +1181,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
private Answer attachVolume(Command cmd, DiskTO disk, boolean isAttach, boolean isManaged, String vmName, String iScsiName, String storageHost, int storagePort) { private Answer attachVolume(Command cmd, DiskTO disk, boolean isAttach, boolean isManaged, String vmName, String iScsiName, String storageHost, int storagePort) {
VolumeObjectTO volumeTO = (VolumeObjectTO)disk.getData(); VolumeObjectTO volumeTO = (VolumeObjectTO)disk.getData();
PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)volumeTO.getDataStore(); DataStoreTO primaryStore = volumeTO.getDataStore();
try { try {
VmwareHypervisorHost hyperHost = hostService.getHyperHost(hostService.getServiceContext(null), null); VmwareHypervisorHost hyperHost = hostService.getHyperHost(hostService.getServiceContext(null), null);
VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName); VirtualMachineMO vmMo = hyperHost.findVmOnHyperHost(vmName);
@ -1382,7 +1383,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
public Answer createVolume(CreateObjectCommand cmd) { public Answer createVolume(CreateObjectCommand cmd) {
VolumeObjectTO volume = (VolumeObjectTO)cmd.getData(); VolumeObjectTO volume = (VolumeObjectTO)cmd.getData();
PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO)volume.getDataStore(); DataStoreTO primaryStore = volume.getDataStore();
try { try {
VmwareContext context = hostService.getServiceContext(null); VmwareContext context = hostService.getServiceContext(null);
@ -1459,11 +1460,11 @@ public class VmwareStorageProcessor implements StorageProcessor {
VmwareContext context = hostService.getServiceContext(null); VmwareContext context = hostService.getServiceContext(null);
VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, null); VmwareHypervisorHost hyperHost = hostService.getHyperHost(context, null);
VolumeObjectTO vol = (VolumeObjectTO)cmd.getData(); VolumeObjectTO vol = (VolumeObjectTO)cmd.getData();
PrimaryDataStoreTO store = (PrimaryDataStoreTO)vol.getDataStore(); DataStoreTO store = vol.getDataStore();
ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, store.getUuid()); ManagedObjectReference morDs = HypervisorHostHelper.findDatastoreWithBackwardsCompatibility(hyperHost, store.getUuid());
if (morDs == null) { if (morDs == null) {
String msg = "Unable to find datastore based on volume mount point " + store.getPath(); String msg = "Unable to find datastore based on volume mount point " + store.getUuid();
s_logger.error(msg); s_logger.error(msg);
throw new Exception(msg); throw new Exception(msg);
} }
@ -1674,7 +1675,7 @@ public class VmwareStorageProcessor implements StorageProcessor {
DataTO srcData = cmd.getSrcTO(); DataTO srcData = cmd.getSrcTO();
SnapshotObjectTO snapshot = (SnapshotObjectTO)srcData; SnapshotObjectTO snapshot = (SnapshotObjectTO)srcData;
DataTO destData = cmd.getDestTO(); DataTO destData = cmd.getDestTO();
PrimaryDataStoreTO pool = (PrimaryDataStoreTO)destData.getDataStore(); DataStoreTO pool = destData.getDataStore();
DataStoreTO imageStore = srcData.getDataStore(); DataStoreTO imageStore = srcData.getDataStore();