Search in sources :

Example 16 with ComputeSystemController

use of com.emc.storageos.computesystemcontroller.ComputeSystemController in project coprhd-controller by CoprHD.

the class HostService method doDiscoverHost.

/**
 * Host Discovery
 *
 * @param host {@link Host} The Host to be discovered.
 * @param taskId {@link String} taskId for the host discovery. as new taskId is generated if null passed.
 * @param updateTaskStatus if true, mark the task status as completed for non-discovered host
 * @return the task used to track the discovery job
 */
protected TaskResourceRep doDiscoverHost(URI hostId, String taskId, boolean updateTaskStatus) {
    Host host = queryObject(Host.class, hostId, true);
    if (taskId == null) {
        taskId = UUID.randomUUID().toString();
    }
    if (host.getDiscoverable() != null && !host.getDiscoverable()) {
        host.setDiscoveryStatus(DataCollectionJobStatus.COMPLETE.name());
        _dbClient.updateObject(host);
    }
    if ((host.getDiscoverable() == null || host.getDiscoverable())) {
        ComputeSystemController controller = getController(ComputeSystemController.class, "host");
        DiscoveredObjectTaskScheduler scheduler = new DiscoveredObjectTaskScheduler(_dbClient, new DiscoverJobExec(controller));
        ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>(1);
        tasks.add(new AsyncTask(Host.class, host.getId(), taskId));
        TaskList taskList = scheduler.scheduleAsyncTasks(tasks);
        return taskList.getTaskList().iterator().next();
    } else {
        // if not discoverable, manually create a ready task
        Operation op = new Operation();
        op.setResourceType(ResourceOperationTypeEnum.DISCOVER_HOST);
        if (updateTaskStatus) {
            op.ready("Host is not discoverable");
        } else {
            op.pending();
        }
        _dbClient.createTaskOpStatus(Host.class, host.getId(), taskId, op);
        return toTask(host, taskId, op);
    }
}
Also used : TaskList(com.emc.storageos.model.TaskList) ComputeSystemController(com.emc.storageos.computesystemcontroller.ComputeSystemController) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayAffinityAsyncTask(com.emc.storageos.volumecontroller.ArrayAffinityAsyncTask) ArrayList(java.util.ArrayList) Host(com.emc.storageos.db.client.model.Host) DiscoveredObjectTaskScheduler(com.emc.storageos.api.service.impl.resource.utils.DiscoveredObjectTaskScheduler) Operation(com.emc.storageos.db.client.model.Operation)

Example 17 with ComputeSystemController

use of com.emc.storageos.computesystemcontroller.ComputeSystemController in project coprhd-controller by CoprHD.

the class InitiatorService method deleteInitiator.

/**
 * Deactivate an initiator.
 *
 * @param id the URN of a ViPR initiator
 * @prereq The initiator must not have active exports
 * @brief Delete host initiator
 * @return A Response indicating success or failure.
 *
 * @throws DatabaseException When an error occurs querying the database.
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deactivate")
@CheckPermission(roles = { Role.TENANT_ADMIN })
public TaskResourceRep deleteInitiator(@PathParam("id") URI id) {
    _log.info("Delete initiator {}", id);
    Initiator initiator = queryObject(Initiator.class, id, isIdEmbeddedInURL(id));
    if (!initiator.getIsManualCreation()) {
        throw APIException.badRequests.initiatorNotCreatedManuallyAndCannotBeDeleted();
    }
    ArgValidator.checkReference(Initiator.class, id, checkForDelete(initiator));
    String taskId = UUID.randomUUID().toString();
    Operation op = _dbClient.createTaskOpStatus(Initiator.class, initiator.getId(), taskId, ResourceOperationTypeEnum.DELETE_INITIATOR);
    if (ComputeSystemHelper.isInitiatorInUse(_dbClient, id.toString())) {
        ComputeSystemController controller = getController(ComputeSystemController.class, null);
        controller.removeInitiatorFromExport(initiator.getHost(), initiator.getId(), taskId);
    } else {
        _dbClient.ready(Initiator.class, initiator.getId(), taskId);
        _dbClient.markForDeletion(initiator);
    }
    auditOp(OperationTypeEnum.DELETE_HOST_INITIATOR, true, null, initiator.auditParameters());
    return toTask(initiator, taskId, op);
}
Also used : MapInitiator(com.emc.storageos.api.mapper.functions.MapInitiator) Initiator(com.emc.storageos.db.client.model.Initiator) ComputeSystemController(com.emc.storageos.computesystemcontroller.ComputeSystemController) Operation(com.emc.storageos.db.client.model.Operation) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 18 with ComputeSystemController

use of com.emc.storageos.computesystemcontroller.ComputeSystemController in project coprhd-controller by CoprHD.

the class IpInterfaceService method deactivateIpInterface.

/**
 * Deactivate an IP interface.
 *
 * @param id the URN of a ViPR IP interface
 * @prereq The IP interface must not have active exports
 * @brief Delete IP interface
 * @return OK if deactivation completed successfully
 * @throws DatabaseException
 */
