use of com.emc.storageos.volumecontroller.AsyncTask in project coprhd-controller by CoprHD.
the class ComputeControllerImpl method deactivateHost.
@Override
public void deactivateHost(AsyncTask[] tasks) throws InternalException {
AsyncTask task = tasks[0];
Host host = _dbClient.queryObject(Host.class, task._id);
if (host != null) {
if (!NullColumnValueGetter.isNullURI(host.getComputeElement())) {
ComputeElement computeElement = _dbClient.queryObject(ComputeElement.class, host.getComputeElement());
execCompute("deactivateHost", computeElement.getComputeSystem(), task._id, task._opId);
} else {
_dbClient.error(Host.class, task._id, task._opId, ComputeSystemControllerException.exceptions.noComputeElementAssociatedWithHost(host.getNativeGuid().toString(), host.getId().toString(), null));
}
}
}
use of com.emc.storageos.volumecontroller.AsyncTask in project coprhd-controller by CoprHD.
the class ComputeDeviceControllerImpl method removeHostFromVcenterCluster.
/**
* This will attempt to remove host from vCenter cluster.
*
* @param hostId
* @param stepId
*/
public void removeHostFromVcenterCluster(URI hostId, String stepId) {
log.info("removeHostFromVcenterCluster {}", hostId);
Host host = null;
try {
WorkflowStepCompleter.stepExecuting(stepId);
host = _dbClient.queryObject(Host.class, hostId);
if (NullColumnValueGetter.isNullURI(host.getVcenterDataCenter())) {
log.info("datacenter is null, nothing to do");
WorkflowStepCompleter.stepSucceded(stepId);
return;
}
if (NullColumnValueGetter.isNullURI(host.getCluster())) {
log.warn("cluster is null, nothing to do");
WorkflowStepCompleter.stepSucceded(stepId);
return;
}
// Test mechanism to invoke a failure. No-op on production systems.
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_068);
String taskId = stepId;
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.UPDATE_VCENTER_CLUSTER);
_dbClient.createTaskOpStatus(VcenterDataCenter.class, host.getVcenterDataCenter(), taskId, op);
AsyncTask task = new AsyncTask(VcenterDataCenter.class, host.getVcenterDataCenter(), taskId);
final String workflowKey = "updateVcenterCluster";
if (!WorkflowService.getInstance().hasWorkflowBeenCreated(taskId, workflowKey)) {
vcenterController.updateVcenterCluster(task, host.getCluster(), null, new URI[] { host.getId() }, null);
// Mark this workflow as created/executed so we don't do it
// again on retry/resume
WorkflowService.getInstance().markWorkflowBeenCreated(taskId, workflowKey);
}
} catch (VcenterControllerException e) {
log.warn("VcenterControllerException when trying to removeHostFromVcenterCluster: " + e.getMessage(), e);
if (e.getCause() instanceof VcenterObjectNotFoundException) {
log.info("did not find the host, considering success");
WorkflowStepCompleter.stepSucceded(stepId);
} else if (e.getCause() instanceof VcenterObjectConnectionException) {
log.info("host is not connected, considering success");
WorkflowStepCompleter.stepSucceded(stepId);
} else {
log.error("failure " + e);
WorkflowStepCompleter.stepFailed(stepId, e);
}
} catch (InternalException e) {
log.error("InternalException when trying to removeHostFromVcenterCluster: " + e.getMessage(), e);
WorkflowStepCompleter.stepFailed(stepId, e);
} catch (Exception e) {
log.error("unexpected exception: " + e.getMessage(), e);
ServiceCoded serviceCoded = ComputeSystemControllerException.exceptions.unableToRemoveHostVcenterCluster(host != null ? host.getHostName() : hostId.toString(), e);
WorkflowStepCompleter.stepFailed(stepId, serviceCoded);
}
}
use of com.emc.storageos.volumecontroller.AsyncTask in project coprhd-controller by CoprHD.
the class VcenterDataCenterService method createOrUpdateVcenterCluster.
/*
* @param create - Whether to create a new cluster vs update an existing
*/
private TaskResourceRep createOrUpdateVcenterCluster(boolean createCluster, URI id, URI clusterId, List<URI> addHosts, List<URI> removeHosts) {
_log.info("createOrUpdateVcenterCluster " + createCluster + " " + id + " " + clusterId);
ArgValidator.checkFieldUriType(id, VcenterDataCenter.class, "id");
VcenterDataCenter vcenterDataCenter = queryObject(VcenterDataCenter.class, id, false);
ArgValidator.checkEntity(vcenterDataCenter, id, isIdEmbeddedInURL(id));
ArgValidator.checkFieldUriType(clusterId, Cluster.class, "clusterId");
Cluster cluster = queryObject(Cluster.class, clusterId, false);
ArgValidator.checkEntity(cluster, clusterId, isIdEmbeddedInURL(clusterId));
verifyAuthorizedInTenantOrg(cluster.getTenant(), getUserFromContext());
/*
* Check if explicit add host or remove hosts are specified
* If one or both are, only execute whats specified
* If nothing is specified, do automatic host selection and import all hosts in cluster
*/
Collection<URI> addHostUris = new ArrayList<URI>();
Collection<URI> removeHostUris = new ArrayList<URI>();
boolean manualHostSpecification = false;
if (addHosts != null && !addHosts.isEmpty()) {
_log.info("Request to explicitly add hosts " + addHosts);
manualHostSpecification = true;
}
if (removeHosts != null && !removeHosts.isEmpty()) {
_log.info("Request to explicitly remove hosts " + removeHosts);
manualHostSpecification = true;
}
if (manualHostSpecification) {
for (URI uri : addHosts) {
Host host = queryObject(Host.class, uri, false);
if (isHostCompatibleForVcenterCluster(host)) {
addHostUris.add(uri);
}
}
for (URI uri : removeHosts) {
Host host = queryObject(Host.class, uri, false);
if (isHostCompatibleForVcenterCluster(host)) {
removeHostUris.add(uri);
}
}
} else {
// If no hosts specified by default add all hosts within cluster
Collection<URI> hostUris = new ArrayList<URI>();
List<NamedElementQueryResultList.NamedElement> hostNamedElements = listChildren(clusterId, Host.class, "label", "cluster");
for (NamedElementQueryResultList.NamedElement hostNamedElement : hostNamedElements) {
Host host = queryObject(Host.class, hostNamedElement.getId(), false);
if (isHostCompatibleForVcenterCluster(host)) {
addHostUris.add(host.getId());
}
}
if (addHostUris.isEmpty()) {
// Require at least a single compatible host for automatic mode, do not create empty cluster
_log.error("Cluster " + cluster.getLabel() + " does not contain any ESX/ESXi hosts and is thus incompatible for vCenter operations");
throw APIException.badRequests.clusterContainsNoCompatibleHostsForVcenter();
}
}
// Find all shared volumes in the cluster
List<URI> volumeUris = new ArrayList<URI>();
try {
List<ExportGroup> exportGroups = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, ExportGroup.class, AlternateIdConstraint.Factory.getConstraint(ExportGroup.class, "clusters", cluster.getId().toString()));
_log.info("Found " + exportGroups.size() + " export groups for cluster " + cluster.getLabel());
for (ExportGroup exportGroup : exportGroups) {
_log.info("Cluster " + cluster.getLabel() + " has export group " + exportGroup.getLabel() + " of type " + exportGroup.getType());
if (exportGroup.forCluster()) {
_log.info("Export group " + exportGroup.getLabel() + " is cluster/shared type");
StringMap volumes = exportGroup.getVolumes();
_log.info("Export group " + exportGroup.getLabel() + " has " + volumes.size() + " volumes");
for (String volumeUriString : volumes.keySet()) {
_log.info("Volume URI " + volumeUriString + " found in export group " + exportGroup.getLabel());
URI uri = URI.create(volumeUriString);
volumeUris.add(uri);
}
}
}
} catch (Exception e) {
_log.error("Exception navigating cluster export groups for shared volumes " + e);
// for time being just ignore
}
Collection<Volume> volumes = _dbClient.queryObject(Volume.class, volumeUris);
for (Volume volume : volumes) {
_log.info("Volume " + volume.getLabel() + " " + volume.getWWN() + " is shared and compatible for VMFS datastore");
}
String taskId = UUID.randomUUID().toString();
Operation op = new Operation();
op.setResourceType(createCluster ? ResourceOperationTypeEnum.CREATE_VCENTER_CLUSTER : ResourceOperationTypeEnum.UPDATE_VCENTER_CLUSTER);
_dbClient.createTaskOpStatus(VcenterDataCenter.class, vcenterDataCenter.getId(), taskId, op);
AsyncTask task = new AsyncTask(VcenterDataCenter.class, vcenterDataCenter.getId(), taskId);
VcenterController vcenterController = getController(VcenterController.class, null);
if (createCluster) {
vcenterController.createVcenterCluster(task, clusterId, addHostUris.toArray(new URI[0]), volumeUris.toArray(new URI[0]));
} else {
vcenterController.updateVcenterCluster(task, clusterId, addHostUris.toArray(new URI[0]), removeHostUris.toArray(new URI[0]), volumeUris.toArray(new URI[0]));
}
auditOp(OperationTypeEnum.CREATE_UPDATE_VCENTER_CLUSTER, true, null, vcenterDataCenter.auditParameters());
return toTask(vcenterDataCenter, taskId, op);
}
use of com.emc.storageos.volumecontroller.AsyncTask in project coprhd-controller by CoprHD.
the class ProtectionSystemService method discoverProtectionSystemsAll.
/**
* Allows the user to manually discover all protection systems.
*
* @brief Discover all protection systems
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
@Path("/discover")
public TaskList discoverProtectionSystemsAll() {
Iterator<URI> protectionIter = _dbClient.queryByType(ProtectionSystem.class, true).iterator();
ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>();
while (protectionIter.hasNext()) {
URI protection = protectionIter.next();
String taskId = UUID.randomUUID().toString();
tasks.add(new AsyncTask(ProtectionSystem.class, protection, taskId));
}
ProtectionController controller = getController(RPController.class, ProtectionSystem._RP);
return discoverProtectionSystems(tasks, controller);
}
use of com.emc.storageos.volumecontroller.AsyncTask in project coprhd-controller by CoprHD.
the class ProtectionSystemService method createProtectionSystem.
/**
* Allow the user to manually create a protection system.
*
* @param param The protection system details.
*
* @brief Create protection system
* @return An asynchronous task corresponding to the discovery job scheduled for the new Protection System.
*
* @throws BadRequestException When the system type is not valid or a
* protection system with the same native guid already exists.
* @throws DatabaseException When an error occurs querying the database.
* @throws ControllerException When an error occurs discovering the protection
* system.
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep createProtectionSystem(ProtectionSystemRequestParam param) throws Exception {
ProtectionSystem system = null;
ProtectionSystem.Type systemType = ProtectionSystem.Type.valueOf(param.getSystemType());
if (!systemType.equals(ProtectionSystem.Type.rp)) {
throw APIException.badRequests.cannotRegisterSystemWithType(systemType.name());
}
system = new ProtectionSystem();
system.setId(URIUtil.createId(ProtectionSystem.class));
system.setSystemType(systemType.name());
system.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
system.setIpAddress(param.getIpAddress());
system.setPortNumber(param.getPortNumber());
system.setUsername(param.getUserName());
system.setPassword(param.getPassword());
system.setLabel(param.getLabel());
system.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.CREATED.toString());
_dbClient.createObject(system);
auditOp(OperationTypeEnum.CREATE_PROTECTION_SYSTEM, true, null, param.getLabel(), systemType.name(), param.getIpAddress(), param.getPortNumber(), param.getUserName(), system.getId().toString());
startProtectionSystem(system);
ProtectionController controller = getController(RPController.class, ProtectionSystem._RP);
ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>(1);
String taskId = UUID.randomUUID().toString();
tasks.add(new AsyncTask(ProtectionSystem.class, system.getId(), taskId));
TaskList taskList = discoverProtectionSystems(tasks, controller);
return taskList.getTaskList().listIterator().next();
}
Aggregations