Search in sources :

Example 6 with BlockController

use of com.emc.storageos.volumecontroller.BlockController in project coprhd-controller by CoprHD.

the class StorageSystemService method deleteStoragePortGroup.

/**
 * Delete a storage port group
 *
 * @param id
 *            the URN of a ViPR storage port.
 *
 * @brief Delete a storage port group
 * @return The pending task
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/storage-port-groups/{pgId}/deactivate")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep deleteStoragePortGroup(@PathParam("id") URI id, @PathParam("pgId") URI pgId) {
    ArgValidator.checkFieldUriType(id, StorageSystem.class, "id");
    StorageSystem system = queryResource(id);
    // Only support for VMAX
    if (!DiscoveredDataObject.Type.vmax.name().equals(system.getSystemType())) {
        APIException.badRequests.operationNotSupportedForSystemType(OperationTypeEnum.CREATE_STORAGE_PORT_GROUP.name(), system.getSystemType());
    }
    ArgValidator.checkFieldUriType(pgId, StoragePortGroup.class, "portGroupId");
    StoragePortGroup portGroup = _dbClient.queryObject(StoragePortGroup.class, pgId);
    String task = UUID.randomUUID().toString();
    Operation op = null;
    if (portGroup == null || portGroup.getInactive()) {
        // The port group has been deleted
        op = _dbClient.createTaskOpStatus(StoragePortGroup.class, portGroup.getId(), task, ResourceOperationTypeEnum.DELETE_STORAGE_PORT_GROUP);
        op.ready();
    } else {
        // Check if the port group is used by any export mask
        URIQueryResultList queryResult = new URIQueryResultList();
        _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getExportMasksByPortGroup(portGroup.getId().toString()), queryResult);
        Iterator<URI> maskIt = queryResult.iterator();
        if (maskIt.hasNext()) {
            URI maskURI = maskIt.next();
            // The port group is used by at least one export mask, throw error
            ArgValidator.checkReference(StoragePortGroup.class, pgId, maskURI.toString());
        }
        op = _dbClient.createTaskOpStatus(StoragePortGroup.class, portGroup.getId(), task, ResourceOperationTypeEnum.DELETE_STORAGE_PORT_GROUP);
        _dbClient.updateObject(portGroup);
        BlockController controller = getController(BlockController.class, system.getSystemType());
        controller.deleteStoragePortGroup(system.getId(), portGroup.getId(), task);
    }
    auditOp(OperationTypeEnum.DELETE_STORAGE_PORT_GROUP, true, null, portGroup.getNativeGuid(), pgId.toString());
    recordStoragePoolPortEvent(OperationTypeEnum.DELETE_STORAGE_PORT_GROUP, OperationTypeEnum.DELETE_STORAGE_PORT_GROUP.getDescription(), portGroup.getId(), "StoragePortGroup");
    return toTask(portGroup, task, op);
}
Also used : MapStoragePortGroup(com.emc.storageos.api.mapper.functions.MapStoragePortGroup) StoragePortGroup(com.emc.storageos.db.client.model.StoragePortGroup) BlockController(com.emc.storageos.volumecontroller.BlockController) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 7 with BlockController

use of com.emc.storageos.volumecontroller.BlockController in project coprhd-controller by CoprHD.

the class InitiatorService method setInitiatorAlias.

/**
 * Sets the alias/initiator name for an initiator
 * on the Storage System
 *
 * @param id the URN of a ViPR initiator
 * @param aliasSetParam the parameter containing the storage system and alias attributes
 * @prereq none
 * @brief Set the serial number and alias on this storage system for an initiator
 * @return A reference to an InitiatorRestRep representing the Initiator Alias after Set..
 * @throws Exception When an error occurs setting the alias on a VMAX Storage System.
 */
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/alias")
public InitiatorAliasRestRep setInitiatorAlias(@PathParam("id") URI id, InitiatorAliasSetParam aliasSetParam) {
    // Basic Checks
    Initiator initiator = queryResource(id);
    verifyUserPermisions(initiator);
    URI systemURI = aliasSetParam.getSystemURI();
    ArgValidator.checkFieldUriType(systemURI, StorageSystem.class, "id");
    StorageSystem system = _permissionsHelper.getObjectById(systemURI, StorageSystem.class);
    ArgValidator.checkEntity(system, systemURI, isIdEmbeddedInURL(systemURI));
    String initiatorAlias = aliasSetParam.getInitiatorAlias();
    ArgValidator.checkFieldNotNull(initiatorAlias, "alias");
    if (!initiatorAlias.contains(EMPTY_INITIATOR_ALIAS)) {
        ArgValidator.checkFieldLengthMaximum(initiatorAlias, ALIAS_MAX_LIMIT, "alias");
    } else {
        ArgValidator.checkFieldLengthMaximum(initiatorAlias.split(EMPTY_INITIATOR_ALIAS)[0], ALIAS_MAX_LIMIT, "alias node name");
        ArgValidator.checkFieldLengthMaximum(initiatorAlias.split(EMPTY_INITIATOR_ALIAS)[1], ALIAS_MAX_LIMIT, "alias port name");
    }
    if (initiatorAlias.matches(ALIAS_ILLEGAL_CHARACTERS)) {
        String errMsg = String.format("Supplied Alias: %s has invalid characters", initiatorAlias);
        _log.error(errMsg);
        throw DeviceControllerException.exceptions.couldNotPerformAliasOperation(errMsg);
    }
    _log.info("Setting alias- {} for initiator {} on system {}", initiatorAlias, id, systemURI);
    if (system != null && StorageSystem.Type.vmax.toString().equalsIgnoreCase(system.getSystemType())) {
        BlockController controller = getController(BlockController.class, system.getSystemType());
        try {
            // Actual Control
            controller.setInitiatorAlias(systemURI, id, initiatorAlias);
        } catch (Exception e) {
            _log.error("Unexpected error: Setting alias failed.", e);
            throw APIException.badRequests.unableToProcessRequest(e.getMessage());
        }
    } else {
        throw APIException.badRequests.operationNotSupportedForSystemType(ALIAS, system.getSystemType());
    }
    // Update the Initiator here..
    if (initiatorAlias.contains(EMPTY_INITIATOR_ALIAS)) {
        // If the Initiator Alias contains the "/" character, the user has supplied
        // different node and port names.
        initiator.mapInitiatorName(system.getSerialNumber(), initiatorAlias);
    } else {
        // The user has set the same node and port names.
        initiatorAlias = String.format("%s%s%s", initiatorAlias, EMPTY_INITIATOR_ALIAS, initiatorAlias);
        initiator.mapInitiatorName(system.getSerialNumber(), initiatorAlias);
    }
    _dbClient.updateObject(initiator);
    return new InitiatorAliasRestRep(system.getSerialNumber(), initiatorAlias);
}
Also used : MapInitiator(com.emc.storageos.api.mapper.functions.MapInitiator) Initiator(com.emc.storageos.db.client.model.Initiator) BlockController(com.emc.storageos.volumecontroller.BlockController) InitiatorAliasRestRep(com.emc.storageos.model.host.InitiatorAliasRestRep) URI(java.net.URI) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 8 with BlockController