@POST
@Path("/{id}/deactivate")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
public TaskResourceRep deactivateIpInterface(@PathParam("id") URI id) throws DatabaseException {
    IpInterface ipInterface = queryResource(id);
    ArgValidator.checkEntity(ipInterface, id, isIdEmbeddedInURL(id));
    if (ipInterface.getIsManualCreation() != null && !ipInterface.getIsManualCreation()) {
        throw APIException.badRequests.ipInterfaceNotCreatedManuallyAndCannotBeDeleted();
    }
    String taskId = UUID.randomUUID().toString();
    Operation op = _dbClient.createTaskOpStatus(IpInterface.class, ipInterface.getId(), taskId, ResourceOperationTypeEnum.DELETE_HOST_IPINTERFACE);
    // Clean up File Export if host is in use
    if (ComputeSystemHelper.isHostIpInterfacesInUse(_dbClient, Collections.singletonList(ipInterface.getIpAddress()), ipInterface.getHost())) {
        ComputeSystemController controller = getController(ComputeSystemController.class, null);
        controller.removeIpInterfaceFromFileShare(ipInterface.getHost(), ipInterface.getId(), taskId);
    } else {
        _dbClient.ready(IpInterface.class, ipInterface.getId(), taskId);
        _dbClient.markForDeletion(ipInterface);
    }
    auditOp(OperationTypeEnum.DELETE_HOST_IPINTERFACE, true, null, ipInterface.auditParameters());
    return toTask(ipInterface, taskId, op);
}
Also used : MapIpInterface(com.emc.storageos.api.mapper.functions.MapIpInterface) IpInterface(com.emc.storageos.db.client.model.IpInterface) ComputeSystemController(com.emc.storageos.computesystemcontroller.ComputeSystemController) Operation(com.emc.storageos.db.client.model.Operation) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 19 with ComputeSystemController

use of com.emc.storageos.computesystemcontroller.ComputeSystemController in project coprhd-controller by CoprHD.

the class VcenterService method detachStorage.

/**
 * Detaches storage from the vCenter.
 *
 * @param id the URN of a ViPR vCenter
 * @brief Detach storage from vCenter
 * @return task
 * @throws DatabaseException when a DB error occurs
 */
@POST
@Path("/{id}/detach-storage")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.TENANT_ADMIN })
public TaskResourceRep detachStorage(@PathParam("id") URI id) throws DatabaseException {
    Vcenter vcenter = queryObject(Vcenter.class, id, true);
    ArgValidator.checkEntity(vcenter, id, true);
    checkIfOtherTenantsUsingTheVcenter(vcenter);
    String taskId = UUID.randomUUID().toString();
    Operation op = _dbClient.createTaskOpStatus(Vcenter.class, vcenter.getId(), taskId, ResourceOperationTypeEnum.DETACH_VCENTER_DATACENTER_STORAGE);
    ComputeSystemController controller = getController(ComputeSystemController.class, null);
    controller.detachVcenterStorage(vcenter.getId(), false, taskId);
    return toTask(vcenter, taskId, op);
}
Also used : MapVcenter(com.emc.storageos.api.mapper.functions.MapVcenter) ComputeSystemController(com.emc.storageos.computesystemcontroller.ComputeSystemController) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 20 with ComputeSystemController

use of com.emc.storageos.computesystemcontroller.ComputeSystemController in project coprhd-controller by CoprHD.

the class VcenterService method doDiscoverVcenter.

/**
 * Vcenter Discovery
 *
 * @param vcenter the Vcenter to be discovered.
 *            provided, a new taskId is generated.
 * @return the task used to track the discovery job
 */
protected TaskResourceRep doDiscoverVcenter(Vcenter vcenter) {
    ComputeSystemController controller = getController(ComputeSystemController.class, "vcenter");
    DiscoveredObjectTaskScheduler scheduler = new DiscoveredObjectTaskScheduler(_dbClient, new DiscoverJobExec(controller));
    String taskId = UUID.randomUUID().toString();
    ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>(1);
    tasks.add(new AsyncTask(Vcenter.class, vcenter.getId(), taskId));
    TaskList taskList = scheduler.scheduleAsyncTasks(tasks);
    TaskResourceRep taskResourceRep = taskList.getTaskList().iterator().next();
    updateTaskTenant(taskResourceRep);
    return taskResourceRep;
}
Also used : MapVcenter(com.emc.storageos.api.mapper.functions.MapVcenter) ComputeSystemController(com.emc.storageos.computesystemcontroller.ComputeSystemController) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayList(java.util.ArrayList) DiscoveredObjectTaskScheduler(com.emc.storageos.api.service.impl.resource.utils.DiscoveredObjectTaskScheduler)

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