Search in sources :

Example 91 with StorageSystem

use of com.emc.storageos.db.client.model.StorageSystem 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 92 with StorageSystem

use of com.emc.storageos.db.client.model.StorageSystem in project coprhd-controller by CoprHD.

the class StorageSystemService method getAllStoragePortGroups.

/**
 * Get all storage port groups for the storage system with the passed id.
 *
 * @param id
 *            the URN of a ViPR storage system.
 *
 * @brief List storage system storage port groups
 * @return A reference to a StoragePortGroupList specifying the id and self link
 *         for each port group.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/storage-port-groups")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public StoragePortGroupList getAllStoragePortGroups(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, StorageSystem.class, "id");
    StorageSystem system = queryResource(id);
    ArgValidator.checkEntity(system, id, isIdEmbeddedInURL(id));
    URIQueryResultList portGroupURIs = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getStorageDevicePortGroupConstraint(id), portGroupURIs);
    StoragePortGroupList portList = new StoragePortGroupList();
    Iterator<URI> portGroupIter = portGroupURIs.iterator();
    while (portGroupIter.hasNext()) {
        URI pgURI = portGroupIter.next();
        StoragePortGroup portGroup = _dbClient.queryObject(StoragePortGroup.class, pgURI);
        if (portGroup != null && !portGroup.getInactive() && !portGroup.checkInternalFlags(Flag.INTERNAL_OBJECT)) {
            portList.getPortGroups().add(toNamedRelatedResource(portGroup, portGroup.getNativeGuid()));
        }
    }
    return portList;
}
Also used : StoragePortGroupList(com.emc.storageos.model.portgroup.StoragePortGroupList) MapStoragePortGroup(com.emc.storageos.api.mapper.functions.MapStoragePortGroup) StoragePortGroup(com.emc.storageos.db.client.model.StoragePortGroup) 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) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 93 with StorageSystem

use of com.emc.storageos.db.client.model.StorageSystem in project coprhd-controller by CoprHD.

the class StorageSystemService method createStorageSystem.

/**
 * Manually create a storage system that cannot be discovered using a SMI-S provider. By
 * default the storage system will be auto-registered upon its creation.
 * For the Block type storage system, the method would add a new system to the SMIS provider.
 * The SMIS provider field in the input parameter file is ignored for file type storage systems
 * (VNX file and Isilon )
 *
 * @param param The storage system details.
 * @prereq none
 * @brief Create storage system
 * @return An asynchronous task corresponding to the discovery job scheduled for the new Storage System.
 *
 * @throws BadRequestException When the system type is not valid or a
 *             storage system with the same native guid already exists.
 * @throws DatabaseException When an error occurs querying the database.
 * @throws ControllerException When an error occurs discovering the storage
 *             system.
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep createStorageSystem(StorageSystemRequestParam param) throws Exception {
    if (!isControllerServiceOnline()) {
        _log.error("Controller services are not started yet");
        throw APIException.serviceUnavailable.controllerServiceUnavailable();
    }
    ArgValidator.checkFieldNotEmpty(param.getSystemType(), "system_type");
    if (!StorageSystem.Type.isDriverManagedStorageSystem(param.getSystemType())) {
        ArgValidator.checkFieldValueFromSystemType(param.getSystemType(), "system_type", Arrays.asList(StorageSystem.Type.vnxfile, StorageSystem.Type.isilon, StorageSystem.Type.rp, StorageSystem.Type.netapp, StorageSystem.Type.netappc, StorageSystem.Type.vnxe, StorageSystem.Type.xtremio, StorageSystem.Type.ecs, StorageSystem.Type.unity, StorageSystem.Type.hp3par));
    }
    StorageSystem.Type systemType = StorageSystem.Type.valueOf(param.getSystemType());
    if (systemType.equals(StorageSystem.Type.vnxfile)) {
        validateVNXFileSMISProviderMandatoryDetails(param);
    }
    ArgValidator.checkFieldNotEmpty(param.getName(), "name");
    checkForDuplicateName(param.getName(), StorageSystem.class);
    if (systemType.equals(StorageSystem.Type.isilon) || systemType.equals(StorageSystem.Type.unity) || systemType.equals(StorageSystem.Type.vnxfile)) {
        ArgValidator.checkFieldValidInetAddress(param.getIpAddress(), "ip_address");
    } else {
        ArgValidator.checkFieldValidIP(param.getIpAddress(), "ip_address");
    }
    ArgValidator.checkFieldNotNull(param.getPortNumber(), "port_number");
    ArgValidator.checkFieldRange(param.getPortNumber(), 1, 65535, "port_number");
    validateStorageSystemExists(param.getIpAddress(), param.getPortNumber());
    StorageSystem system = prepareStorageSystem(param);
    auditOp(OperationTypeEnum.CREATE_STORAGE_SYSTEM, true, null, param.getSerialNumber(), param.getSystemType(), param.getIpAddress(), param.getPortNumber());
    startStorageSystem(system);
    // Rather if else everywhere some code duplication with object and file
    if (StorageSystem.Type.ecs.toString().equals(system.getSystemType())) {
        ObjectController controller = getController(ObjectController.class, param.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();
    } else {
        FileController controller = getController(FileController.class, param.getSystemType());
        ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>(1);
        String taskId = UUID.randomUUID().toString();
        tasks.add(new AsyncTask(StorageSystem.class, system.getId(), taskId));
        /**
         * Creates MonitoringJob token on ZooKeeper for vnxfile/isilon device.
         * Currently we are handling monitoring for vnxfile/vmax/vnxblock/isilon devices.
         * We should not create MonitoringJob token for netapp/rp now.
         */
        if (StorageSystem.Type.vnxfile.toString().equals(system.getSystemType()) || StorageSystem.Type.isilon.toString().equals(system.getSystemType())) {
            controller.startMonitoring(new AsyncTask(StorageSystem.class, system.getId(), taskId), StorageSystem.Type.valueOf(system.getSystemType()));
        }
        TaskList taskList = discoverStorageSystems(tasks, controller);
        return taskList.getTaskList().listIterator().next();
    }
}
Also used : ObjectController(com.emc.storageos.volumecontroller.ObjectController) TaskList(com.emc.storageos.model.TaskList) FileController(com.emc.storageos.volumecontroller.FileController) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayAffinityAsyncTask(com.emc.storageos.volumecontroller.ArrayAffinityAsyncTask) ArrayList(java.util.ArrayList) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 94 with StorageSystem

