Search in sources :

Example 6 with RestLinkRep

use of com.emc.storageos.model.RestLinkRep in project coprhd-controller by CoprHD.

the class ExportUtils method createInitiatorTargetRefRep.

/**
 * Creates and returns an instance of REST response object.
 *
 * @param exportGroup the export group the initiator is in
 * @param blockObject the block object
 * @param hlu the lun id used for the block object by the initiator
 * @param initiator the initiator
 * @param port the target port
 * @param fcZoneReference the record of the SAN zone created on the switch when a zone is created.
 *            Returns null when zoning is not required or when the zone creation failed.
 * @return the export REST response object.
 */
private static ITLRestRep createInitiatorTargetRefRep(ExportGroup exportGroup, BlockObject blockObject, String hlu, Initiator initiator, StoragePort port, FCZoneReference fcZoneReference) {
    ITLRestRep rep = new ITLRestRep();
    rep.setHlu(Integer.parseInt(hlu));
    // Set block object
    ITLRestRep.ITLBlockObjectRestRep blockObjectRestRep = new ITLRestRep.ITLBlockObjectRestRep();
    blockObjectRestRep.setId(blockObject.getId());
    blockObjectRestRep.setLink(new RestLinkRep("self", RestLinkFactory.newLink(blockObject)));
    blockObjectRestRep.setWwn(getBlockObjectFormattedWWN(blockObject));
    rep.setBlockObject(blockObjectRestRep);
    // Set initiator
    ITLRestRep.ITLInitiatorRestRep initiatorRestRep = new ITLRestRep.ITLInitiatorRestRep();
    initiatorRestRep.setId(initiator.getId());
    initiatorRestRep.setLink(new RestLinkRep("self", RestLinkFactory.newLink(initiator)));
    initiatorRestRep.setPort(initiator.getInitiatorPort());
    rep.setInitiator(initiatorRestRep);
    // Set storage port
    ITLRestRep.ITLStoragePortRestRep storagePortRestRep = new ITLRestRep.ITLStoragePortRestRep();
    if (port != null) {
        storagePortRestRep.setId(port.getId());
        storagePortRestRep.setLink(new RestLinkRep("self", RestLinkFactory.newLink(port)));
        storagePortRestRep.setPort(port.getPortNetworkId());
        if (port.getIpAddress() != null) {
            storagePortRestRep.setIpAddress(port.getIpAddress());
            storagePortRestRep.setTcpPort(String.valueOf(port.getTcpPortNumber()));
        }
    }
    rep.setStoragePort(storagePortRestRep);
    // Export
    rep.setExport(toNamedRelatedResource(exportGroup, exportGroup.getLabel()));
    if (fcZoneReference != null) {
        rep.setSanZoneName(fcZoneReference.getZoneName());
    }
    return rep;
}
Also used : RestLinkRep(com.emc.storageos.model.RestLinkRep) ITLRestRep(com.emc.storageos.model.block.export.ITLRestRep)

Example 7 with RestLinkRep

use of com.emc.storageos.model.RestLinkRep 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)

Example 8 with RestLinkRep

use of com.emc.storageos.model.RestLinkRep in project coprhd-controller by CoprHD.

the class VirtualPoolMapper method mapVirtualPoolFields.

