Search in sources :

Example 61 with Host

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

the class ExportService method getListOfInitiators.

private List<Initiator> getListOfInitiators(Connector connector, String tenant_id, String protocol, Volume vol) {
    List<Initiator> initiators = new ArrayList<Initiator>();
    boolean bFound = false;
    if (protocol.equals(Protocol.iSCSI.name())) {
        // this is an iSCSI request
        String port = connector.initiator;
        String hostname = connector.host;
        List<Initiator> iscsi_initiators = new ArrayList<Initiator>();
        Boolean found = searchInDb(port, iscsi_initiators, Protocol.iSCSI.name());
        if (found) {
            initiators.addAll(iscsi_initiators);
        } else {
            // not found, create a new one
            _log.info("Creating new iSCSI initiator, iqn = {}", port);
            // Make sure the port is a valid iSCSI port.
            if (!iSCSIUtility.isValidIQNPortName(port) && !iSCSIUtility.isValidEUIPortName(port))
                throw APIException.badRequests.invalidIscsiInitiatorPort();
            // Find host, and if not found, create new host
            Host host = getHost(hostname, tenant_id);
            // create and populate the initiator
            Initiator initiator = new Initiator();
            initiator.setHost(host.getId());
            initiator.setHostName(connector.host);
            if (!NullColumnValueGetter.isNullURI(host.getCluster())) {
                Cluster cluster = queryObject(Cluster.class, host.getCluster(), false);
                initiator.setClusterName(cluster.getLabel());
            }
            initiator.setId(URIUtil.createId(Initiator.class));
            initiator.setInitiatorPort(port);
            // allows deletion via UI
            initiator.setIsManualCreation(true);
            initiator.setProtocol(HostInterface.Protocol.iSCSI.name());
            addInitiatorToNetwork(initiator, vol);
            ScopedLabelSet tags = new ScopedLabelSet();
            tags.add(new ScopedLabel("openstack", "dynamic"));
            initiator.setTag(tags);
            _dbClient.createObject(initiator);
            initiators.add(initiator);
        }
    } else if (protocol.equals(Protocol.FC.name())) {
        // this is an FC request
        for (String fc_port : connector.wwpns) {
            // See if this initiator exists in our DB
            List<Initiator> fc_initiators = new ArrayList<Initiator>();
            Boolean found = searchInDb(fc_port, fc_initiators, Protocol.FC.name());
            if (found) {
                bFound = true;
                initiators.addAll(fc_initiators);
            } else {
                // not found, we don't create dynamically for FC
                _log.info("FC initiator for wwpn {} not found", fc_port);
            }
        }
        if (!bFound) {
            throw APIException.internalServerErrors.genericApisvcError("Export Failed", new Exception("No FC initiator found for export"));
        }
    } else {
        throw APIException.internalServerErrors.genericApisvcError("Unsupported volume protocol", new Exception("The protocol specified is not supported. The protocols supported are " + Protocol.FC.name() + " and " + Protocol.iSCSI.name()));
    }
    return initiators;
}
Also used : ArrayList(java.util.ArrayList) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) Initiator(com.emc.storageos.db.client.model.Initiator) ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel) ITLRestRepList(com.emc.storageos.model.block.export.ITLRestRepList) List(java.util.List) ArrayList(java.util.ArrayList) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList)

Example 62 with Host

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

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

the class VolumeIngestionUtil method updateExportGroup.

/**
 * Update an ExportGroup.
 *
 * @param exportGroup the ExportGroup to update
 * @param volume a BlockObject for the ExportGroup
 * @param wwnToHluMap the wwn to hlu map
 * @param dbClient a reference to the database client
 * @param allInitiators a List of all initiators for the ExportGroup
 * @param hosts a List of Hosts for the ExportGroup
 * @param cluster a Cluster for the ExportGroup
 */
public static <T extends BlockObject> void updateExportGroup(ExportGroup exportGroup, T volume, Map<String, Integer> wwnToHluMap, DbClient dbClient, List<Initiator> allInitiators, List<Host> hosts, Cluster cluster) {
    for (Host host : hosts) {
        if (null == exportGroup.getHosts() || !exportGroup.getHosts().contains(host.getId().toString())) {
            exportGroup.addHost(host);
        }
    }
    if (null != cluster && (null == exportGroup.getClusters() || !exportGroup.getClusters().contains(cluster.getId().toString()))) {
        exportGroup.addCluster(cluster);
    }
    for (Initiator ini : allInitiators) {
        if (exportGroup.getInitiators() == null || !exportGroup.getInitiators().contains(ini.getId().toString())) {
            exportGroup.addInitiator(ini);
        }
    }
    // Do not add the block object to the export group if it is partially ingested
    if (!volume.checkInternalFlags(Flag.PARTIALLY_INGESTED)) {
        _logger.info("adding volume {} to export group {}", volume.forDisplay(), exportGroup.forDisplay());
        Integer hlu = ExportGroup.LUN_UNASSIGNED;
        if (wwnToHluMap.containsKey(volume.getWWN())) {
            hlu = wwnToHluMap.get(volume.getWWN());
        }
        exportGroup.addVolume(volume.getId(), hlu);
    } else {
        _logger.info("volume {} is partially ingested, so not adding to export group {}", volume.forDisplay(), exportGroup.forDisplay());
    }
    if (volume instanceof Volume) {
        Volume vol = (Volume) volume;
        URI haVarray = checkVplexHighAvailabilityArray(vol, dbClient);
        if (null != haVarray) {
            exportGroup.putAltVirtualArray(volume.getStorageController().toString(), haVarray.toString());
        }
    }
}
Also used : BigInteger(java.math.BigInteger) Initiator(com.emc.storageos.db.client.model.Initiator) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) Volume(com.emc.storageos.db.client.model.Volume) Host(com.emc.storageos.db.client.model.Host) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 64 with Host

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

