Search in sources :

Example 41 with VirtualNAS

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

the class ProjectService method validateVNasServers.

/**
 * Validate VNAS Servers before assign to a project
 *
 * @param project to which VANS servers will be assigned
 * @param param Assign virtual NAS server parameters
 * @param error message
 * @brief Validate VNAS Servers
 * @return List of valid NAS servers
 * @throws BadRequestException
 */
public StringSet validateVNasServers(Project project, VirtualNasParam param, StringBuilder errorMsg) {
    Set<String> vNasIds = param.getVnasServers();
    StringSet validNas = new StringSet();
    boolean shareVNASWithMultipleProjects = Boolean.valueOf(customConfigHandler.getComputedCustomConfigValue(CustomConfigConstants.SHARE_VNAS_WITH_MULTIPLE_PROJECTS, "global", null));
    _log.info("Can vNAS be shared with multiple projects? : {}", shareVNASWithMultipleProjects);
    if (vNasIds != null && !vNasIds.isEmpty() && project != null) {
        // Get list of domains associated with the project
        Set<String> projectDomains = ProjectUtility.getDomainsOfProject(_permissionsHelper, project);
        for (String id : vNasIds) {
            if (project.getAssignedVNasServers().contains(id)) {
                continue;
            }
            URI vnasURI = URI.create(id);
            VirtualNAS vnas = _permissionsHelper.getObjectById(vnasURI, VirtualNAS.class);
            ArgValidator.checkEntity(vnas, vnasURI, isIdEmbeddedInURL(vnasURI));
            // Validate the VNAS is assigned to project!!!
            if (!shareVNASWithMultipleProjects && !vnas.isNotAssignedToProject()) {
                errorMsg.append(" vNas: " + vnas.getNasName() + " is already associated to a project.");
                _log.error(errorMsg.toString());
                continue;
            }
            // Validate the VNAS is in Discovery state -VISIBLE!!!
            if (!DiscoveryStatus.VISIBLE.name().equals(vnas.getDiscoveryStatus())) {
                errorMsg.append(" vNas " + vnas.getNasName() + " is not in Discovery-VISIBLE state ");
                _log.error(errorMsg.toString());
                continue;
            }
            // Validate the VNAS state should be in loaded state !!!
            if (!vnas.getVNasState().equalsIgnoreCase(VirtualNasState.LOADED.getNasState())) {
                errorMsg.append(" vNas " + vnas.getNasName() + " is not in Loaded state");
                _log.error(errorMsg.toString());
                continue;
            }
            // Get list of domains associated with a VNAS server and validate with project's domain
            boolean domainMatched = ProjectUtility.doesProjectDomainMatchesWithVNASDomain(projectDomains, vnas);
            if (!domainMatched) {
                errorMsg.append(" vNas " + vnas.getNasName() + " domain is not matched with project domain");
                _log.error(errorMsg.toString());
                continue;
            }
            if (!shareVNASWithMultipleProjects) {
                /*
                     * Get list of file systems and associated project of VNAS server and validate with Project
                     * If the FS is on a vNAS associated with a project, then validation fails
                     */
                URIQueryResultList fsList = new URIQueryResultList();
                boolean projectMatched = true;
                StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, vnas.getStorageDeviceURI());
                for (String storagePort : vnas.getStoragePorts()) {
                    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getStoragePortFileshareConstraint(URI.create(storagePort)), fsList);
                    Iterator<URI> fsItr = fsList.iterator();
                    while (fsItr.hasNext()) {
                        FileShare fileShare = _dbClient.queryObject(FileShare.class, fsItr.next());
                        if (fileShare != null && !fileShare.getInactive()) {
                            // if fs contain vNAS uri, then compare uri of vNAS assgined to project
                            if (fileShare.getVirtualNAS() != null && 0 == fileShare.getVirtualNAS().compareTo(vnas.getId())) {
                                _log.debug("Validation of assigned vNAS URI: {} and file system path : {} ", fileShare.getVirtualNAS(), fileShare.getPath());
                                if (!fileShare.getProject().getURI().toString().equals(project.getId().toString())) {
                                    projectMatched = false;
                                    break;
                                }
                            } else {
                                // for isilon, if fs don't have vNAS uri, compare fspath with base path of AZ
                                if (storageSystem.getSystemType().equals(StorageSystem.Type.isilon.name())) {
                                    if (fileShare.getPath().startsWith(vnas.getBaseDirPath() + "/") == false) {
                                        continue;
                                    }
                                }
                                _log.debug("Validation of assigned vNAS base path {} and file path : {} ", vnas.getBaseDirPath(), fileShare.getPath());
                                if (!fileShare.getProject().getURI().toString().equals(project.getId().toString())) {
                                    projectMatched = false;
                                    break;
                                }
                            }
                        }
                    }
                    if (!projectMatched) {
                        break;
                    }
                }
                if (!projectMatched) {
                    errorMsg.append(" vNas " + vnas.getNasName() + " has file systems belongs to other project");
                    _log.error(errorMsg.toString());
                    continue;
                }
            }
            validNas.add(id);
        }
    } else {
        throw APIException.badRequests.invalidEntryForProjectVNAS();
    }
    return validNas;
}
Also used : VirtualNAS(com.emc.storageos.db.client.model.VirtualNAS) StringSet(com.emc.storageos.db.client.model.StringSet) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) FileShare(com.emc.storageos.db.client.model.FileShare) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 42 with VirtualNAS

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

