Search in sources :

Example 46 with VirtualArray

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

the class VirtualArrayService method getVirtualArrayStoragePorts.

/**
 * Returns the storage ports for the VirtualArray with the passed id. When
 * the VirtualArray has been explicitly assigned to one or more storage
 * ports, this API will return the ids of those storage ports. VirtualArrays
 * can be explicitly assigned to storage ports when a storage port is
 * created or later by modifying the storage port after it has been created.
 * <p>
 * Whether or not a VirtualArray has been explicitly assigned to any storage ports the VirtualArray may still have implicit associations
 * with one or more storage port due to the VirtualArray's network connectivity. That is, a network resides in a VirtualArray and may
 * contain storage ports. This implies that these storage ports reside in the VirtualArray. If the VirtualArray has no explicit storage
 * port assignments, but does have implicit associations, the API will instead return those storage ports implicitly associated.
 * <p>
 * The API provides the ability to force the return of the list of storage ports implicitly associated with the VirtualArray using the
 * request parameter "network_connectivity". Passing this parameter with a value of "true" will return the ids of the storage ports
 * implicitly associated with the VirtualArray as described.
 *
 * @param id the URN of a ViPR VirtualArray.
 * @param useNetworkConnectivity true to use the network connectivity to
 *            get the list of storage ports implicitly connected to the
 *            VirtualArray.
 *
 * @brief List VirtualArray storage ports
 * @return The ids of the storage ports associated with the VirtualArray.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/storage-ports")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR }, acls = { ACL.USE })
public StoragePortList getVirtualArrayStoragePorts(@PathParam("id") URI id, @QueryParam("network_connectivity") boolean useNetworkConnectivity) {
    // Get and validate the varray with the passed id.
    ArgValidator.checkFieldUriType(id, VirtualArray.class, "id");
    VirtualArray varray = _dbClient.queryObject(VirtualArray.class, id);
    ArgValidator.checkEntity(varray, id, isIdEmbeddedInURL(id));
    // Query the database for the storage ports associated with the
    // VirtualArray. If the request is for storage ports whose
    // association with the VirtualArray is implicit through network
    // connectivity, then return only these storage ports. Otherwise,
    // the result is for storage ports explicitly assigned to the
    // VirtualArray.
    URIQueryResultList storagePortURIs = new URIQueryResultList();
    if (useNetworkConnectivity) {
        _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getImplicitVirtualArrayStoragePortsConstraint(id.toString()), storagePortURIs);
    } else {
        _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVirtualArrayStoragePortsConstraint(id.toString()), storagePortURIs);
    }
    // Create and return the result.
    StoragePortList storagePorts = new StoragePortList();
    for (URI uri : storagePortURIs) {
        StoragePort storagePort = _dbClient.queryObject(StoragePort.class, uri);
        if ((storagePort != null) && (RegistrationStatus.REGISTERED.toString().equals(storagePort.getRegistrationStatus())) && DiscoveryStatus.VISIBLE.toString().equals(storagePort.getDiscoveryStatus())) {
            storagePorts.getPorts().add(toNamedRelatedResource(storagePort, storagePort.getNativeGuid()));
        }
    }
    return storagePorts;
}
Also used : MapVirtualArray(com.emc.storageos.api.mapper.functions.MapVirtualArray) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) StoragePort(com.emc.storageos.db.client.model.StoragePort) StoragePortList(com.emc.storageos.model.ports.StoragePortList) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 47 with VirtualArray

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

the class VirtualArrayService method getAvailableAttributes.

/**
 * Finds the available attributes & its values in a varray. Ex: In a
 * varray, if a system supports raid_levels such as RAID1, RAID2 then
 * this API call provides the supported information.
 *
 * @param id the URN of a ViPR VirtualArray.
 * @brief List available attributes for VirtualArray
 * @return List available attributes for VirtualArray
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/available-attributes")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public AttributeList getAvailableAttributes(@PathParam("id") URI id) {
    // Get and validate the varray with the passed id.
    ArgValidator.checkFieldUriType(id, VirtualArray.class, "id");
    VirtualArray varray = _dbClient.queryObject(VirtualArray.class, id);
    ArgValidator.checkEntityNotNull(varray, id, isIdEmbeddedInURL(id));
    _log.info("Finding the available attributes for varray: {}", id);
    AttributeList list = new AttributeList();
    list.setVArrayId(id);
    ObjectLocalCache cache = new ObjectLocalCache(_dbClient);
    List<StoragePool> pools = getVirtualArrayPools(Arrays.asList(id), cache).get(id);
    Map<String, Set<String>> availableAttrs = _matcherFramework.getAvailableAttributes(id, pools, cache, AttributeMatcher.VPOOL_MATCHERS);
    cache.clearCache();
    for (Map.Entry<String, Set<String>> entry : availableAttrs.entrySet()) {
        list.getAttributes().add(new VirtualPoolAvailableAttributesResourceRep(entry.getKey(), entry.getValue()));
    }
    return list;
}
Also used : MapVirtualArray(com.emc.storageos.api.mapper.functions.MapVirtualArray) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) StoragePool(com.emc.storageos.db.client.model.StoragePool) Set(java.util.Set) HashSet(java.util.HashSet) StringSet(com.emc.storageos.db.client.model.StringSet) VirtualPoolAvailableAttributesResourceRep(com.emc.storageos.model.vpool.VirtualPoolAvailableAttributesResourceRep) VArrayAttributeList(com.emc.storageos.model.varray.VArrayAttributeList) AttributeList(com.emc.storageos.model.varray.AttributeList) ObjectLocalCache(com.emc.storageos.volumecontroller.impl.utils.ObjectLocalCache) Map(java.util.Map) HashMap(java.util.HashMap) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 48 with VirtualArray

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

the class VirtualArrayService method getVirtualArrayList.

/**
 * List VirtualArrays in zone the user is authorized to see
 *
 * @brief List VirtualArrays in zone
 * @return List of VirtualArrays
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public VirtualArrayList getVirtualArrayList(@DefaultValue("") @QueryParam(VDC_ID_QUERY_PARAM) String shortVdcId, @DefaultValue("") @QueryParam(TENANT_ID_QUERY_PARAM) String tenantId) {
    _geoHelper.verifyVdcId(shortVdcId);
    VirtualArrayList list = new VirtualArrayList();
    TenantOrg tenant_input = null;
    // if input tenant is not empty, but user have no access to it, return empty list.
    if (!StringUtils.isEmpty(tenantId)) {
        tenant_input = getTenantIfHaveAccess(tenantId);
        if (tenant_input == null) {
            return list;
        }
    }
    List<VirtualArray> nhObjList = Collections.emptyList();
    if (_geoHelper.isLocalVdcId(shortVdcId)) {
        _log.debug("retrieving virtual arrays via dbclient");
        final List<URI> ids = _dbClient.queryByType(VirtualArray.class, true);
        nhObjList = _dbClient.queryObject(VirtualArray.class, ids);
    } else {
        _log.debug("retrieving virtual arrays via geoclient");
        try {
            GeoServiceClient geoClient = _geoHelper.getClient(shortVdcId);
            final List<URI> ids = Lists.newArrayList(geoClient.queryByType(VirtualArray.class, true));
            nhObjList = Lists.newArrayList(geoClient.queryObjects(VirtualArray.class, ids));
        } catch (Exception ex) {
            // TODO: revisit this exception
            _log.error("error retrieving virtual arrays", ex);
            throw APIException.internalServerErrors.genericApisvcError("error retrieving virtual arrays", ex);
        }
    }
    StorageOSUser user = getUserFromContext();
    // else only return the list, which input tenant has access.
    if (_permissionsHelper.userHasGivenRole(user, null, Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR)) {
        for (VirtualArray nh : nhObjList) {
            if (tenant_input == null || _permissionsHelper.tenantHasUsageACL(tenant_input.getId(), nh)) {
                list.getVirtualArrays().add(toNamedRelatedResource(ResourceTypeEnum.VARRAY, nh.getId(), nh.getLabel()));
            }
        }
    } else {
        // otherwise, filter by only authorized to use
        URI tenant = null;
        if (tenant_input == null) {
            tenant = URI.create(user.getTenantId());
        } else {
            tenant = tenant_input.getId();
        }
        Set<VirtualArray> varraySet = new HashSet<VirtualArray>();
        for (VirtualArray virtualArray : nhObjList) {
            if (_permissionsHelper.tenantHasUsageACL(tenant, virtualArray)) {
                varraySet.add(virtualArray);
            }
        }
        // if no tenant specified in request, also adding varrays which sub-tenants of the user have access to.
        if (tenant_input == null) {
            List<URI> subtenants = _permissionsHelper.getSubtenantsWithRoles(user);
            for (VirtualArray virtualArray : nhObjList) {
                if (_permissionsHelper.tenantHasUsageACL(subtenants, virtualArray)) {
                    varraySet.add(virtualArray);
                }
            }
        }
        for (VirtualArray virtualArray : varraySet) {
            list.getVirtualArrays().add(toNamedRelatedResource(ResourceTypeEnum.VARRAY, virtualArray.getId(), virtualArray.getLabel()));
        }
    }
    return list;
}
Also used : MapVirtualArray(com.emc.storageos.api.mapper.functions.MapVirtualArray) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) VirtualArrayList(com.emc.storageos.model.varray.VirtualArrayList) GeoServiceClient(com.emc.storageos.security.geo.GeoServiceClient) URI(java.net.URI) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) HashSet(java.util.HashSet) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 49 with VirtualArray

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

the class VirtualArrayService method updateVirtualArray.

/**
 * @brief Update VirtualArray
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
@Path("/{id}")
public VirtualArrayRestRep updateVirtualArray(@PathParam("id") URI id, VirtualArrayUpdateParam param) {
    VirtualArray varray = queryResource(id);
    if (param.getLabel() != null && !param.getLabel().isEmpty()) {
        if (!varray.getLabel().equalsIgnoreCase(param.getLabel())) {
            // check for active VirtualArray with same name
            checkDuplicateLabel(VirtualArray.class, param.getLabel());
        }
        varray.setLabel(param.getLabel());
    }
    if (param.getBlockSettings().getAutoSanZoning() != null) {
        varray.setAutoSanZoning(param.getBlockSettings().getAutoSanZoning());
    }
    if (param.getObjectSettings().getProtectionType() != null) {
        varray.setProtectionType(param.getObjectSettings().getProtectionType());
    }
    _dbClient.persistObject(varray);
    auditOp(OperationTypeEnum.UPDATE_VARRAY, true, null, id.toString(), param.getLabel(), varray.getAutoSanZoning().toString());
    return map(varray);
}
Also used : MapVirtualArray(com.emc.storageos.api.mapper.functions.MapVirtualArray) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) 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 50 with VirtualArray

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

the class VirtualArrayService method getOtherSearchResults.

/**
 * Finds the virtual arrays for the initiator port with the passed
 * identifier and returns the id, name, and self link for those virtual
 * arrays. This API only supports fiber channel and iSCSI initiator ports,
 * and the passed port identifier must be the WWN or IQN of the port.
 *
 * Note that in order for an initiator to be associated with any virtual,
 * arrays it must be in an active network. The virtual arrays for the passed
 * initiator are those active virtual arrays associated with the storage
 * ports in the initiator's active network. If the initiator is not in a
 * network, an empty list is returned.
 *
 * parameter: 'initiator_port' The identifier of the initiator port.
 *
 * @param parameters The search parameters.
 * @param authorized Whether or not the caller is authorized.
 *
 * @return The search results specifying the virtual arrays for the
 *         initiator identified in the passed search parameters.
 */