private static <T extends VirtualPoolCommonRestRep> T mapVirtualPoolFields(VirtualPool from, T to, Map<URI, VpoolProtectionVarraySettings> protectionSettings) {
    mapDataObjectFieldsNoLink(from, to);
    ResourceTypeEnum type = ResourceTypeEnum.BLOCK_VPOOL;
    switch(VirtualPool.Type.valueOf(from.getType())) {
        case block:
            type = ResourceTypeEnum.BLOCK_VPOOL;
            break;
        case file:
            type = ResourceTypeEnum.FILE_VPOOL;
            break;
        case object:
            type = ResourceTypeEnum.OBJECT_VPOOL;
    }
    to.setLink(new RestLinkRep("self", RestLinkFactory.newLink(type, from.getId())));
    to.setType(from.getType());
    to.setDescription(from.getDescription());
    to.setProtocols(from.getProtocols());
    to.setProvisioningType(from.getSupportedProvisioningType());
    to.setNumPaths(from.getNumPaths());
    if (from.getArrayInfo() != null) {
        StringSetMap arrayInfo = from.getArrayInfo();
        // System Type
        StringSet systemTypes = arrayInfo.get(VirtualPoolCapabilityValuesWrapper.SYSTEM_TYPE);
        if (systemTypes != null) {
            // TODO: CD - This does not seem right. Do we support many?
            for (String systemType : systemTypes) {
                to.setSystemType(systemType);
            }
        }
    }
    if (!VdcUtil.isRemoteObject(from)) {
        mapVirtualPoolCommonLocalMappings(from, to);
    }
    return to;
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) ResourceTypeEnum(com.emc.storageos.model.ResourceTypeEnum) RestLinkRep(com.emc.storageos.model.RestLinkRep) StringSet(com.emc.storageos.db.client.model.StringSet)

Example 9 with RestLinkRep

use of com.emc.storageos.model.RestLinkRep in project coprhd-controller by CoprHD.

the class ComputeMapper method map.

/**
 * Utility mapper method to map fields of {@link ComputeImageServer} columnFamily to {@link ComputeImageServerRestRep} rest
 * representation.
 *
 * @param dbclient
 *            {@link DbClient} instance
 * @param from
 *            {@link ComputeImageServer} instance that has to be mapped.
 * @return {@link ComputeImageServerRestRep}
 */
public static ComputeImageServerRestRep map(DbClient dbclient, ComputeImageServer from) {
    if (from == null) {
        return null;
    }
    ComputeImageServerRestRep to = new ComputeImageServerRestRep();
    mapDataObjectFields(from, to);
    try {
        to.setLink(new RestLinkRep("self", RestLinkFactory.simpleServiceLink(ResourceTypeEnum.COMPUTE_IMAGESERVER, from.getId())));
    } catch (URISyntaxException e) {
        LOG.warn("Error while creating self link URI.", e);
    }
    to.setImageServerIp(from.getImageServerIp());
    to.setImageServerSecondIp(from.getImageServerSecondIp());
    to.setTftpBootDir(from.getTftpBootDir());
    to.setComputeImageServerStatus(from.getComputeImageServerStatus());
    to.setImageServerUser(from.getImageServerUser());
    to.setOsInstallTimeout(new Long(TimeUnit.MILLISECONDS.toSeconds(from.getOsInstallTimeoutMs())).intValue());
    to.setSshTimeout(new Long(TimeUnit.MILLISECONDS.toSeconds(from.getSshTimeoutMs())).intValue());
    to.setImageImportTimeout(new Long(TimeUnit.MILLISECONDS.toSeconds(from.getImageImportTimeoutMs())).intValue());
    to.setComputeImages(new ArrayList<NamedRelatedResourceRep>());
    to.setFailedImages(new ArrayList<NamedRelatedResourceRep>());
    if (from.getComputeImages() != null) {
        for (String computeimage : from.getComputeImages()) {
            ComputeImage image = dbclient.queryObject(ComputeImage.class, URIUtil.uri(computeimage));
            if (image == null) {
                LOG.warn("Could not find compute image in database with id '" + computeimage + "'");
                continue;
            }
            to.getComputeImages().add(DbObjectMapper.toNamedRelatedResource(ResourceTypeEnum.COMPUTE_IMAGE, image.getId(), image.getLabel()));
        }
    }
    if (from.getFailedComputeImages() != null) {
        for (String failedImageID : from.getFailedComputeImages()) {
            ComputeImage failedImage = dbclient.queryObject(ComputeImage.class, URIUtil.uri(failedImageID));
            if (failedImage == null) {
                LOG.warn("Could not find failed compute image in database with id '" + failedImageID + "'");
                continue;
            }
            to.getFailedImages().add(DbObjectMapper.toNamedRelatedResource(ResourceTypeEnum.COMPUTE_IMAGE, failedImage.getId(), failedImage.getLabel()));
        }
    }
    return to;
}
Also used : RestLinkRep(com.emc.storageos.model.RestLinkRep) URISyntaxException(java.net.URISyntaxException) NamedRelatedResourceRep(com.emc.storageos.model.NamedRelatedResourceRep) ComputeImageServerRestRep(com.emc.storageos.model.compute.ComputeImageServerRestRep) ComputeImage(com.emc.storageos.db.client.model.ComputeImage)