the class VirtualNasService method queryResource.

@Override
protected VirtualNAS queryResource(URI id) {
    ArgValidator.checkUri(id);
    VirtualNAS vNas = _dbClient.queryObject(VirtualNAS.class, id);
    ArgValidator.checkEntity(vNas, id, isIdEmbeddedInURL(id));
    return vNas;
}
Also used : VirtualNAS(com.emc.storageos.db.client.model.VirtualNAS)

Example 43 with VirtualNAS

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

the class VirtualNasService method getVirtualNasServer.

/**
 * Gets the details of virtual NAS.
 *
 * @param id the URN of a ViPR virtual NAS.
 *
 * @brief Show virtual NAS
 * @return A VirtualNASRestRep reference specifying the data for the
 *         virtual NAS with the passed id.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public VirtualNASRestRep getVirtualNasServer(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, VirtualNAS.class, "id");
    VirtualNAS vNas = queryResource(id);
    return MapVirtualNas.getInstance(_dbClient).toVirtualNasRestRep(vNas);
}
Also used : VirtualNAS(com.emc.storageos.db.client.model.VirtualNAS) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 44 with VirtualNAS

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

the class VirtualNasService method queryRegisteredResource.

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

Example 45 with VirtualNAS

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

the class StoragePortService method getVirtualNasForStoragePort.

/**
 * It return VirtualNAS for given StoragePort
 *
 * @param sp A reference to the storage port.
 * @return VirtualNAS for a storage Port
 */
private VirtualNAS getVirtualNasForStoragePort(StoragePort sp) {
    URIQueryResultList vNasUriList = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getVirtualNASContainStoragePortConstraint(sp.getId()), vNasUriList);
    Iterator<URI> vNasIter = vNasUriList.iterator();
    while (vNasIter.hasNext()) {
        VirtualNAS vNas = _dbClient.queryObject(VirtualNAS.class, vNasIter.next());
        if (vNas != null && !vNas.getInactive()) {
            return vNas;
        }
    }
    return null;
}
Also used : VirtualNAS(com.emc.storageos.db.client.model.VirtualNAS) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Aggregations

VirtualNAS (com.emc.storageos.db.client.model.VirtualNAS)54 URI (java.net.URI)26 ArrayList (java.util.ArrayList)19 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)18 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)16 StringSet (com.emc.storageos.db.client.model.StringSet)15 PhysicalNAS (com.emc.storageos.db.client.model.PhysicalNAS)9 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)9 List (java.util.List)9 StoragePort (com.emc.storageos.db.client.model.StoragePort)8 URISyntaxException (java.net.URISyntaxException)8 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)7 FileDeviceInputOutput (com.emc.storageos.volumecontroller.FileDeviceInputOutput)7 Project (com.emc.storageos.db.client.model.Project)6 StringMap (com.emc.storageos.db.client.model.StringMap)6 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)6 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)6 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)6 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)6 ControllerException (com.emc.storageos.volumecontroller.ControllerException)6