use of com.emc.storageos.computesystemcontroller.ComputeSystemController in project coprhd-controller by CoprHD.
the class HostService method updateBootVolume.
/**
* Updates the hosts boot volume Id
*
* @param id the URN of host
* @param hostUpdateParam
* @brief Update the host boot volume
* @return the task.
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
@Path("/{id}/update-boot-volume")
public TaskResourceRep updateBootVolume(@PathParam("id") URI id, HostUpdateParam param) {
Host host = queryObject(Host.class, id, true);
boolean hasPendingTasks = hostHasPendingTasks(id);
boolean updateSanBootTargets = param.getUpdateSanBootTargets();
if (hasPendingTasks) {
throw APIException.badRequests.cannotUpdateHost("another operation is in progress for this host");
}
auditOp(OperationTypeEnum.UPDATE_HOST_BOOT_VOLUME, true, null, host.auditParameters());
String taskId = UUID.randomUUID().toString();
ComputeSystemController controller = getController(ComputeSystemController.class, null);
Operation op = _dbClient.createTaskOpStatus(Host.class, id, taskId, ResourceOperationTypeEnum.UPDATE_HOST_BOOT_VOLUME);
// The volume being set as the boot volume should be exported to the host and should not be exported to any other initiators.
// The controller call invoked below validates that before setting the volume as the boot volume.
controller.setHostBootVolume(host.getId(), param.getBootVolume(), updateSanBootTargets, taskId);
return toTask(host, taskId, op);
}
use of com.emc.storageos.computesystemcontroller.ComputeSystemController in project coprhd-controller by CoprHD.
the class HostService method createInitiator.
/**
* Creates a new initiator for a host.
*
* @param id
* the URN of a ViPR Host
* @param createParam
* the details of the initiator
* @brief Create host initiator
* @return the details of the host initiator when creation
* is successfully.
* @throws DatabaseException
* when a database error occurs.
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
@Path("/{id}/initiators")
public TaskResourceRep createInitiator(@PathParam("id") URI id, InitiatorCreateParam createParam) throws DatabaseException {
Host host = queryObject(Host.class, id, true);
Cluster cluster = null;
validateInitiatorData(createParam, null);
// create and populate the initiator
Initiator initiator = new Initiator();
initiator.setHost(id);
initiator.setHostName(host.getHostName());
if (!NullColumnValueGetter.isNullURI(host.getCluster())) {
cluster = queryObject(Cluster.class, host.getCluster(), false);
initiator.setClusterName(cluster.getLabel());
}
initiator.setId(URIUtil.createId(Initiator.class));
populateInitiator(initiator, createParam);
_dbClient.createObject(initiator);
String taskId = UUID.randomUUID().toString();
Operation op = _dbClient.createTaskOpStatus(Initiator.class, initiator.getId(), taskId, ResourceOperationTypeEnum.ADD_HOST_INITIATOR);
// if host in use. update export with new initiator
if (ComputeSystemHelper.isHostInUse(_dbClient, host.getId())) {
ComputeSystemController controller = getController(ComputeSystemController.class, null);
controller.addInitiatorsToExport(initiator.getHost(), Arrays.asList(initiator.getId()), taskId);
} else {
// No updates were necessary, so we can close out the task.
_dbClient.ready(Initiator.class, initiator.getId(), taskId);
}
auditOp(OperationTypeEnum.CREATE_HOST_INITIATOR, true, null, initiator.auditParameters());
return toTask(initiator, taskId, op);
}
use of com.emc.storageos.computesystemcontroller.ComputeSystemController in project coprhd-controller by CoprHD.
the class EventService method getEventDetails.
/**
* Gets details for an event
*
* @param event the event to get details for
* @param approve if true, get the approve details, if false the get the decline details
* @return event details
*/
public List<String> getEventDetails(ActionableEvent event, boolean approve) {
byte[] method = approve ? event.getApproveMethod() : event.getDeclineMethod();
if (method == null || method.length == 0) {
_log.info("Method is null or empty for event " + event.getId());
return Lists.newArrayList("N/A");
}
ActionableEvent.Method eventMethod = ActionableEvent.Method.deserialize(method);
if (eventMethod == null) {
_log.info("Event method is null or empty for event " + event.getId());
return Lists.newArrayList("N/A");
}
String eventMethodName = eventMethod.getMethodName() + DETAILS_SUFFIX;
try {
Method classMethod = getMethod(ActionableEventExecutor.class, eventMethodName);
if (classMethod == null) {
return Lists.newArrayList("N/A");
} else {
ComputeSystemController controller = getController(ComputeSystemController.class, null);
ActionableEventExecutor executor = new ActionableEventExecutor(_dbClient, controller);
return (List<String>) classMethod.invoke(executor, eventMethod.getArgs());
}
} catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
_log.error(e.getMessage(), e.getCause());
throw APIException.badRequests.errorInvokingEventMethod(event.getId(), eventMethodName);
}
}
use of com.emc.storageos.computesystemcontroller.ComputeSystemController in project coprhd-controller by CoprHD.
the class EventService method executeEventMethod.
/**
* Executes an actionable event method
*
* @param event the event to execute
* @param approve if true, the action is to approve, if false the action is to decline
* @return list of tasks
*/
public TaskList executeEventMethod(ActionableEvent event, boolean approve) {
TaskList taskList = new TaskList();
byte[] method = approve ? event.getApproveMethod() : event.getDeclineMethod();
String eventStatus = approve ? ActionableEvent.Status.approved.name() : ActionableEvent.Status.declined.name();
event.setEventExecutionTime(Calendar.getInstance());
event.setApproveDetails(new StringSet(getEventDetails(event, true)));
event.setDeclineDetails(new StringSet(getEventDetails(event, false)));
if (method == null || method.length == 0) {
_log.info("Method is null or empty for event " + event.getId());
event.setEventStatus(eventStatus);
_dbClient.updateObject(event);
return taskList;
}
ActionableEvent.Method eventMethod = ActionableEvent.Method.deserialize(method);
if (eventMethod == null) {
_log.info("Event method is null or empty for event " + event.getId());
event.setEventStatus(eventStatus);
_dbClient.updateObject(event);
return taskList;
}
try {
Method classMethod = getMethod(ActionableEventExecutor.class, eventMethod.getMethodName());
ComputeSystemController controller = getController(ComputeSystemController.class, null);
ActionableEventExecutor executor = new ActionableEventExecutor(_dbClient, controller);
Object[] parameters = Arrays.copyOf(eventMethod.getArgs(), eventMethod.getArgs().length + 1);
parameters[parameters.length - 1] = event.getId();
event.setEventStatus(eventStatus);
_dbClient.updateObject(event);
TaskResourceRep result = (TaskResourceRep) classMethod.invoke(executor, parameters);
if (result != null && result.getId() != null) {
Collection<String> taskCollection = Lists.newArrayList(result.getId().toString());
ActionableEvent updatedEvent = _dbClient.queryObject(ActionableEvent.class, event.getId());
updatedEvent.setTaskIds(new StringSet(taskCollection));
_dbClient.updateObject(updatedEvent);
}
taskList.addTask(result);
return taskList;
} catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
_log.error(e.getMessage(), e.getCause());
throw APIException.badRequests.errorInvokingEventMethod(event.getId(), eventMethod.getMethodName());
}
}
use of com.emc.storageos.computesystemcontroller.ComputeSystemController in project coprhd-controller by CoprHD.
the class AbstractDiscoveryAdapter method removeOldHostsFromExport.
protected void removeOldHostsFromExport(URI clusterURI, List<Host> hosts) {
// update export if host is in use
if (ComputeSystemHelper.isClusterInExport(dbClient, clusterURI)) {
String taskId = UUID.randomUUID().toString();
ComputeSystemController controller = getController(ComputeSystemController.class, null);
List<URI> hostIds = Lists.newArrayList();
for (Host host : hosts) {
hostIds.add(host.getId());
}
controller.removeHostsFromExport(hostIds, clusterURI, false, NullColumnValueGetter.getNullURI(), taskId);
}
}
Aggregations