Example 10 with RestLinkRep

use of com.emc.storageos.model.RestLinkRep in project coprhd-controller by CoprHD.

the class DbObjectMapper method map.

public static CustomConfigRestRep map(CustomConfig from) {
    if (from == null) {
        return null;
    }
    CustomConfigRestRep to = new CustomConfigRestRep();
    to.setLink(new RestLinkRep("self", RestLinkFactory.newLink(from)));
    // build the config type Link
    String service = ResourceTypeEnum.CONFIG_TYPE.getService();
    StringBuilder build = (new StringBuilder(service)).append('/').append(from.getConfigType());
    try {
        RelatedConfigTypeRep type = new RelatedConfigTypeRep();
        type.setConfigName(from.getConfigType());
        type.setSelfLink(new RestLinkRep("self", new URI(build.toString())));
        to.setConfigType(type);
    } catch (URISyntaxException e) {
    // it should not happen
    }
    to.setId(from.getId());
    to.setName(from.getLabel());
    StringMap scopeMap = from.getScope();
    ScopeParam scopeParm = new ScopeParam();
    for (Map.Entry<String, String> entry : scopeMap.entrySet()) {
        scopeParm.setType(entry.getKey());
        scopeParm.setValue(entry.getValue());
    }
    to.setScope(scopeParm);
    to.setValue(from.getValue());
    to.setRegistered(from.getRegistered());
    to.setSystemDefault(from.getSystemDefault());
    return to;
}
Also used : RelatedConfigTypeRep(com.emc.storageos.model.customconfig.RelatedConfigTypeRep) StringMap(com.emc.storageos.db.client.model.StringMap) CustomConfigRestRep(com.emc.storageos.model.customconfig.CustomConfigRestRep) RestLinkRep(com.emc.storageos.model.RestLinkRep) ScopeParam(com.emc.storageos.model.customconfig.ScopeParam) URISyntaxException(java.net.URISyntaxException) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Map(java.util.Map) StringMap(com.emc.storageos.db.client.model.StringMap)

Aggregations

RestLinkRep (com.emc.storageos.model.RestLinkRep)22 URI (java.net.URI)9 SearchResultResourceRep (com.emc.storageos.model.search.SearchResultResourceRep)8 SearchResults (com.emc.storageos.model.search.SearchResults)6 ArrayList (java.util.ArrayList)6 NamedURI (com.emc.storageos.db.client.model.NamedURI)5 NamedRelatedResourceRep (com.emc.storageos.model.NamedRelatedResourceRep)5 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)4 StringMap (com.emc.storageos.db.client.model.StringMap)4 URISyntaxException (java.net.URISyntaxException)4 List (java.util.List)4 BulkList (com.emc.storageos.api.service.impl.response.BulkList)3 ResRepFilter (com.emc.storageos.api.service.impl.response.ResRepFilter)3 SearchedResRepList (com.emc.storageos.api.service.impl.response.SearchedResRepList)2 TimestampedURIQueryResult (com.emc.storageos.db.client.TimestampedURIQueryResult)2 AggregatedConstraint (com.emc.storageos.db.client.constraint.AggregatedConstraint)2 Constraint (com.emc.storageos.db.client.constraint.Constraint)2 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)2 NamedElementQueryResultList (com.emc.storageos.db.client.constraint.NamedElementQueryResultList)2 StringSet (com.emc.storageos.db.client.model.StringSet)2