use of com.emc.storageos.volumecontroller.BlockController in project coprhd-controller by CoprHD.

the class SMISProviderService method registerSMISProvider.

/**
 * Register an SMI-S provider to create storage systems of type
 * vnxblock and vmax. This call is not used to create SMI-S
 * providers for vnxfile.
 * <p>
 * The method is deprecated. Use /vdc/storage-providers instead.
 *
 * @param param SMIS-Provider parameters
 * @brief Register SMI-S provider
 * @return Newly registered SMIS-Provider details
 * @throws ControllerException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN })
public TaskResourceRep registerSMISProvider(SMISProviderCreateParam param) throws ControllerException {
    String providerKey = param.getIpAddress() + "-" + param.getPortNumber();
    List<StorageProvider> providers = CustomQueryUtility.getActiveStorageProvidersByProviderId(_dbClient, providerKey);
    if (providers != null && !providers.isEmpty()) {
        throw APIException.badRequests.invalidParameterSMISProviderAlreadyRegistered(providerKey);
    }
    ArgValidator.checkFieldNotEmpty(param.getName(), "name");
    checkForDuplicateName(param.getName(), StorageProvider.class);
    ArgValidator.checkFieldNotEmpty(param.getIpAddress(), "ip_address");
    ArgValidator.checkFieldNotNull(param.getPortNumber(), "port_number");
    ArgValidator.checkFieldNotEmpty(param.getUserName(), "user_name");
    ArgValidator.checkFieldNotEmpty(param.getPassword(), "password");
    ArgValidator.checkFieldNotNull(param.getUseSSL(), "use_ssl");
    ArgValidator.checkFieldRange(param.getPortNumber(), 1, 65535, "port_number");
    StorageProvider smisProvider = new StorageProvider();
    smisProvider.setInterfaceType(StorageProvider.InterfaceType.smis.name());
    smisProvider.setId(URIUtil.createId(StorageProvider.class));
    smisProvider.setLabel(param.getName());
    smisProvider.setIPAddress(param.getIpAddress());
    smisProvider.setPortNumber(param.getPortNumber());
    smisProvider.setUserName(param.getUserName());
    smisProvider.setPassword(param.getPassword());
    smisProvider.setUseSSL(param.getUseSSL());
    smisProvider.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
    _dbClient.createObject(smisProvider);
    auditOp(OperationTypeEnum.REGISTER_SMISPROVIDER, true, null, smisProvider.getLabel(), smisProvider.getId().toString(), smisProvider.getIPAddress(), smisProvider.getPortNumber(), smisProvider.getUserName());
    ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>(1);
    String taskId = UUID.randomUUID().toString();
    tasks.add(new AsyncTask(StorageProvider.class, smisProvider.getId(), taskId));
    // @TODO revisit this to avoid hard coding.
    BlockController controller = getController(BlockController.class, "vnxblock");
    /**
     * Creates MonitoringJob token for vnxblock/vmax device on zooKeeper queue
     */
    controller.startMonitoring(new AsyncTask(StorageProvider.class, smisProvider.getId(), taskId), StorageSystem.Type.vnxblock);
    DiscoveredObjectTaskScheduler scheduler = new DiscoveredObjectTaskScheduler(_dbClient, new ScanJobExec(controller));
    TaskList taskList = scheduler.scheduleAsyncTasks(tasks);
    return taskList.getTaskList().listIterator().next();
}
Also used : BlockController(com.emc.storageos.volumecontroller.BlockController) TaskList(com.emc.storageos.model.TaskList) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayList(java.util.ArrayList) DiscoveredObjectTaskScheduler(com.emc.storageos.api.service.impl.resource.utils.DiscoveredObjectTaskScheduler) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 9 with BlockController