the class ExternalDeviceExportOperations method createDriverInitiator.

private Initiator createDriverInitiator(com.emc.storageos.db.client.model.Initiator initiator) {
    Initiator driverInitiator = new Initiator();
    driverInitiator.setPort(initiator.getInitiatorPort());
    driverInitiator.setHostName(initiator.getHostName());
    driverInitiator.setClusterName(initiator.getClusterName());
    driverInitiator.setNode(initiator.getInitiatorNode());
    driverInitiator.setProtocol(Initiator.Protocol.valueOf(initiator.getProtocol()));
    driverInitiator.setDisplayName(initiator.getLabel());
    // set host OS type
    driverInitiator.setHostOsType(Initiator.HostOsType.Other);
    Host host = dbClient.queryObject(Host.class, initiator.getHost());
    String hostType = host.getType();
    for (Initiator.HostOsType driverInitiatorHostType : Initiator.HostOsType.values()) {
        if (hostType.equals(driverInitiatorHostType.toString())) {
            driverInitiator.setHostOsType(driverInitiatorHostType);
        }
    }
    log.info("Initiator host OS type {}", driverInitiator.getHostOsType());
    return driverInitiator;
}
Also used : Initiator(com.emc.storageos.storagedriver.model.Initiator) Host(com.emc.storageos.db.client.model.Host)

Example 65 with Host

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

the class CephStorageDevice method mapVolumes.

/**
 * Map volumes to hosts on the hosts themselves.
 *
 * @param storage
 *            [in] - Storage System object
 * @param volumeMap
 *            [in] - Volume URI to Integer LUN map
 * @param initiators
 *            [in] - Collection of Initiator objects
 * @param completer
 *            [in] - TaskCompleter
 */
private void mapVolumes(StorageSystem storage, Map<URI, Integer> volumeMap, Collection<Initiator> initiators, TaskCompleter completer) {
    _log.info("mapVolumes: volumeMap: {}", volumeMap);
    _log.info("mapVolumes: initiators: {}", initiators);
    try {
        for (Map.Entry<URI, Integer> volMapEntry : volumeMap.entrySet()) {
            URI objectUri = volMapEntry.getKey();
            BlockObject object = Volume.fetchExportMaskBlockObject(_dbClient, objectUri);
            String monitorAddress = storage.getSmisProviderIP();
            String monitorUser = storage.getSmisUserName();
            String monitorKey = storage.getSmisPassword();
            RBDMappingOptions rbdOptions = new RBDMappingOptions(object);
            for (Initiator initiator : initiators) {
                Host host = _dbClient.queryObject(Host.class, initiator.getHost());
                if (initiator.getProtocol().equalsIgnoreCase(HostInterface.Protocol.RBD.name())) {
                    _log.info(String.format("mapVolume: host %s pool %s volume %s", host.getHostName(), rbdOptions.poolName, rbdOptions.volumeName));
                    LinuxSystemCLI linuxClient = getLinuxClient(host);
                    linuxClient.mapRBD(monitorAddress, monitorUser, monitorKey, rbdOptions.poolName, rbdOptions.volumeName, rbdOptions.snapshotName);
                } else {
                    String msg = String.format("Unexpected initiator protocol %s, port %s, pool %s, volume %s", initiator.getProtocol(), initiator.getInitiatorPort(), rbdOptions.poolName, rbdOptions.volumeName);
                    ServiceCoded code = DeviceControllerErrors.ceph.operationFailed("mapVolumes", msg);
                    completer.error(_dbClient, code);
                    return;
                }
            }
        }
        completer.ready(_dbClient);
    } catch (Exception e) {
        _log.error("Encountered an exception", e);
        ServiceCoded code = DeviceControllerErrors.ceph.operationFailed("mapVolumes", e.getMessage());
        completer.error(_dbClient, code);
    }
}
Also used : LinuxSystemCLI(com.iwave.ext.linux.LinuxSystemCLI) Initiator(com.emc.storageos.db.client.model.Initiator) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) Host(com.emc.storageos.db.client.model.Host) HashMap(java.util.HashMap) Map(java.util.Map) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Aggregations

Host (com.emc.storageos.db.client.model.Host)227 URI (java.net.URI)104 Initiator (com.emc.storageos.db.client.model.Initiator)52 ArrayList (java.util.ArrayList)49 HashMap (java.util.HashMap)38 Cluster (com.emc.storageos.db.client.model.Cluster)37 HashSet (java.util.HashSet)35 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)33 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)32 VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)26 ComputeElement (com.emc.storageos.db.client.model.ComputeElement)24 Volume (com.emc.storageos.db.client.model.Volume)20 Path (javax.ws.rs.Path)20 Produces (javax.ws.rs.Produces)20 Vcenter (com.emc.storageos.db.client.model.Vcenter)19 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)18 ExportMask (com.emc.storageos.db.client.model.ExportMask)18 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)17 NamedURI (com.emc.storageos.db.client.model.NamedURI)16 StringSet (com.emc.storageos.db.client.model.StringSet)16