Search in sources :

Example 1 with Operation

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());
        }
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) BiosCommandResult(com.emc.storageos.volumecontroller.impl.BiosCommandResult) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) Operation(com.emc.storageos.db.client.model.Operation) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)

Example 2 with Operation

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);
}
Also used : MapStoragePort(com.emc.storageos.api.mapper.functions.MapStoragePort) StoragePort(com.emc.storageos.db.client.model.StoragePort) Operation(com.emc.storageos.db.client.model.Operation) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 3 with Operation

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);
}
Also used : MapStoragePortGroup(com.emc.storageos.api.mapper.functions.MapStoragePortGroup) StoragePortGroup(com.emc.storageos.db.client.model.StoragePortGroup) BlockController(com.emc.storageos.volumecontroller.BlockController) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 4 with Operation

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();
}
Also used : TaskList(com.emc.storageos.model.TaskList) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayAffinityAsyncTask(com.emc.storageos.volumecontroller.ArrayAffinityAsyncTask) ArrayList(java.util.ArrayList) Operation(com.emc.storageos.db.client.model.Operation) StorageController(com.emc.storageos.volumecontroller.StorageController) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 5 with Operation

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);
}
Also used : SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) NamedURI(com.emc.storageos.db.client.model.NamedURI) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) Operation(com.emc.storageos.db.client.model.Operation) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) FileShare(com.emc.storageos.db.client.model.FileShare) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Aggregations

Operation (com.emc.storageos.db.client.model.Operation)272 URI (java.net.URI)114 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)105 Path (javax.ws.rs.Path)105 Produces (javax.ws.rs.Produces)103 Volume (com.emc.storageos.db.client.model.Volume)93 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)92 ArrayList (java.util.ArrayList)83 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)70 Consumes (javax.ws.rs.Consumes)70 NamedURI (com.emc.storageos.db.client.model.NamedURI)68 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)68 POST (javax.ws.rs.POST)67 TaskList (com.emc.storageos.model.TaskList)59 FileShare (com.emc.storageos.db.client.model.FileShare)56 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)49 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)40 MapFileShare (com.emc.storageos.api.mapper.functions.MapFileShare)36 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)35 ControllerException (com.emc.storageos.volumecontroller.ControllerException)35