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);
}
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);
}
Aggregations