@Override
protected SearchResults getOtherSearchResults(Map<String, List<String>> parameters, boolean authorized) {
    SearchResults result = new SearchResults();
    String[] searchCriteria = { SEARCH_INITIATOR_PORT, SEARCH_HOST, SEARCH_CLUSTER };
    validateSearchParameters(parameters, searchCriteria);
    Set<String> varrayIds = new HashSet<String>();
    for (Map.Entry<String, List<String>> entry : parameters.entrySet()) {
        if (entry.getKey().equals(SEARCH_INITIATOR_PORT)) {
            String initiatorId = parameters.get(SEARCH_INITIATOR_PORT).get(0);
            // Validate the user passed a value for the initiator port.
            ArgValidator.checkFieldNotEmpty(initiatorId, SEARCH_INITIATOR_PORT);
            // Validate the format of the passed initiator port.
            if (!EndpointUtility.isValidEndpoint(initiatorId, EndpointType.ANY)) {
                throw APIException.badRequests.initiatorPortNotValid();
            }
            _log.info("Searching for virtual arrays for initiator {}", initiatorId);
            varrayIds.addAll(ConnectivityUtil.getInitiatorVarrays(initiatorId, _dbClient));
            break;
        } else if (entry.getKey().equals(SEARCH_HOST)) {
            // find and validate host
            String hostId = parameters.get(SEARCH_HOST).get(0);
            URI hostUri = URI.create(hostId);
            ArgValidator.checkFieldNotEmpty(hostId, SEARCH_HOST);
            Host host = queryObject(Host.class, hostUri, false);
            verifyAuthorizedInTenantOrg(host.getTenant(), getUserFromContext());
            _log.info("looking for virtual arrays connected to host " + host.getHostName());
            varrayIds.addAll(getVarraysForHost(hostUri));
            break;
        } else if (entry.getKey().equals(SEARCH_CLUSTER)) {
            // find and validate cluster
            String clusterId = parameters.get(SEARCH_CLUSTER).get(0);
            URI clusterUri = URI.create(clusterId);
            ArgValidator.checkFieldNotEmpty(clusterId, SEARCH_CLUSTER);
            Cluster cluster = queryObject(Cluster.class, clusterUri, false);
            verifyAuthorizedInTenantOrg(cluster.getTenant(), getUserFromContext());
            _log.info("looking for virtual arrays connected to cluster " + cluster.getLabel());
            List<Set<String>> hostVarraySets = new ArrayList<Set<String>>();
            List<NamedElementQueryResultList.NamedElement> dataObjects = listChildren(clusterUri, Host.class, "label", "cluster");
            for (NamedElementQueryResultList.NamedElement dataObject : dataObjects) {
                Set<String> hostVarrays = getVarraysForHost(dataObject.getId());
                hostVarraySets.add(hostVarrays);
            }
            boolean first = true;
            for (Set<String> varrays : hostVarraySets) {
                if (first) {
                    varrayIds.addAll(varrays);
                    first = false;
                } else {
                    varrayIds.retainAll(varrays);
                }
            }
            break;
        }
    }
    // For each virtual array in the set create a search result
    // and add it to the search results list.
    List<SearchResultResourceRep> searchResultList = new ArrayList<SearchResultResourceRep>();
    if (!varrayIds.isEmpty()) {
        for (String varrayId : varrayIds) {
            URI varrayURI = URI.create(varrayId);
            VirtualArray varray = _dbClient.queryObject(VirtualArray.class, varrayURI);
            // Filter out those that are inactive or not accessible to the user.
            if (varray == null || varray.getInactive()) {
                _log.info("Could not find virtual array {} in the database, or " + "the virtual array is inactive", varrayURI);
                continue;
            }
            if (!authorized) {
                if (!_permissionsHelper.tenantHasUsageACL(URI.create(getUserFromContext().getTenantId()), varray)) {
                    _log.info("Virtual array {} is not accessible.", varrayURI);
                    continue;
                }
            }
            RestLinkRep selfLink = new RestLinkRep("self", RestLinkFactory.newLink(getResourceType(), varrayURI));
            SearchResultResourceRep searchResult = new SearchResultResourceRep(varrayURI, selfLink, varray.getLabel());
            searchResultList.add(searchResult);
        }
    }
    result.setResource(searchResultList);
    return result;
}
Also used : MapVirtualArray(com.emc.storageos.api.mapper.functions.MapVirtualArray) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) Set(java.util.Set) HashSet(java.util.HashSet) StringSet(com.emc.storageos.db.client.model.StringSet) SearchResultResourceRep(com.emc.storageos.model.search.SearchResultResourceRep) ArrayList(java.util.ArrayList) VirtualArrayList(com.emc.storageos.model.varray.VirtualArrayList) RestLinkRep(com.emc.storageos.model.RestLinkRep) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) SearchResults(com.emc.storageos.model.search.SearchResults) URI(java.net.URI) StoragePortGroupRestRepList(com.emc.storageos.model.portgroup.StoragePortGroupRestRepList) VArrayAttributeList(com.emc.storageos.model.varray.VArrayAttributeList) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) StoragePortList(com.emc.storageos.model.ports.StoragePortList) ArrayList(java.util.ArrayList) StoragePoolList(com.emc.storageos.model.pools.StoragePoolList) VirtualArrayConnectivityList(com.emc.storageos.model.varray.VirtualArrayConnectivityList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) VirtualArrayList(com.emc.storageos.model.varray.VirtualArrayList) AttributeList(com.emc.storageos.model.varray.AttributeList) List(java.util.List) AutoTierPolicyList(com.emc.storageos.model.block.tier.AutoTierPolicyList) BulkList(com.emc.storageos.api.service.impl.response.BulkList) VirtualPoolList(com.emc.storageos.model.vpool.VirtualPoolList) NetworkList(com.emc.storageos.model.varray.NetworkList) Map(java.util.Map) HashMap(java.util.HashMap) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) HashSet(java.util.HashSet)

Aggregations

VirtualArray (com.emc.storageos.db.client.model.VirtualArray)183 URI (java.net.URI)91 ArrayList (java.util.ArrayList)91 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)84 Project (com.emc.storageos.db.client.model.Project)53 NamedURI (com.emc.storageos.db.client.model.NamedURI)52 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)52 StringSet (com.emc.storageos.db.client.model.StringSet)50 Volume (com.emc.storageos.db.client.model.Volume)46 VirtualPoolCapabilityValuesWrapper (com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper)44 List (java.util.List)44 StoragePool (com.emc.storageos.db.client.model.StoragePool)43 HashMap (java.util.HashMap)38 StringMap (com.emc.storageos.db.client.model.StringMap)37 Recommendation (com.emc.storageos.volumecontroller.Recommendation)37 RPRecommendation (com.emc.storageos.volumecontroller.RPRecommendation)31 RPProtectionRecommendation (com.emc.storageos.volumecontroller.RPProtectionRecommendation)30 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)29 Network (com.emc.storageos.db.client.model.Network)27 VPlexRecommendation (com.emc.storageos.volumecontroller.VPlexRecommendation)27