use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class NetworkDeviceController method testCommunication.
@Override
public void testCommunication(URI network, String task) throws ControllerException {
try {
BiosCommandResult result = doConnect(network);
if (result.isCommandSuccess()) {
Operation op = new Operation();
op.setMessage(result.getMessage());
_dbClient.ready(NetworkSystem.class, network, task);
} else {
String opName = ResourceOperationTypeEnum.UPDATE_NETWORK.getName();
ServiceError serviceError = NetworkDeviceControllerException.errors.testCommunicationFailed(opName, network.toString());
_dbClient.error(NetworkSystem.class, network, task, serviceError);
}
} catch (Exception e) {
_log.error("Exception while trying update task status");
try {
String opName = ResourceOperationTypeEnum.UPDATE_NETWORK.getName();
ServiceError serviceError = NetworkDeviceControllerException.errors.testCommunicationFailedExc(opName, network.toString(), e);
_dbClient.error(NetworkSystem.class, network, task, serviceError);
} catch (DatabaseException ioe) {
_log.error(ioe.getMessage());
}
}
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class StoragePortService method deleteStoragePort.
/**
* Remove a storage port. The method would remove the deregistered storage port and all resources
* associated with the storage port from the database.
* Note they are not removed from the storage system physically,
* but become unavailable for the user.
*
* @param id the URN of a ViPR storage port to be removed.
*
* @brief Remove storage port from ViPR
* @return Status indicating success or failure.
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deactivate")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep deleteStoragePort(@PathParam("id") URI id) {
ArgValidator.checkFieldUriType(id, StoragePort.class, "id");
StoragePort port = queryResource(id);
if (!RegistrationStatus.UNREGISTERED.toString().equalsIgnoreCase(port.getRegistrationStatus()) || DiscoveryStatus.VISIBLE.name().equalsIgnoreCase(port.getDiscoveryStatus())) {
throw APIException.badRequests.cannotDeactivateStoragePort();
}
String taskId = UUID.randomUUID().toString();
Operation op = _dbClient.createTaskOpStatus(StoragePool.class, id, taskId, ResourceOperationTypeEnum.DELETE_STORAGE_PORT);
PurgeRunnable.executePurging(_dbClient, _dbPurger, _asynchJobService.getExecutorService(), port, _retry_attempts, taskId, 60);
return toTask(port, taskId, op);
}
use of com.emc.storageos.db.client.model.Operation 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);
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class StorageSystemService method updateStorageSystem.
/**
* Allows the user to update credentials for a manually created storage systems.
* Allows the user to update only the name field for vmax and vnx block systems.
*
* @param id the URN of a ViPR storage system
* @param param The storage system details to update.
*
* @brief Update storage system credentials
* @return A StorageSystemRestRep reference specifying the storage system
* data.
*
* @throws BadRequestException When the system is not valid.
* @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 })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep updateStorageSystem(@PathParam("id") URI id, StorageSystemUpdateRequestParam param) throws ControllerException {
StorageSystem system = _dbClient.queryObject(StorageSystem.class, id);
ArgValidator.checkEntity(system, id, isIdEmbeddedInURL(id));
StorageSystem.Type systemType = StorageSystem.Type.valueOf(system.getSystemType());
if (param.getName() != null && !param.getName().isEmpty() && !param.getName().equalsIgnoreCase(system.getLabel())) {
checkForDuplicateName(param.getName(), StorageSystem.class);
system.setLabel(param.getName());
}
// If unlimited resources is set to false, then max resources should also be specified. If not specified, throw error
if (null != param.getIsUnlimitedResourcesSet()) {
if (param.getIsUnlimitedResourcesSet()) {
system.setIsResourceLimitSet(false);
} else {
if (null != param.getMaxResources()) {
system.setIsResourceLimitSet(true);
system.setMaxResources(param.getMaxResources());
} else {
throw APIException.badRequests.parameterMaxResourcesMissing();
}
}
} else if (null != param.getMaxResources()) {
system.setMaxResources(param.getMaxResources());
system.setIsResourceLimitSet(true);
}
// create Task with ready state and return it. Discovery not needed.
if (systemType.equals(StorageSystem.Type.vmax) || systemType.equals(StorageSystem.Type.vnxblock) || systemType.equals(StorageSystem.Type.hds) || systemType.equals(StorageSystem.Type.openstack) || systemType.equals(StorageSystem.Type.scaleio) || systemType.equals(StorageSystem.Type.xtremio) || systemType.equals(StorageSystem.Type.ceph)) {
// this check is to inform the user that he/she can not update fields other than name and max_resources.
if (param.getIpAddress() != null || param.getPortNumber() != null || param.getUserName() != null || param.getPassword() != null || param.getSmisProviderIP() != null || param.getSmisPortNumber() != null || param.getSmisUserName() != null || param.getSmisPassword() != null || param.getSmisUseSSL() != null) {
throw APIException.badRequests.onlyNameAndMaxResourceCanBeUpdatedForSystemWithType(systemType.name());
}
_dbClient.updateObject(system);
String taskId = UUID.randomUUID().toString();
TaskList taskList = new TaskList();
Operation op = new Operation();
op.ready("Updated Storage System name");
op.setResourceType(ResourceOperationTypeEnum.UPDATE_STORAGE_SYSTEM);
_dbClient.createTaskOpStatus(StorageSystem.class, system.getId(), taskId, op);
taskList.getTaskList().add(toTask(system, taskId, op));
return taskList.getTaskList().listIterator().next();
}
if (systemType.equals(StorageSystem.Type.vnxfile)) {
validateVNXFileSMISProviderMandatoryDetails(param);
}
String existingIPAddress = system.getIpAddress();
Integer existingPortNumber = system.getPortNumber();
// check to ensure a system does not exist with the new ip + port combo
if (((param.getIpAddress() != null && !param.getIpAddress().equals(existingIPAddress)) || (param.getPortNumber() != null && !param.getPortNumber().equals(existingPortNumber)))) {
String ipAddress = (param.getIpAddress() != null) ? param.getIpAddress() : system.getIpAddress();
Integer portNumber = (param.getPortNumber() != null) ? param.getPortNumber() : system.getPortNumber();
if (systemType.equals(StorageSystem.Type.isilon) || systemType.equals(StorageSystem.Type.unity) || systemType.equals(StorageSystem.Type.vnxfile) || systemType.equals(StorageSystem.Type.vnxe)) {
ArgValidator.checkFieldValidInetAddress(ipAddress, "ip_address");
} else {
ArgValidator.checkFieldValidIP(ipAddress, "ip_address");
}
ArgValidator.checkFieldRange(portNumber, 1, 65535, "port_number");
validateStorageSystemExists(ipAddress, portNumber);
system.setMgmtAccessPoint(ipAddress + "-" + portNumber);
}
updateStorageObj(system, param);
auditOp(OperationTypeEnum.UPDATE_STORAGE_SYSTEM, true, null, id.toString(), param.getIpAddress(), param.getPortNumber());
startStorageSystem(system);
// execute discovery
StorageController controller = getController(FileController.class, system.getSystemType());
ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>(1);
String taskId = UUID.randomUUID().toString();
tasks.add(new AsyncTask(StorageSystem.class, system.getId(), taskId));
TaskList taskList = discoverStorageSystems(tasks, controller);
return taskList.getTaskList().listIterator().next();
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class InternalFileResource method releaseFileSystemInternal.
/**
* Release a file system from its current tenant & project for internal object usage
*
* @param id the URN of a ViPR file system to be released
* @return the updated file system
* @throws InternalException
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/release")
public FileShareRestRep releaseFileSystemInternal(@PathParam("id") URI id) throws InternalException {
ArgValidator.checkFieldUriType(id, FileShare.class, "id");
FileShare fs = _fileService.queryResource(id);
// and just return success down at the bottom
if (!fs.checkInternalFlags(Flag.INTERNAL_OBJECT)) {
URI tenantURI = fs.getTenant().getURI();
if (!_permissionsHelper.userHasGivenRole(getUserFromContext(), tenantURI, Role.TENANT_ADMIN)) {
throw APIException.forbidden.onlyAdminsCanReleaseFileSystems(Role.TENANT_ADMIN.toString());
}
// we can't release a fs that has exports
FSExportMap exports = fs.getFsExports();
if ((exports != null) && (!exports.isEmpty())) {
throw APIException.badRequests.cannotReleaseFileSystemExportExists(exports.keySet().toString());
}
// we can't release a fs that has shares
SMBShareMap shares = fs.getSMBFileShares();
if ((shares != null) && (!shares.isEmpty())) {
throw APIException.badRequests.cannotReleaseFileSystemSharesExists(shares.keySet().toString());
}
// files systems with pending operations can't be released
if (fs.getOpStatus() != null) {
for (String opId : fs.getOpStatus().keySet()) {
Operation op = fs.getOpStatus().get(opId);
if (Operation.Status.pending.name().equals(op.getStatus())) {
throw APIException.badRequests.cannotReleaseFileSystemWithTasksPending();
}
}
}
// file systems with snapshots can't be released
Integer snapCount = _fileService.getNumSnapshots(fs);
if (snapCount > 0) {
throw APIException.badRequests.cannotReleaseFileSystemSnapshotExists(snapCount);
}
TenantOrg rootTenant = _permissionsHelper.getRootTenant();
// we can't release the file system to the root tenant if the root tenant has no access
// to the filesystem's virtual pool
ArgValidator.checkFieldNotNull(fs.getVirtualPool(), "virtualPool");
VirtualPool virtualPool = _permissionsHelper.getObjectById(fs.getVirtualPool(), VirtualPool.class);
ArgValidator.checkEntity(virtualPool, fs.getVirtualPool(), false);
if (!_permissionsHelper.tenantHasUsageACL(rootTenant.getId(), virtualPool)) {
throw APIException.badRequests.cannotReleaseFileSystemRootTenantLacksVPoolACL(virtualPool.getId().toString());
}
fs.setOriginalProject(fs.getProject().getURI());
fs.setTenant(new NamedURI(rootTenant.getId(), fs.getLabel()));
fs.setProject(new NamedURI(_internalProject.getId(), fs.getLabel()));
fs.addInternalFlags(INTERNAL_FILESHARE_FLAGS);
_dbClient.updateAndReindexObject(fs);
// audit against the source project, not the new dummy internal project
auditOp(OperationTypeEnum.RELEASE_FILE_SYSTEM, true, null, fs.getId().toString(), fs.getOriginalProject().toString());
}
return map(fs);
}
Aggregations