use of org.apache.cloudstack.storage.command.StorageSubSystemCommand in project cloudstack by apache.
the class XenServerGuru method getCommandHostDelegation.
@Override
public Pair<Boolean, Long> getCommandHostDelegation(long hostId, Command cmd) {
if (cmd instanceof StorageSubSystemCommand) {
StorageSubSystemCommand c = (StorageSubSystemCommand) cmd;
c.setExecuteInSequence(true);
}
boolean isCopyCommand = cmd instanceof CopyCommand;
Pair<Boolean, Long> defaultHostToExecuteCommands = super.getCommandHostDelegation(hostId, cmd);
if (!isCopyCommand) {
logger.debug("We are returning the default host to execute commands because the command is not of Copy type.");
return defaultHostToExecuteCommands;
}
CopyCommand copyCommand = (CopyCommand) cmd;
DataTO srcData = copyCommand.getSrcTO();
DataTO destData = copyCommand.getDestTO();
boolean isSourceDataHypervisorXenServer = srcData.getHypervisorType() == HypervisorType.XenServer;
if (!isSourceDataHypervisorXenServer) {
logger.debug("We are returning the default host to execute commands because the target hypervisor of the source data is not XenServer.");
return defaultHostToExecuteCommands;
}
DataStoreTO srcStore = srcData.getDataStore();
DataStoreTO destStore = destData.getDataStore();
boolean isSourceAndDestinationNfsObjects = srcStore instanceof NfsTO && destStore instanceof NfsTO;
if (!isSourceAndDestinationNfsObjects) {
logger.debug("We are returning the default host to execute commands because the source and destination objects are not NFS type.");
return defaultHostToExecuteCommands;
}
boolean isSourceObjectSnapshotTypeAndDestinationObjectTemplateType = srcData.getObjectType() == DataObjectType.SNAPSHOT && destData.getObjectType() == DataObjectType.TEMPLATE;
if (!isSourceObjectSnapshotTypeAndDestinationObjectTemplateType) {
logger.debug("We are returning the default host to execute commands because the source and destination objects are not snapshot and template respectively.");
return defaultHostToExecuteCommands;
}
HostVO defaultHostToExecuteCommand = hostDao.findById(hostId);
HostVO hostCandidateToExecutedCommand = hostDao.findHostInZoneToExecuteCommand(defaultHostToExecuteCommand.getDataCenterId(), srcData.getHypervisorType());
hostDao.loadDetails(hostCandidateToExecutedCommand);
String hypervisorVersion = hostCandidateToExecutedCommand.getHypervisorVersion();
if (StringUtils.isBlank(hypervisorVersion)) {
logger.debug("We are returning the default host to execute commands because the hypervisor version is blank.");
return defaultHostToExecuteCommands;
}
boolean isXenServer610 = StringUtils.equals(hypervisorVersion, "6.1.0");
if (isXenServer610) {
logger.debug("We are returning the default host to execute commands because the hypervisor version is 6.1.0.");
return defaultHostToExecuteCommands;
}
String snapshotHotFixVersion = hostCandidateToExecutedCommand.getDetail(XenserverConfigs.XS620HotFix);
boolean isXenServer620 = StringUtils.equals(hypervisorVersion, "6.2.0");
if (isXenServer620 && !StringUtils.equalsIgnoreCase(XenserverConfigs.XSHotFix62ESP1004, snapshotHotFixVersion)) {
logger.debug(String.format("We are returning the default host to execute commands because the hypervisor version is not 6.2.0 with hotfix ESP1004 [hypervisorVersion=%s, hotfixVersion=%s]", hypervisorVersion, snapshotHotFixVersion));
return defaultHostToExecuteCommands;
}
logger.debug(String.format("We are changing the hostId to executed command from %d to %d.", hostId, hostCandidateToExecutedCommand.getId()));
return new Pair<Boolean, Long>(Boolean.TRUE, new Long(hostCandidateToExecutedCommand.getId()));
}
use of org.apache.cloudstack.storage.command.StorageSubSystemCommand in project cloudstack by apache.
the class VmwareSecondaryStorageResourceHandler method executeRequest.
@Override
public Answer executeRequest(Command cmd) {
try {
Answer answer;
NDC.push(getCommandLogTitle(cmd));
logCommand(cmd);
if (cmd instanceof PrimaryStorageDownloadCommand) {
answer = execute((PrimaryStorageDownloadCommand) cmd);
} else if (cmd instanceof BackupSnapshotCommand) {
answer = execute((BackupSnapshotCommand) cmd);
} else if (cmd instanceof CreatePrivateTemplateFromVolumeCommand) {
answer = execute((CreatePrivateTemplateFromVolumeCommand) cmd);
} else if (cmd instanceof CreatePrivateTemplateFromSnapshotCommand) {
answer = execute((CreatePrivateTemplateFromSnapshotCommand) cmd);
} else if (cmd instanceof CopyVolumeCommand) {
answer = execute((CopyVolumeCommand) cmd);
} else if (cmd instanceof CreateVolumeFromSnapshotCommand) {
answer = execute((CreateVolumeFromSnapshotCommand) cmd);
} else if (cmd instanceof StorageSubSystemCommand) {
answer = storageSubsystemHandler.handleStorageCommands((StorageSubSystemCommand) cmd);
} else if (cmd instanceof CreateEntityDownloadURLCommand) {
answer = execute((CreateEntityDownloadURLCommand) cmd);
} else {
answer = _resource.defaultAction(cmd);
}
// special handling to pass-back context info for cleanups
if (cmd.getContextParam("execid") != null) {
answer.setContextParam("execid", cmd.getContextParam("execid"));
}
if (cmd.getContextParam("checkpoint") != null) {
answer.setContextParam("checkpoint", cmd.getContextParam("checkpoint"));
}
if (cmd.getContextParam("checkpoint2") != null) {
answer.setContextParam("checkpoint2", cmd.getContextParam("checkpoint2"));
}
if (s_logger.isDebugEnabled())
s_logger.debug("Command execution answer: " + _gson.toJson(answer));
return answer;
} finally {
if (s_logger.isDebugEnabled())
s_logger.debug("Done executing " + _gson.toJson(cmd));
recycleServiceContext();
NDC.pop();
}
}
use of org.apache.cloudstack.storage.command.StorageSubSystemCommand in project cloudstack by apache.
the class KVMGuru method getCommandHostDelegation.
@Override
public Pair<Boolean, Long> getCommandHostDelegation(long hostId, Command cmd) {
if (cmd instanceof StorageSubSystemCommand) {
StorageSubSystemCommand c = (StorageSubSystemCommand) cmd;
c.setExecuteInSequence(false);
}
if (cmd instanceof CopyCommand) {
CopyCommand c = (CopyCommand) cmd;
boolean inSeq = true;
if (c.getSrcTO().getObjectType() == DataObjectType.SNAPSHOT || c.getDestTO().getObjectType() == DataObjectType.SNAPSHOT) {
inSeq = false;
} else if (c.getDestTO().getDataStore().getRole() == DataStoreRole.Image || c.getDestTO().getDataStore().getRole() == DataStoreRole.ImageCache) {
inSeq = false;
}
c.setExecuteInSequence(inSeq);
if (c.getSrcTO().getHypervisorType() == HypervisorType.KVM) {
return new Pair<>(true, hostId);
}
}
return new Pair<>(false, hostId);
}
use of org.apache.cloudstack.storage.command.StorageSubSystemCommand in project cloudstack by apache.
the class VmwareResource method executeRequest.
@Override
public Answer executeRequest(Command cmd) {
logCommand(cmd);
Answer answer = null;
NDC.push(getCommandLogTitle(cmd));
try {
long cmdSequence = _cmdSequence++;
Date startTime = DateUtil.currentGMTTime();
PropertyMapDynamicBean mbean = new PropertyMapDynamicBean();
mbean.addProp("StartTime", DateUtil.getDateDisplayString(TimeZone.getDefault(), startTime));
mbean.addProp("Command", _gson.toJson(cmd));
mbean.addProp("Sequence", String.valueOf(cmdSequence));
mbean.addProp("Name", cmd.getClass().getSimpleName());
Class<? extends Command> clz = cmd.getClass();
if (cmd instanceof NetworkElementCommand) {
return _vrResource.executeRequest((NetworkElementCommand) cmd);
} else if (clz == ReadyCommand.class) {
answer = execute((ReadyCommand) cmd);
} else if (clz == GetHostStatsCommand.class) {
answer = execute((GetHostStatsCommand) cmd);
} else if (clz == GetVmStatsCommand.class) {
answer = execute((GetVmStatsCommand) cmd);
} else if (clz == GetVmNetworkStatsCommand.class) {
answer = execute((GetVmNetworkStatsCommand) cmd);
} else if (clz == GetVmDiskStatsCommand.class) {
answer = execute((GetVmDiskStatsCommand) cmd);
} else if (cmd instanceof GetVolumeStatsCommand) {
return execute((GetVolumeStatsCommand) cmd);
} else if (clz == CheckHealthCommand.class) {
answer = execute((CheckHealthCommand) cmd);
} else if (clz == StopCommand.class) {
answer = execute((StopCommand) cmd);
} else if (clz == RebootRouterCommand.class) {
answer = execute((RebootRouterCommand) cmd);
} else if (clz == RebootCommand.class) {
answer = execute((RebootCommand) cmd);
} else if (clz == CheckVirtualMachineCommand.class) {
answer = execute((CheckVirtualMachineCommand) cmd);
} else if (clz == PrepareForMigrationCommand.class) {
answer = execute((PrepareForMigrationCommand) cmd);
} else if (clz == MigrateCommand.class) {
answer = execute((MigrateCommand) cmd);
} else if (clz == MigrateVmToPoolCommand.class) {
answer = execute((MigrateVmToPoolCommand) cmd);
} else if (clz == MigrateWithStorageCommand.class) {
answer = execute((MigrateWithStorageCommand) cmd);
} else if (clz == MigrateVolumeCommand.class) {
answer = execute((MigrateVolumeCommand) cmd);
} else if (clz == DestroyCommand.class) {
answer = execute((DestroyCommand) cmd);
} else if (clz == CreateStoragePoolCommand.class) {
return execute((CreateStoragePoolCommand) cmd);
} else if (clz == ModifyTargetsCommand.class) {
answer = execute((ModifyTargetsCommand) cmd);
} else if (clz == ModifyStoragePoolCommand.class) {
answer = execute((ModifyStoragePoolCommand) cmd);
} else if (clz == GetStoragePoolCapabilitiesCommand.class) {
answer = execute((GetStoragePoolCapabilitiesCommand) cmd);
} else if (clz == DeleteStoragePoolCommand.class) {
answer = execute((DeleteStoragePoolCommand) cmd);
} else if (clz == CopyVolumeCommand.class) {
answer = execute((CopyVolumeCommand) cmd);
} else if (clz == AttachIsoCommand.class) {
answer = execute((AttachIsoCommand) cmd);
} else if (clz == ValidateSnapshotCommand.class) {
answer = execute((ValidateSnapshotCommand) cmd);
} else if (clz == ManageSnapshotCommand.class) {
answer = execute((ManageSnapshotCommand) cmd);
} else if (clz == BackupSnapshotCommand.class) {
answer = execute((BackupSnapshotCommand) cmd);
} else if (clz == CreateVolumeFromSnapshotCommand.class) {
answer = execute((CreateVolumeFromSnapshotCommand) cmd);
} else if (clz == CreatePrivateTemplateFromVolumeCommand.class) {
answer = execute((CreatePrivateTemplateFromVolumeCommand) cmd);
} else if (clz == CreatePrivateTemplateFromSnapshotCommand.class) {
answer = execute((CreatePrivateTemplateFromSnapshotCommand) cmd);
} else if (clz == UpgradeSnapshotCommand.class) {
answer = execute((UpgradeSnapshotCommand) cmd);
} else if (clz == GetStorageStatsCommand.class) {
answer = execute((GetStorageStatsCommand) cmd);
} else if (clz == PrimaryStorageDownloadCommand.class) {
answer = execute((PrimaryStorageDownloadCommand) cmd);
} else if (clz == GetVncPortCommand.class) {
answer = execute((GetVncPortCommand) cmd);
} else if (clz == SetupCommand.class) {
answer = execute((SetupCommand) cmd);
} else if (clz == MaintainCommand.class) {
answer = execute((MaintainCommand) cmd);
} else if (clz == PingTestCommand.class) {
answer = execute((PingTestCommand) cmd);
} else if (clz == CheckOnHostCommand.class) {
answer = execute((CheckOnHostCommand) cmd);
} else if (clz == ModifySshKeysCommand.class) {
answer = execute((ModifySshKeysCommand) cmd);
} else if (clz == NetworkUsageCommand.class) {
answer = execute((NetworkUsageCommand) cmd);
} else if (clz == StartCommand.class) {
answer = execute((StartCommand) cmd);
} else if (clz == CheckSshCommand.class) {
answer = execute((CheckSshCommand) cmd);
} else if (clz == CheckNetworkCommand.class) {
answer = execute((CheckNetworkCommand) cmd);
} else if (clz == PlugNicCommand.class) {
answer = execute((PlugNicCommand) cmd);
} else if (clz == ReplugNicCommand.class) {
answer = execute((ReplugNicCommand) cmd);
} else if (clz == UnPlugNicCommand.class) {
answer = execute((UnPlugNicCommand) cmd);
} else if (cmd instanceof CreateVMSnapshotCommand) {
return execute((CreateVMSnapshotCommand) cmd);
} else if (cmd instanceof DeleteVMSnapshotCommand) {
return execute((DeleteVMSnapshotCommand) cmd);
} else if (cmd instanceof RevertToVMSnapshotCommand) {
return execute((RevertToVMSnapshotCommand) cmd);
} else if (clz == ResizeVolumeCommand.class) {
return execute((ResizeVolumeCommand) cmd);
} else if (clz == UnregisterVMCommand.class) {
return execute((UnregisterVMCommand) cmd);
} else if (cmd instanceof StorageSubSystemCommand) {
checkStorageProcessorAndHandlerNfsVersionAttribute((StorageSubSystemCommand) cmd);
return storageHandler.handleStorageCommands((StorageSubSystemCommand) cmd);
} else if (clz == ScaleVmCommand.class) {
return execute((ScaleVmCommand) cmd);
} else if (clz == PvlanSetupCommand.class) {
return execute((PvlanSetupCommand) cmd);
} else if (clz == GetVmIpAddressCommand.class) {
return execute((GetVmIpAddressCommand) cmd);
} else if (clz == UnregisterNicCommand.class) {
answer = execute((UnregisterNicCommand) cmd);
} else if (clz == GetUnmanagedInstancesCommand.class) {
answer = execute((GetUnmanagedInstancesCommand) cmd);
} else if (clz == PrepareUnmanageVMInstanceCommand.class) {
answer = execute((PrepareUnmanageVMInstanceCommand) cmd);
} else if (clz == ValidateVcenterDetailsCommand.class) {
answer = execute((ValidateVcenterDetailsCommand) cmd);
} else if (clz == SetupPersistentNetworkCommand.class) {
answer = execute((SetupPersistentNetworkCommand) cmd);
} else if (clz == GetVmVncTicketCommand.class) {
answer = execute((GetVmVncTicketCommand) cmd);
} else {
answer = Answer.createUnsupportedCommandAnswer(cmd);
}
if (cmd.getContextParam("checkpoint") != null) {
answer.setContextParam("checkpoint", cmd.getContextParam("checkpoint"));
}
Date doneTime = DateUtil.currentGMTTime();
mbean.addProp("DoneTime", DateUtil.getDateDisplayString(TimeZone.getDefault(), doneTime));
mbean.addProp("Answer", _gson.toJson(answer));
synchronized (this) {
try {
JmxUtil.registerMBean("VMware " + _morHyperHost.getValue(), "Command " + cmdSequence + "-" + cmd.getClass().getSimpleName(), mbean);
_cmdMBeans.add(mbean);
if (_cmdMBeans.size() >= MazCmdMBean) {
PropertyMapDynamicBean mbeanToRemove = _cmdMBeans.get(0);
_cmdMBeans.remove(0);
JmxUtil.unregisterMBean("VMware " + _morHyperHost.getValue(), "Command " + mbeanToRemove.getProp("Sequence") + "-" + mbeanToRemove.getProp("Name"));
}
} catch (Exception e) {
if (s_logger.isTraceEnabled())
s_logger.trace("Unable to register JMX monitoring due to exception " + ExceptionUtil.toString(e));
}
}
} finally {
recycleServiceContext();
NDC.pop();
}
if (s_logger.isTraceEnabled())
s_logger.trace("End executeRequest(), cmd: " + cmd.getClass().getSimpleName());
return answer;
}
use of org.apache.cloudstack.storage.command.StorageSubSystemCommand in project cloudstack by apache.
the class XenServerGuruTest method getCommandHostDelegationTestCommanIsStorageSubSystemCommand.
@Test
public void getCommandHostDelegationTestCommanIsStorageSubSystemCommand() {
StorageSubSystemCommand storageSubSystemCommandMock = Mockito.mock(StorageSubSystemCommand.class);
Pair<Boolean, Long> pairHostToExecuteCommand = xenServerGuru.getCommandHostDelegation(defaultHostId, storageSubSystemCommandMock);
assertPairOfHostToExecuteCommandIsTheDefaultHostId(pairHostToExecuteCommand);
Mockito.verify(storageSubSystemCommandMock).setExecuteInSequence(true);
}
Aggregations