use of com.emc.storageos.db.client.model.StorageSystem in project coprhd-controller by CoprHD.

the class StorageSystemService method getVnasServers.

/**
 * Gets all virtual NAS for the registered storage system with the passed
 * id.
 *
 * @param id the URN of a ViPR storage system.
 *
 * @brief List storage system virtual nas servers
 * @return A reference to a StoragePooList specifying the id and self link
 *         for each storage pool.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/vnasservers")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public VirtualNASList getVnasServers(@PathParam("id") URI id) {
    // Make sure storage system is registered.
    ArgValidator.checkFieldUriType(id, StorageSystem.class, "id");
    StorageSystem system = queryResource(id);
    ArgValidator.checkEntity(system, id, isIdEmbeddedInURL(id));
    VirtualNASList vNasList = new VirtualNASList();
    URIQueryResultList vNasURIs = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getStorageDeviceVirtualNasConstraint(id), vNasURIs);
    Iterator<URI> vNasIter = vNasURIs.iterator();
    while (vNasIter.hasNext()) {
        URI vNasURI = vNasIter.next();
        VirtualNAS vNas = _dbClient.queryObject(VirtualNAS.class, vNasURI);
        if (vNas != null && !vNas.getInactive()) {
            vNasList.getVNASServers().add(toNamedRelatedResource(vNas, vNas.getNativeGuid()));
        }
    }
    return vNasList;
}
Also used : VirtualNASList(com.emc.storageos.model.vnas.VirtualNASList) VirtualNAS(com.emc.storageos.db.client.model.VirtualNAS) 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) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 95 with StorageSystem

use of com.emc.storageos.db.client.model.StorageSystem in project coprhd-controller by CoprHD.

the class StorageSystemService method queryRegisteredSystem.

/**
 * Gets the storage system with the passed id from the database.
 *
 * @param id the URN of a ViPR storage system
 *
 * @return A reference to the registered StorageSystem.
 *
 * @throws ServiceCodeException When the storage system is not
 *             registered.
 */
protected StorageSystem queryRegisteredSystem(URI id) {
    ArgValidator.checkUri(id);
    StorageSystem system = _dbClient.queryObject(StorageSystem.class, id);
    ArgValidator.checkEntityNotNull(system, id, isIdEmbeddedInURL(id));
    if (!RegistrationStatus.REGISTERED.toString().equalsIgnoreCase(system.getRegistrationStatus())) {
        throw APIException.badRequests.resourceNotRegistered(StorageSystem.class.getSimpleName(), id);
    }
    return system;
}
Also used : StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

StorageSystem (com.emc.storageos.db.client.model.StorageSystem)1088 URI (java.net.URI)581 ArrayList (java.util.ArrayList)424 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)319 Volume (com.emc.storageos.db.client.model.Volume)299 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)272 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)258 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)246 NamedURI (com.emc.storageos.db.client.model.NamedURI)243 WorkflowException (com.emc.storageos.workflow.WorkflowException)233 ControllerException (com.emc.storageos.volumecontroller.ControllerException)231 HashMap (java.util.HashMap)172 StoragePool (com.emc.storageos.db.client.model.StoragePool)159 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)158 StringSet (com.emc.storageos.db.client.model.StringSet)156 URISyntaxException (java.net.URISyntaxException)145 List (java.util.List)139 IOException (java.io.IOException)136 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)127 Workflow (com.emc.storageos.workflow.Workflow)126