use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.
the class StoragePortService method checkForDuplicatePortNetworkIdWithinSystem.
/**
* Check if a storage port with the same portNetworkId exists for the passed storage system.
*
* @param dbClient the db client
* @param portNetworkId the port network id
* @param systemURI the system uri
*/
public static void checkForDuplicatePortNetworkIdWithinSystem(DbClient dbClient, String portNetworkId, URI systemURI) {
URIQueryResultList portUriList = new URIQueryResultList();
dbClient.queryByConstraint(AlternateIdConstraint.Factory.getStoragePortEndpointConstraint(portNetworkId), portUriList);
Iterator<URI> storagePortIter = portUriList.iterator();
while (storagePortIter.hasNext()) {
StoragePort port = dbClient.queryObject(StoragePort.class, storagePortIter.next());
if (port != null && !port.getInactive() && port.getStorageDevice().toString().equals(systemURI.toString())) {
throw APIException.badRequests.duplicateEntityWithField("StoragePort", "portNetworkId");
}
}
}
use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.
the class StorageProviderService method addStorageSystem.
/**
* Allows the user to add a storage system and rescans the provider.
* After that corresponding provider should be able to be rescanned and add this system back to the list of managed systems.
*
* @param id id the URN of a ViPR Storage provider
* @param param The storage system details.
*
* @brief Add a new storage system and rescan the provider.
* @return An asynchronous task corresponding to the scan job scheduled for the provider.
*
* @throws BadRequestException When the system type is not valid or a
* storage system with the same native guid already exists.
* @throws com.emc.storageos.db.exceptions.DatabaseException When an error occurs querying the database.
* @throws ControllerException When an error occurs discovering the storage
* system.
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN })
@Path("/{id}/storage-systems")
public TaskResourceRep addStorageSystem(@PathParam("id") URI id, StorageSystemProviderRequestParam param) throws ControllerException {
TaskResourceRep taskRep;
URIQueryResultList list = new URIQueryResultList();
ArgValidator.checkFieldNotEmpty(param.getSystemType(), "system_type");
if (!StorageSystem.Type.isProviderStorageSystem(param.getSystemType())) {
throw APIException.badRequests.cannotAddStorageSystemTypeToStorageProvider(param.getSystemType());
}
StorageProvider provider = _dbClient.queryObject(StorageProvider.class, id);
ArgValidator.checkEntityNotNull(provider, id, isIdEmbeddedInURL(id));
ArgValidator.checkFieldNotEmpty(param.getSerialNumber(), "serialNumber");
String nativeGuid = NativeGUIDGenerator.generateNativeGuid(param.getSystemType(), param.getSerialNumber());
// check for duplicate StorageSystem.
List<StorageSystem> systems = CustomQueryUtility.getActiveStorageSystemByNativeGuid(_dbClient, nativeGuid);
if (systems != null && !systems.isEmpty()) {
throw APIException.badRequests.invalidParameterProviderStorageSystemAlreadyExists("nativeGuid", nativeGuid);
}
int cleared = DecommissionedResource.removeDecommissionedFlag(_dbClient, nativeGuid, StorageSystem.class);
if (cleared == 0) {
log.info("Cleared {} decommissioned systems", cleared);
} else {
log.info("Did not find any decommissioned systems to clear. Continue to scan.");
}
ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>(1);
String taskId = UUID.randomUUID().toString();
tasks.add(new AsyncTask(StorageProvider.class, provider.getId(), taskId));
BlockController controller = getController(BlockController.class, provider.getInterfaceType());
DiscoveredObjectTaskScheduler scheduler = new DiscoveredObjectTaskScheduler(_dbClient, new ScanJobExec(controller));
TaskList taskList = scheduler.scheduleAsyncTasks(tasks);
return taskList.getTaskList().listIterator().next();
}
use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.
the class StorageSystemService method registerStorageSystem.
/**
* Allows the user register the storage system with the passed id.
*
* @param id the URN of a ViPR storage system.
*
* @brief Register storage system
* @return A StorageSystemRestRep reference specifying the data for the
* updated storage system.
* @throws ControllerException
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/register")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public StorageSystemRestRep registerStorageSystem(@PathParam("id") URI id) throws ControllerException {
// Validate the storage system.
ArgValidator.checkFieldUriType(id, StorageSystem.class, "id");
StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, id);
ArgValidator.checkEntity(storageSystem, id, isIdEmbeddedInURL(id));
// If not already registered, register it now.
if (RegistrationStatus.UNREGISTERED.toString().equalsIgnoreCase(storageSystem.getRegistrationStatus())) {
storageSystem.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
_dbClient.updateObject(storageSystem);
startStorageSystem(storageSystem);
auditOp(OperationTypeEnum.REGISTER_STORAGE_SYSTEM, true, null, storageSystem.getId().toString(), id.toString());
}
// Register all Pools.
URIQueryResultList storagePoolURIs = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getStorageDeviceStoragePoolConstraint(id), storagePoolURIs);
Iterator<URI> storagePoolIter = storagePoolURIs.iterator();
List<StoragePool> registeredPools = new ArrayList<StoragePool>();
while (storagePoolIter.hasNext()) {
StoragePool pool = _dbClient.queryObject(StoragePool.class, storagePoolIter.next());
if (pool.getInactive() || DiscoveredDataObject.RegistrationStatus.REGISTERED.toString().equals(pool.getRegistrationStatus())) {
continue;
}
registerStoragePool(pool);
registeredPools.add(pool);
}
// Register all Ports.
URIQueryResultList storagePortURIs = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getStorageDeviceStoragePortConstraint(id), storagePortURIs);
Iterator<URI> storagePortIter = storagePortURIs.iterator();
while (storagePortIter.hasNext()) {
StoragePort port = _dbClient.queryObject(StoragePort.class, storagePortIter.next());
if (port.getInactive() || DiscoveredDataObject.RegistrationStatus.REGISTERED.toString().equals(port.getRegistrationStatus())) {
continue;
}
registerStoragePort(port);
}
StringBuffer errorMessage = new StringBuffer();
// Pool registration also update its varray relationship, so, we should also update vpool to pool relation.
ImplicitPoolMatcher.matchModifiedStoragePoolsWithAllVirtualPool(registeredPools, _dbClient, _coordinator, errorMessage);
return map(storageSystem);
}
use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.
the class StorageSystemService method checkForDuplicatePortName.
/**
* Check if a storage port with the same name exists for the passed storage system.
*
* @param name Port name
* @param id Storage system id
*/
private void checkForDuplicatePortName(String name, URI systemURI) {
URIQueryResultList storagePortURIs = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getStorageDeviceStoragePortConstraint(systemURI), storagePortURIs);
Iterator<URI> storagePortIter = storagePortURIs.iterator();
while (storagePortIter.hasNext()) {
StoragePort port = _dbClient.queryObject(StoragePort.class, storagePortIter.next());
if (port != null && !port.getInactive() && port.getLabel().equalsIgnoreCase(name)) {
throw APIException.badRequests.duplicateLabel(name);
}
}
}
use of com.emc.storageos.db.client.constraint.URIQueryResultList 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);
}
Aggregations