use of com.emc.storageos.db.client.model.StoragePortGroup in project coprhd-controller by CoprHD.
the class ExportGroupService method changePortGroup.
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/change-port-group")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep changePortGroup(@PathParam("id") URI id, ChangePortGroupParam param) throws ControllerException {
// Basic validation of ExportGroup and the request
param.logParameters(_log);
ExportGroup exportGroup = queryObject(ExportGroup.class, id, true);
if (exportGroup.checkInternalFlags(DataObject.Flag.DELETION_IN_PROGRESS)) {
throw BadRequestException.badRequests.deletionInProgress(exportGroup.getClass().getSimpleName(), exportGroup.getLabel());
}
validateExportGroupNoPendingEvents(exportGroup);
Boolean wait = new Boolean(param.getWaitBeforeRemovePaths());
validateSuspendSetForNonDiscoverableHosts(exportGroup, wait, true);
ArgValidator.checkUri(param.getNewPortGroup());
StoragePortGroup newPortGroup = queryObject(StoragePortGroup.class, param.getNewPortGroup(), true);
if (!newPortGroup.isUsable()) {
throw APIException.badRequests.portGroupInvalid(newPortGroup.getNativeGuid());
}
URI systemURI = newPortGroup.getStorageDevice();
StorageSystem system = queryObject(StorageSystem.class, systemURI, true);
// Get the virtual array, default to Export Group varray. Validate it matches.
URI varray = exportGroup.getVirtualArray();
String value = customConfigHandler.getComputedCustomConfigValue(CustomConfigConstants.VMAX_USE_PORT_GROUP_ENABLED, Type.vmax.name(), null);
if (!Boolean.TRUE.toString().equalsIgnoreCase(value)) {
throw APIException.badRequests.portGroupSettingIsOff();
}
com.emc.storageos.api.service.impl.resource.utils.ExportUtils.validatePortGroupWithVirtualArray(newPortGroup, varray, _dbClient);
URI currentPortGroup = param.getCurrentPortGroup();
if (currentPortGroup != null && currentPortGroup.equals(newPortGroup.getId())) {
throw APIException.badRequests.changePortGroupSameNewPortGroup(newPortGroup.getNativeGuid());
}
URI exportMaskURI = param.getExportMask();
ExportMask mask = null;
if (exportMaskURI != null) {
mask = queryObject(ExportMask.class, exportMaskURI, true);
if (mask != null) {
if (!exportGroup.getExportMasks().contains(exportMaskURI.toString())) {
throw APIException.badRequests.changePortGroupInvalidExportMask(mask.getMaskName());
}
if (!systemURI.equals(mask.getStorageDevice())) {
throw APIException.badRequests.changePortGroupInvalidExportMask(mask.getMaskName());
}
if (currentPortGroup != null && !currentPortGroup.equals(mask.getPortGroup())) {
throw APIException.badRequests.changePortGroupInvalidExportMask(mask.getMaskName());
}
}
}
List<ExportMask> exportMasks = new ArrayList<ExportMask>();
if (mask != null) {
exportMasks.add(mask);
} else {
exportMasks = ExportMaskUtils.getExportMasks(_dbClient, exportGroup, system.getId(), currentPortGroup);
}
if (exportMasks.isEmpty()) {
throw APIException.badRequests.noValidExportMaskInExportGroup(exportGroup.getLabel());
}
List<URI> affectedMasks = new ArrayList<URI>();
for (ExportMask exportMask : exportMasks) {
URI currentPGUri = exportMask.getPortGroup();
StringSet newPorts = newPortGroup.getStoragePorts();
if (!newPortGroup.getId().equals(currentPGUri)) {
StoragePortGroup currentPG = queryObject(StoragePortGroup.class, currentPGUri, false);
StringSet currentPorts = currentPG.getStoragePorts();
if (!Collections.disjoint(newPorts, currentPorts)) {
throw APIException.badRequests.changePortGroupPortGroupNoOverlap(newPortGroup.getLabel());
}
// because we could not add use the same storage group and a new port group to create the new masking view
if (system.checkIfVmax3()) {
String volumeWithHostIO = ExportUtils.getVolumeHasHostIOLimitSet(_dbClient, exportMask.getVolumes());
if (volumeWithHostIO != null) {
throw APIException.badRequests.changePortGroupNotSupportedforHostIOLimit(volumeWithHostIO);
}
}
// Check if there is any existing volumes in the export mask
if (exportMask.getExistingVolumes() != null && !exportMask.getExistingVolumes().isEmpty()) {
throw APIException.badRequests.changePortGroupExistingVolumes(exportMask.getMaskName(), Joiner.on(',').join(exportMask.getExistingVolumes().keySet()));
}
if (exportMask.getExistingInitiators() != null && !exportMask.getExistingInitiators().isEmpty()) {
throw APIException.badRequests.changePortGroupExistingInitiators(exportMask.getMaskName(), Joiner.on(',').join(exportMask.getExistingInitiators()));
}
affectedMasks.add(exportMask.getId());
} else {
_log.info(String.format("The export mask %s uses the same port group %s", exportMask.getMaskName(), newPortGroup.getLabel()));
}
}
String task = UUID.randomUUID().toString();
if (affectedMasks.isEmpty()) {
_log.info("No export mask to change port group, do nothing");
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.EXPORT_CHANGE_PORT_GROUP);
op.setMessage("No port group change is needed for this export group");
op.ready();
exportGroup.getOpStatus().createTaskStatus(task, op);
_dbClient.updateObject(exportGroup);
return toTask(exportGroup, task, op);
}
Operation op = initTaskStatus(exportGroup, task, Operation.Status.pending, ResourceOperationTypeEnum.EXPORT_CHANGE_PORT_GROUP);
TaskResourceRep taskRes = toTask(exportGroup, task, op);
// persist the export group to the database
_dbClient.updateObject(exportGroup);
auditOp(OperationTypeEnum.EXPORT_CHANGE_PORT_GROUP, true, AuditLogManager.AUDITOP_BEGIN, exportGroup.getLabel(), exportGroup.getId().toString(), exportGroup.getVirtualArray().toString(), exportGroup.getProject().toString());
BlockExportController exportController = getExportController();
_log.info(String.format("Submitting change port group %s request.", newPortGroup.getNativeGuid()));
exportController.exportGroupChangePortGroup(systemURI, id, newPortGroup.getId(), affectedMasks, wait, task);
return taskRes;
}
use of com.emc.storageos.db.client.model.StoragePortGroup in project coprhd-controller by CoprHD.
the class VirtualArrayService method getVirtualArrayStoragePortGroups.
/**
* This method gets storage port groups for a given virtual array. The storage ports in the port group
* should all be assigned or connected to the virtual array.
* If export group is specified, it will return the port group used in the export masks belonging to the export
* group, plus
* the port groups in the virtual array, but in different storage system from the export masks.
* If storage system is specified, it will only return the port groups belonging to the storage system.
* If vpool is specified, it will get the port groups from the same storage system as vpool's storage pools reside.
* If consistency group is specified, it will return the port groups in the same storage system as the consistency
* group
* This API is used by UI to get storage port group list for create and export volumes related catalog services
*
* @param id
* - Virtual array URI
* @param storageURI
* - OPTIONAL Storage system URI
* @param exportGroupURI
* - OPTIONAL Export group URI
* @param vpoolURI
* - OPTIONAL virtual pool URI
* @param cgURI
* - OPTIONAL consistency group URI
* @param registeredOnly
* - OPTIONAL if true, only registered port group would be returned
* if false, both registered and deregistered port group would be returned
* if not set, default to true
* @return - Storage port group list
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/storage-port-groups")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR }, acls = { ACL.USE })
public StoragePortGroupRestRepList getVirtualArrayStoragePortGroups(@PathParam("id") URI id, @QueryParam("storage_system") URI storageURI, @QueryParam("export_group") URI exportGroupURI, @QueryParam("vpool") URI vpoolURI, @QueryParam("consistency_group") URI cgURI, @QueryParam("registered_only") Boolean registeredOnly) {
// Get and validate the varray with the passed id.
ArgValidator.checkFieldUriType(id, VirtualArray.class, "id");
VirtualArray varray = _dbClient.queryObject(VirtualArray.class, id);
ArgValidator.checkEntity(varray, id, isIdEmbeddedInURL(id));
Set<URI> portURIs = new HashSet<URI>();
// Query the database for the storage ports associated with the
// VirtualArray.
URIQueryResultList storagePortURIs = new URIQueryResultList();
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVirtualArrayStoragePortsConstraint(id.toString()), storagePortURIs);
for (URI portURI : storagePortURIs) {
portURIs.add(portURI);
}
Set<URI> portGroupURIs = new HashSet<URI>();
StoragePortGroupRestRepList portGroups = new StoragePortGroupRestRepList();
Set<URI> excludeSystem = new HashSet<URI>();
if (storageURI != null) {
StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storageURI);
if (!Type.vmax.name().equals(storageSystem.getSystemType())) {
_log.info(String.format("The specified storage system %s is type %s, no port group supported", storageURI.toString(), storageSystem.getSystemType()));
return portGroups;
}
}
if (cgURI != null) {
BlockConsistencyGroup cg = _dbClient.queryObject(BlockConsistencyGroup.class, cgURI);
if (cg != null) {
URI cgStorage = cg.getStorageController();
if (!NullColumnValueGetter.isNullURI(cgStorage)) {
if (storageURI != null && !storageURI.equals(cgStorage)) {
_log.error(String.format("The consistency group %s storage system %s does not match the passed in storageURI %s", cg.getLabel(), cgStorage.toString(), storageURI.toString()));
return portGroups;
} else if (storageURI == null) {
StorageSystem cgSystem = _dbClient.queryObject(StorageSystem.class, cgStorage);
if (Type.vmax.name().equals(cgSystem.getSystemType())) {
storageURI = cgStorage;
} else {
_log.info(String.format("The consistency group %s storage system %s is %s. port group is not supported", cg.getLabel(), cgSystem.getNativeGuid(), cgSystem.getSystemType()));
return portGroups;
}
}
}
}
}
Set<URI> includedSystems = new HashSet<URI>();
if (storageURI != null) {
includedSystems.add(storageURI);
}
if (vpoolURI != null) {
// vpool is specified. Get storage port groups belonging to the same storage system as the vpool
// valid storage pools.
ArgValidator.checkFieldUriType(vpoolURI, VirtualPool.class, "vpool");
VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, vpoolURI);
if (VirtualPool.vPoolSpecifiesHighAvailability(vpool)) {
// This is vplex, return empty
_log.warn(String.format("The vpool %s is for vplex, no port group is supported", vpool.getLabel()));
return portGroups;
}
List<StoragePool> pools = VirtualPool.getValidStoragePools(vpool, _dbClient, true);
Set<URI> poolSystems = new HashSet<URI>();
if (!CollectionUtils.isEmpty(pools)) {
for (StoragePool pool : pools) {
URI poolSystemURI = pool.getStorageDevice();
if (storageURI != null && storageURI.equals(poolSystemURI)) {
poolSystems.add(poolSystemURI);
} else if (storageURI == null) {
poolSystems.add(poolSystemURI);
}
}
if (poolSystems.isEmpty()) {
// No valid storage system belong to the vpool
_log.info(String.format("The virtual pool %s does not have any pool in the valid storage system", vpool.getLabel()));
return portGroups;
} else {
includedSystems.addAll(poolSystems);
}
} else {
_log.warn(String.format("The vpool %s does not have any valid storage pools, no port group returned", vpool.getLabel()));
return portGroups;
}
}
if (exportGroupURI != null) {
// When export group URI is specified, it would return all the port groups current used in the export masks,
// (no other port groups in the same storage system will be returned.) plus the port groups in the other
// storage systems
// which are available in the virtual array.
ExportGroup exportGroup = _dbClient.queryObject(ExportGroup.class, exportGroupURI);
if (exportGroup == null || !id.equals(exportGroup.getVirtualArray())) {
_log.error(String.format("The export group %s is not valid", exportGroupURI.toString()));
return portGroups;
}
StringSet exportMasks = exportGroup.getExportMasks();
if (!CollectionUtils.isEmpty(exportMasks)) {
for (String emStr : exportMasks) {
URI maskUri = URI.create(emStr);
ExportMask exportMask = _dbClient.queryObject(ExportMask.class, maskUri);
if (exportMask == null) {
continue;
}
if (NullColumnValueGetter.isNullURI(exportMask.getPortGroup())) {
continue;
}
if ((!NullColumnValueGetter.isNullURI(storageURI) && storageURI.equals(exportMask.getStorageDevice())) || includedSystems.isEmpty() || includedSystems.contains(exportMask.getStorageDevice())) {
portGroupURIs.add(exportMask.getPortGroup());
}
// Add the export mask storage system to the exclude systems, so that no other port groups from the
// same storage system would be returned
excludeSystem.add(exportMask.getStorageDevice());
}
}
}
for (URI portURI : portURIs) {
// Get port groups for each port
StoragePort port = _dbClient.queryObject(StoragePort.class, portURI);
if (port == null || (storageURI != null && !storageURI.equals(port.getStorageDevice())) || excludeSystem.contains(port.getStorageDevice())) {
continue;
}
if (!includedSystems.isEmpty() && !includedSystems.contains(port.getStorageDevice())) {
continue;
}
if ((port != null) && (RegistrationStatus.REGISTERED.toString().equals(port.getRegistrationStatus())) && DiscoveryStatus.VISIBLE.toString().equals(port.getDiscoveryStatus())) {
URIQueryResultList pgURIs = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getStoragePortPortGroupConstraint(portURI), pgURIs);
for (URI groupURI : pgURIs) {
portGroupURIs.add(groupURI);
}
}
}
// Sort the list based on its metrics
Iterator<StoragePortGroup> it = _dbClient.queryIterativeObjects(StoragePortGroup.class, portGroupURIs, true);
List<StoragePortGroup> sortPGs = new ArrayList<StoragePortGroup>();
while (it.hasNext()) {
sortPGs.add(it.next());
}
Collections.sort(sortPGs, new StoragePortGroupComparator());
boolean checkRegistered = (registeredOnly != null ? registeredOnly : true);
// return the result.
for (StoragePortGroup portGroup : sortPGs) {
if (portGroup != null && !portGroup.getInactive() && (!checkRegistered || portGroup.isUsable()) && portURIs.containsAll(StringSetUtil.stringSetToUriList(portGroup.getStoragePorts()))) {
StoragePortGroupRestRep pgRep = MapStoragePortGroup.getInstance(_dbClient).toStoragePortGroupRestRep(portGroup);
portGroups.getStoragePortGroups().add(pgRep);
}
}
return portGroups;
}
use of com.emc.storageos.db.client.model.StoragePortGroup in project coprhd-controller by CoprHD.
the class StorageSystemService method checkForDuplicatePortGroupName.
/**
* Check if a storage port group with the same name exists for the passed storage system.
*
* @param name
* Port group name
* @param id
* Storage system id
*/
private void checkForDuplicatePortGroupName(String name, URI systemURI) {
URIQueryResultList portGroupURIs = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getStorageDevicePortGroupConstraint(systemURI), portGroupURIs);
Iterator<URI> portGroupIter = portGroupURIs.iterator();
while (portGroupIter.hasNext()) {
StoragePortGroup portGroup = _dbClient.queryObject(StoragePortGroup.class, portGroupIter.next());
if (portGroup != null && !portGroup.getInactive() && portGroup.getLabel().equalsIgnoreCase(name)) {
throw APIException.badRequests.duplicateLabel(name);
}
}
}
use of com.emc.storageos.db.client.model.StoragePortGroup in project coprhd-controller by CoprHD.
the class StorageSystemService method registerStoragePortGroup.
/**
* Allows the user to register a unregistered storage port group so that it
* coudl be used/shared for export. This sets the registration_status of the
* storage port group to REGISTERED, and mutable to false
*
* @param id
* the URN of a ViPR storage port group.
*
* @brief Register storage port group
* @return StoragePortGroup
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/storage-port-groups/{portGroupId}/register")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public StoragePortGroupRestRep registerStoragePortGroup(@PathParam("portGroupId") URI portGroupId) {
ArgValidator.checkFieldUriType(portGroupId, StoragePortGroup.class, "portGroupId");
StoragePortGroup portGroup = _dbClient.queryObject(StoragePortGroup.class, portGroupId);
if (portGroup.checkInternalFlags(Flag.INTERNAL_OBJECT)) {
// internal port group
throw APIException.badRequests.internalPortGroup(portGroup.getNativeGuid());
}
if (RegistrationStatus.UNREGISTERED.toString().equalsIgnoreCase(portGroup.getRegistrationStatus())) {
// Setting status to REGISTERED.
portGroup.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
portGroup.setMutable(false);
_dbClient.updateObject(portGroup);
// Record the storage port group register event.
recordStoragePoolPortEvent(OperationTypeEnum.REGISTER_STORAGE_PORT_GROUP, OperationTypeEnum.REGISTER_STORAGE_PORT_GROUP.getDescription(), portGroup.getId(), "StoragePortGroup");
auditOp(OperationTypeEnum.REGISTER_STORAGE_PORT_GROUP, true, null, portGroup.getLabel(), portGroup.getId().toString());
}
return MapStoragePortGroup.getInstance(_dbClient).toStoragePortGroupRestRep(portGroup);
}
use of com.emc.storageos.db.client.model.StoragePortGroup in project coprhd-controller by CoprHD.
the class StorageSystemService method createStoragePortGroup.
/**
* Create a storage port group
*
* @param id
* the URN of a ViPR storage port.
*
* @brief Create a storage port
* @return The pending task
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/storage-port-groups")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep createStoragePortGroup(@PathParam("id") URI id, StoragePortGroupCreateParam param) {
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.checkFieldNotEmpty(param.getName(), "name");
String portGroupName = param.getName();
List<URI> ports = param.getStoragePorts();
for (URI port : ports) {
ArgValidator.checkFieldUriType(port, StoragePort.class, "portURI");
StoragePort sport = _dbClient.queryObject(StoragePort.class, port);
ArgValidator.checkEntityNotNull(sport, port, isIdEmbeddedInURL(port));
}
checkForDuplicatePortGroupName(portGroupName, id);
StoragePortGroup portGroup = new StoragePortGroup();
portGroup.setLabel(portGroupName);
if (param.getRegistered()) {
portGroup.setRegistrationStatus(RegistrationStatus.REGISTERED.name());
} else {
portGroup.setRegistrationStatus(RegistrationStatus.UNREGISTERED.name());
}
portGroup.setStorageDevice(id);
portGroup.setStoragePorts(StringSetUtil.uriListToStringSet(ports));
portGroup.setId(URIUtil.createId(StoragePortGroup.class));
portGroup.setMutable(false);
_dbClient.createObject(portGroup);
String task = UUID.randomUUID().toString();
Operation op = _dbClient.createTaskOpStatus(StoragePortGroup.class, portGroup.getId(), task, ResourceOperationTypeEnum.CREATE_STORAGE_PORT_GROUP);
_dbClient.updateObject(portGroup);
auditOp(OperationTypeEnum.CREATE_STORAGE_PORT_GROUP, true, null, param.getName(), id.toString());
recordStoragePoolPortEvent(OperationTypeEnum.CREATE_STORAGE_PORT_GROUP, OperationTypeEnum.CREATE_STORAGE_PORT_GROUP.getDescription(), portGroup.getId(), "StoragePortGroup");
TaskResourceRep taskRes = toTask(portGroup, task, op);
BlockController controller = getController(BlockController.class, system.getSystemType());
controller.createStoragePortGroup(system.getId(), portGroup.getId(), task);
return taskRes;
}
Aggregations