Search in sources :

Example 1 with InitiatorAliasRestRep

use of com.emc.storageos.model.host.InitiatorAliasRestRep 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 2 with InitiatorAliasRestRep

use of com.emc.storageos.model.host.InitiatorAliasRestRep in project coprhd-controller by CoprHD.

the class InitiatorService method getInitiatorAlias.

/**
 * Shows the alias/initiator name for an initiator
 * if set on the Storage System
 *
 * @param id the URN of a ViPR initiator
 * @param sid the pstorage system uri
 * @prereq none
 * @brief Show the serial number and alias of an initiator
 * @return A reference to an InitiatorRestRep representing the Initiator Alias if Set..
 * @throws Exception When an error occurs querying the VMAX Storage System.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/alias/{sid}")
public InitiatorAliasRestRep getInitiatorAlias(@PathParam("id") URI id, @PathParam("sid") URI systemURI) {
    // Basic Checks
    Initiator initiator = queryResource(id);
    verifyUserPermisions(initiator);
    ArgValidator.checkFieldUriType(systemURI, StorageSystem.class, "id");
    StorageSystem system = _permissionsHelper.getObjectById(systemURI, StorageSystem.class);
    ArgValidator.checkEntity(system, systemURI, isIdEmbeddedInURL(systemURI));
    _log.info("Retrieving alias for initiator {} on system {}", id, systemURI);
    String initiatorAlias = null;
    if (system != null && StorageSystem.Type.vmax.toString().equalsIgnoreCase(system.getSystemType())) {
        BlockController controller = getController(BlockController.class, system.getSystemType());
        // Actual Control
        try {
            initiatorAlias = controller.getInitiatorAlias(systemURI, id);
        } catch (Exception e) {
            _log.error("Unexpected error: Getting alias failed.", e);
            throw APIException.badRequests.unableToProcessRequest(e.getMessage());
        }
    } else {
        throw APIException.badRequests.operationNotSupportedForSystemType(ALIAS, system.getSystemType());
    }
    // If the Alias is empty, set it to "/".
    if (NullColumnValueGetter.isNullValue(initiatorAlias)) {
        initiatorAlias = EMPTY_INITIATOR_ALIAS;
    }
    // Update the initiator
    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) 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) GET(javax.ws.rs.GET)

Aggregations

MapInitiator (com.emc.storageos.api.mapper.functions.MapInitiator)2 Initiator (com.emc.storageos.db.client.model.Initiator)2 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)2 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)2 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)2 InitiatorAliasRestRep (com.emc.storageos.model.host.InitiatorAliasRestRep)2 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)2 BlockController (com.emc.storageos.volumecontroller.BlockController)2 Consumes (javax.ws.rs.Consumes)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 URI (java.net.URI)1 GET (javax.ws.rs.GET)1 PUT (javax.ws.rs.PUT)1