use of com.emc.storageos.db.client.model.Initiator in project coprhd-controller by CoprHD.
the class NetworkZoningParam method updateZoningParamUsingFCZoneReference.
/**
* Build the zoningMap attribute of zoningParam using FCZoneReference and exportGroup
*
* @param zoningParam
* @param initsToRemoveOnlyFromZone
* @param exportGroup
*/
public static void updateZoningParamUsingFCZoneReference(List<NetworkZoningParam> zoningParam, List<URI> initsToRemoveOnlyFromZone, ExportGroup exportGroup, DbClient dbClient) {
HashMap<String, Initiator> initiatorMap = new HashMap<String, Initiator>();
for (URI initiatorURI : initsToRemoveOnlyFromZone) {
Initiator iniObject = dbClient.queryObject(Initiator.class, initiatorURI);
String iniString = iniObject.getInitiatorPort().toUpperCase();
initiatorMap.put(iniString, iniObject);
}
// Retrieve FCZoneReference zone references that have the same initiator WWN.
// These zone should be removed. since the initiator is no longer available.
List<FCZoneReference> fcRefs = NetworkUtil.getFCZoneReferencesFromExportGroup(dbClient, exportGroup);
Set<String> iniConsidered = new HashSet<String>();
for (NetworkZoningParam networkZoningParam : zoningParam) {
StringSetMap zoneMap = networkZoningParam.getZoningMap();
if (zoneMap.isEmpty()) {
for (FCZoneReference fcZoneReference : fcRefs) {
String[] initiatorAndPort = getInitiatorAndPortFromPwwnKey(fcZoneReference.getPwwnKey());
if (initiatorAndPort != null) {
String initiator = initiatorAndPort[0];
String port = initiatorAndPort[1];
Initiator iniObject = initiatorMap.get(initiator);
if (iniObject != null) {
StoragePort sp = NetworkUtil.getStoragePort(port, dbClient);
if (sp != null) {
iniConsidered.add(iniObject.getInitiatorPort());
zoneMap.put(iniObject.getId().toString(), sp.getId().toString());
}
}
} else {
_log.warn("Could not obtain initiator and port correctly from the PwwnKey {}", fcZoneReference.getPwwnKey());
}
}
// removed the initiator from map the as this initiator is considered for zone map
if (!iniConsidered.isEmpty()) {
initiatorMap.keySet().removeAll(iniConsidered);
}
}
}
}
use of com.emc.storageos.db.client.model.Initiator 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.db.client.model.Initiator in project coprhd-controller by CoprHD.
the class InitiatorService method registerInitiator.
/**
* Manually register the initiator with the passed id.
*
* @param id the URN of a ViPR initiator
*
* @brief Register initiator
* @return A reference to an InitiatorRestRep specifying the data for the
* initiator.
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
@Path("/{id}/register")
public InitiatorRestRep registerInitiator(@PathParam("id") URI id) {
ArgValidator.checkFieldUriType(id, Initiator.class, "id");
Initiator initiator = _dbClient.queryObject(Initiator.class, id);
ArgValidator.checkEntity(initiator, id, isIdEmbeddedInURL(id));
if (RegistrationStatus.UNREGISTERED.toString().equalsIgnoreCase(initiator.getRegistrationStatus())) {
initiator.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
_dbClient.persistObject(initiator);
auditOp(OperationTypeEnum.REGISTER_INITIATOR, true, null, initiator.getId().toString());
}
return map(initiator);
}
use of com.emc.storageos.db.client.model.Initiator in project coprhd-controller by CoprHD.
the class InitiatorService method updateInitiator.
/**
* Update a host initiator.
*
* @param id the URN of a ViPR initiator
* @param updateParam the parameter containing the new attributes
* @prereq none
* @brief Update initiator.
* @return the details of the updated host initiator.
* @throws DatabaseException when a DB error occurs
*/
@PUT
@Path("/{id}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
public InitiatorRestRep updateInitiator(@PathParam("id") URI id, InitiatorUpdateParam updateParam) throws DatabaseException {
Initiator initiator = queryObject(Initiator.class, id, true);
_hostService.validateInitiatorData(updateParam, initiator);
_hostService.populateInitiator(initiator, updateParam);
_dbClient.persistObject(initiator);
auditOp(OperationTypeEnum.UPDATE_HOST_INITIATOR, true, null, initiator.auditParameters());
return map(queryObject(Initiator.class, id, false));
}
use of com.emc.storageos.db.client.model.Initiator in project coprhd-controller by CoprHD.
the class InitiatorService method deregisterInitiator.
/**
* Allows the user to deregister a registered initiator so that it is no
* longer used by the system. This simply sets the registration_status of
* the initiator to UNREGISTERED.
*
* @param id the URN of a ViPR initiator
*
* @brief Unregister initiator
* @return Status response indicating success or failure
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deregister")
@CheckPermission(roles = { Role.TENANT_ADMIN })
public InitiatorRestRep deregisterInitiator(@PathParam("id") URI id) {
Initiator initiator = queryResource(id);
ArgValidator.checkEntity(initiator, id, isIdEmbeddedInURL(id));
if (ComputeSystemHelper.isInitiatorInUse(_dbClient, id.toString())) {
throw APIException.badRequests.resourceHasActiveReferencesWithType(Initiator.class.getSimpleName(), initiator.getId(), ExportGroup.class.getSimpleName());
}
if (RegistrationStatus.REGISTERED.toString().equalsIgnoreCase(initiator.getRegistrationStatus())) {
initiator.setRegistrationStatus(RegistrationStatus.UNREGISTERED.toString());
_dbClient.persistObject(initiator);
auditOp(OperationTypeEnum.DEREGISTER_INITIATOR, true, null, initiator.getLabel(), initiator.getId().toString());
}
return map(initiator);
}
Aggregations