use of com.emc.storageos.volumecontroller.BlockController in project coprhd-controller by CoprHD.

the class SMISProviderService method scanSMISProviders.

/**
 * Scan all SMI-S providers.
 * <p>
 * The method is deprecated. Use /vdc/storage-providers/scan instead.
 *
 * @brief Scan SMI-S providers
 * @return TasList of all created asynchronous tasks
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN })
@Path("/scan")
public TaskList scanSMISProviders() {
    TaskList taskList = new TaskList();
    List<StorageProvider> providerList = CustomQueryUtility.getActiveStorageProvidersByInterfaceType(_dbClient, StorageProvider.InterfaceType.smis.name());
    if (providerList == null || providerList.isEmpty()) {
        return taskList;
    }
    BlockController controller = getController(BlockController.class, "vnxblock");
    DiscoveredObjectTaskScheduler scheduler = new DiscoveredObjectTaskScheduler(_dbClient, new ScanJobExec(controller));
    ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>();
    for (StorageProvider smisProvider : providerList) {
        String taskId = UUID.randomUUID().toString();
        tasks.add(new AsyncTask(StorageProvider.class, smisProvider.getId(), taskId));
    }
    taskList = scheduler.scheduleAsyncTasks(tasks);
    return taskList;
}
Also used : BlockController(com.emc.storageos.volumecontroller.BlockController) TaskList(com.emc.storageos.model.TaskList) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayList(java.util.ArrayList) DiscoveredObjectTaskScheduler(com.emc.storageos.api.service.impl.resource.utils.DiscoveredObjectTaskScheduler) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) 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 10 with BlockController

use of com.emc.storageos.volumecontroller.BlockController in project coprhd-controller by CoprHD.

the class AbstractBlockServiceApiImpl method createSnapshot.

/**
 * Uses the appropriate controller to create the snapshots.
 *
 * @param reqVolume
 *            The volume from the snapshot request.
 * @param snapshotURIs
 *            The URIs of the prepared snapshots
 * @param snapshotType
 *            The snapshot technology type.
 * @param createInactive
 *            true if the snapshots should be created but not
 *            activated, false otherwise.
 * @param readOnly
 *            true if the snapshot should be read only, false otherwise
 * @param taskId
 *            The unique task identifier.
 */
@Override
public void createSnapshot(Volume reqVolume, List<URI> snapshotURIs, String snapshotType, Boolean createInactive, Boolean readOnly, String taskId) {
    StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, reqVolume.getStorageController());
    BlockController controller = getController(BlockController.class, storageSystem.getSystemType());
    controller.createSnapshot(storageSystem.getId(), snapshotURIs, createInactive, readOnly, taskId);
}
Also used : BlockController(com.emc.storageos.volumecontroller.BlockController) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

BlockController (com.emc.storageos.volumecontroller.BlockController)48 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)32 Operation (com.emc.storageos.db.client.model.Operation)23 URI (java.net.URI)23 ArrayList (java.util.ArrayList)20 TaskList (com.emc.storageos.model.TaskList)16 Produces (javax.ws.rs.Produces)15 Volume (com.emc.storageos.db.client.model.Volume)13 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)13 Path (javax.ws.rs.Path)13 ControllerException (com.emc.storageos.volumecontroller.ControllerException)12 Consumes (javax.ws.rs.Consumes)12 POST (javax.ws.rs.POST)11 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)10 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)9 NamedURI (com.emc.storageos.db.client.model.NamedURI)8 StorageProvider (com.emc.storageos.db.client.model.StorageProvider)8 AsyncTask (com.emc.storageos.volumecontroller.AsyncTask)8 Controller (com.emc.storageos.Controller)7 DiscoveredObjectTaskScheduler (com.emc.storageos.api.service.impl.resource.utils.DiscoveredObjectTaskScheduler)7