Search in sources :

Example 1 with ComputeSystemController

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);
}
Also used : ComputeSystemController(com.emc.storageos.computesystemcontroller.ComputeSystemController) Host(com.emc.storageos.db.client.model.Host) Operation(com.emc.storageos.db.client.model.Operation) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 2 with ComputeSystemController

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);
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) ComputeSystemController(com.emc.storageos.computesystemcontroller.ComputeSystemController) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) Operation(com.emc.storageos.db.client.model.Operation) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 3 with ComputeSystemController

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);
    }
}
Also used : ActionableEvent(com.emc.storageos.db.client.model.ActionableEvent) ComputeSystemController(com.emc.storageos.computesystemcontroller.ComputeSystemController) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) AggregationQueryResultList(com.emc.storageos.db.client.constraint.AggregationQueryResultList) List(java.util.List) TaskList(com.emc.storageos.model.TaskList) BulkList(com.emc.storageos.api.service.impl.response.BulkList) EventList(com.emc.storageos.model.event.EventList)

Example 4 with ComputeSystemController

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());
    }
}
Also used : ActionableEvent(com.emc.storageos.db.client.model.ActionableEvent) TaskList(com.emc.storageos.model.TaskList) ComputeSystemController(com.emc.storageos.computesystemcontroller.ComputeSystemController) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) StringSet(com.emc.storageos.db.client.model.StringSet) DataObject(com.emc.storageos.db.client.model.DataObject)

Example 5 with ComputeSystemController

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);
    }
}
Also used : ComputeSystemController(com.emc.storageos.computesystemcontroller.ComputeSystemController) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI)

Aggregations

ComputeSystemController (com.emc.storageos.computesystemcontroller.ComputeSystemController)21 Path (javax.ws.rs.Path)12 Produces (javax.ws.rs.Produces)12 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)10 POST (javax.ws.rs.POST)10 Host (com.emc.storageos.db.client.model.Host)9 Operation (com.emc.storageos.db.client.model.Operation)9 URI (java.net.URI)6 Initiator (com.emc.storageos.db.client.model.Initiator)4 MapVcenter (com.emc.storageos.api.mapper.functions.MapVcenter)3 TaskList (com.emc.storageos.model.TaskList)3 ArrayList (java.util.ArrayList)3 Consumes (javax.ws.rs.Consumes)3 MapVcenterDataCenter (com.emc.storageos.api.mapper.functions.MapVcenterDataCenter)2 DiscoveredObjectTaskScheduler (com.emc.storageos.api.service.impl.resource.utils.DiscoveredObjectTaskScheduler)2 ActionableEvent (com.emc.storageos.db.client.model.ActionableEvent)2 Cluster (com.emc.storageos.db.client.model.Cluster)2 AsyncTask (com.emc.storageos.volumecontroller.AsyncTask)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2