Search in sources :

Example 21 with Cluster

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

the class ComputeSystemHelper method updateClusterTenant.

/**
 * Updates the Cluster's tenant.
 *
 * @param dbClient DBClient for the database operations.
 * @param dataCenterId data center URI.
 * @param tenantId tenant id to be updated.
 */
private static void updateClusterTenant(DbClient dbClient, URI dataCenterId, URI tenantId) {
    List<NamedElement> clustersUris = listChildren(dbClient, dataCenterId, Cluster.class, "label", "vcenterDataCenter");
    for (NamedElement clusterUri : clustersUris) {
        Cluster cluster = dbClient.queryObject(Cluster.class, clusterUri.getId());
        if (cluster != null) {
            cluster.setTenant(tenantId);
            dbClient.persistObject(cluster);
        }
    }
}
Also used : Cluster(com.emc.storageos.db.client.model.Cluster) NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)

Example 22 with Cluster

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

the class AbstractDiscoveryAdapter method processHostChanges.

public void processHostChanges(List<HostStateChange> changes, List<URI> deletedHosts, List<URI> deletedClusters, boolean isVCenter) {
    log.info("There are " + changes.size() + " changes");
    // Iterate through all host state changes and create states for all of the affected export groups
    for (HostStateChange change : changes) {
        log.info("HostChange: " + change);
        Host host = dbClient.queryObject(Host.class, change.getHost().getId());
        // For every host change (added/removed initiator, cluster change), get all exports that this host
        // currently belongs to
        List<Initiator> newInitiatorObjects = dbClient.queryObject(Initiator.class, change.getNewInitiators());
        List<Initiator> oldInitiatorObjects = dbClient.queryObject(Initiator.class, change.getOldInitiators());
        if (newInitiatorObjects.isEmpty() && !oldInitiatorObjects.isEmpty()) {
            List<URI> hostInitiators = ComputeSystemHelper.getChildrenUris(dbClient, host.getId(), Initiator.class, "host");
            if (hostInitiators.size() == oldInitiatorObjects.size()) {
                log.info("No initiators were re-discovered for host " + host.getId() + " so we will not delete its initiators");
                DiscoveryStatusUtils.markAsFailed(getModelClient(), host, "No initiators were discovered", null);
                continue;
            }
        }
        // 3) If no datacenter or cluster change, make sure we have updated atleast the new datacenter for the host
        if (!NullColumnValueGetter.isNullURI(change.getOldDatacenter()) && !NullColumnValueGetter.isNullURI(change.getNewDatacenter()) && !change.getOldDatacenter().toString().equalsIgnoreCase(change.getNewDatacenter().toString())) {
            VcenterDataCenter oldDatacenter = dbClient.queryObject(VcenterDataCenter.class, change.getOldDatacenter());
            VcenterDataCenter currentDatacenter = dbClient.queryObject(VcenterDataCenter.class, change.getNewDatacenter());
            Cluster cluster = null;
            if (!NullColumnValueGetter.isNullURI(change.getNewCluster())) {
                cluster = dbClient.queryObject(Cluster.class, change.getNewCluster());
            }
            URI oldClusterURI = change.getOldCluster();
            Cluster oldCluster = null;
            if (!NullColumnValueGetter.isNullURI(oldClusterURI)) {
                oldCluster = dbClient.queryObject(Cluster.class, oldClusterURI);
            }
            if (!oldDatacenter.getVcenter().toString().equals(currentDatacenter.getVcenter().toString())) {
                Vcenter oldVcenter = dbClient.queryObject(Vcenter.class, oldDatacenter.getVcenter());
                Vcenter currentVcenter = dbClient.queryObject(Vcenter.class, currentDatacenter.getVcenter());
                EventUtils.createActionableEvent(dbClient, EventUtils.EventCode.HOST_VCENTER_CHANGE, host.getTenant(), ComputeSystemDialogProperties.getMessage("ComputeSystem.hostVcenterChangeLabel", oldVcenter.getLabel(), currentVcenter.getLabel()), ComputeSystemDialogProperties.getMessage("ComputeSystem.hostVcenterChangeDescription", host.getLabel(), oldCluster == null ? "N/A" : oldCluster.getLabel(), cluster == null ? " N/A " : cluster.getLabel()), ComputeSystemDialogProperties.getMessage("ComputeSystem.hostVcenterChangeWarning"), host, Lists.newArrayList(host.getId(), host.getCluster(), cluster == null ? NullColumnValueGetter.getNullURI() : cluster.getId()), EventUtils.hostVcenterChange, new Object[] { host.getId(), cluster != null ? cluster.getId() : NullColumnValueGetter.getNullURI(), currentDatacenter.getId(), isVCenter }, EventUtils.hostVcenterChangeDecline, new Object[] { host.getId(), cluster != null ? cluster.getId() : NullColumnValueGetter.getNullURI(), currentDatacenter.getId(), isVCenter });
            } else {
                EventUtils.createActionableEvent(dbClient, EventUtils.EventCode.HOST_DATACENTER_CHANGE, host.getTenant(), ComputeSystemDialogProperties.getMessage("ComputeSystem.hostDatacenterChangeLabel", oldDatacenter.getLabel(), currentDatacenter.getLabel()), ComputeSystemDialogProperties.getMessage("ComputeSystem.hostDatacenterChangeDescription", host.getLabel(), oldCluster == null ? "N/A" : oldCluster.getLabel(), cluster == null ? " N/A " : cluster.getLabel()), ComputeSystemDialogProperties.getMessage("ComputeSystem.hostDatacenterChangeWarning"), host, Lists.newArrayList(host.getId(), host.getCluster(), cluster == null ? NullColumnValueGetter.getNullURI() : cluster.getId()), EventUtils.hostDatacenterChange, new Object[] { host.getId(), cluster != null ? cluster.getId() : NullColumnValueGetter.getNullURI(), currentDatacenter.getId(), isVCenter }, EventUtils.hostDatacenterChangeDecline, new Object[] { host.getId(), cluster != null ? cluster.getId() : NullColumnValueGetter.getNullURI(), currentDatacenter.getId(), isVCenter });
            }
        } else if ((change.getOldCluster() == null && change.getNewCluster() != null) || (change.getOldCluster() != null && change.getNewCluster() == null) || (change.getOldCluster() != null && change.getNewCluster() != null && !change.getOldCluster().toString().equals(change.getNewCluster().toString()))) {
            Cluster cluster = null;
            if (!NullColumnValueGetter.isNullURI(change.getNewCluster())) {
                cluster = dbClient.queryObject(Cluster.class, change.getNewCluster());
            }
            URI oldClusterURI = change.getOldCluster();
            Cluster oldCluster = null;
            if (!NullColumnValueGetter.isNullURI(oldClusterURI)) {
                oldCluster = dbClient.queryObject(Cluster.class, oldClusterURI);
            }
            boolean oldClusterInUse = oldCluster == null ? false : ComputeSystemHelper.isClusterInExport(dbClient, oldCluster.getId());
            boolean newClusterInUse = cluster == null ? false : ComputeSystemHelper.isClusterInExport(dbClient, cluster.getId());
            if ((cluster != null || oldCluster != null) && (oldClusterInUse || newClusterInUse)) {
                String name = null;
                String description = null;
                if (cluster != null && oldCluster == null) {
                    name = ComputeSystemDialogProperties.getMessage("ComputeSystem.hostClusterChangeAddedLabel", cluster.getLabel());
                    description = ComputeSystemDialogProperties.getMessage("ComputeSystem.hostClusterChangeAddedDescription", host.getLabel(), cluster.getLabel());
                } else if (cluster == null && oldCluster != null) {
                    name = ComputeSystemDialogProperties.getMessage("ComputeSystem.hostClusterChangeRemovedLabel", oldCluster.getLabel());
                    description = ComputeSystemDialogProperties.getMessage("ComputeSystem.hostClusterChangeRemovedDescription", host.getLabel(), oldCluster.getLabel());
                } else {
                    name = ComputeSystemDialogProperties.getMessage("ComputeSystem.hostClusterChangeMovedLabel", oldCluster.getLabel(), cluster.getLabel());
                    description = ComputeSystemDialogProperties.getMessage("ComputeSystem.hostClusterChangeMovedDescription", host.getLabel(), oldCluster.getLabel(), cluster.getLabel());
                }
                EventUtils.createActionableEvent(dbClient, EventUtils.EventCode.HOST_CLUSTER_CHANGE, host.getTenant(), name, description, ComputeSystemDialogProperties.getMessage("ComputeSystem.hostClusterChangeWarning"), host, Lists.newArrayList(host.getId(), host.getCluster(), cluster == null ? NullColumnValueGetter.getNullURI() : cluster.getId()), EventUtils.hostClusterChange, new Object[] { host.getId(), cluster != null ? cluster.getId() : NullColumnValueGetter.getNullURI(), NullColumnValueGetter.isNullURI(change.getNewDatacenter()) ? NullColumnValueGetter.getNullURI() : change.getNewDatacenter(), isVCenter }, EventUtils.hostClusterChangeDecline, new Object[] { host.getId(), cluster != null ? cluster.getId() : NullColumnValueGetter.getNullURI(), NullColumnValueGetter.isNullURI(change.getNewDatacenter()) ? NullColumnValueGetter.getNullURI() : change.getNewDatacenter(), isVCenter });
            } else {
                host.setCluster(cluster == null ? NullColumnValueGetter.getNullURI() : cluster.getId());
                dbClient.updateObject(host);
                ComputeSystemHelper.updateHostAndInitiatorClusterReferences(dbClient, host.getCluster(), host.getId());
                if (cluster != null) {
                    ComputeSystemHelper.updateHostVcenterDatacenterReference(dbClient, host.getId(), cluster != null ? cluster.getVcenterDataCenter() : NullColumnValueGetter.getNullURI());
                }
            }
        } else if (!NullColumnValueGetter.isNullURI(change.getNewDatacenter())) {
            VcenterDataCenter currentDatacenter = dbClient.queryObject(VcenterDataCenter.class, change.getNewDatacenter());
            host.setTenant(currentDatacenter.getTenant());
            host.setVcenterDataCenter(currentDatacenter.getId());
            dbClient.updateObject(host);
        }
        if (ComputeSystemHelper.isHostInUse(dbClient, host.getId())) {
            for (Initiator oldInitiator : oldInitiatorObjects) {
                EventUtils.createActionableEvent(dbClient, EventUtils.EventCode.HOST_INITIATOR_DELETE, host.getTenant(), ComputeSystemDialogProperties.getMessage("ComputeSystem.removeInitiatorLabel", oldInitiator.getInitiatorPort()), ComputeSystemDialogProperties.getMessage("ComputeSystem.removeInitiatorDescription", oldInitiator.getInitiatorPort()), ComputeSystemDialogProperties.getMessage("ComputeSystem.removeInitiatorWarning"), host, Lists.newArrayList(host.getId(), oldInitiator.getId()), EventUtils.removeInitiator, new Object[] { oldInitiator.getId() }, EventUtils.removeInitiatorDecline, new Object[] { oldInitiator.getId() });
            }
            for (Initiator newInitiator : newInitiatorObjects) {
                EventUtils.createActionableEvent(dbClient, EventUtils.EventCode.HOST_INITIATOR_ADD, host.getTenant(), ComputeSystemDialogProperties.getMessage("ComputeSystem.addInitiatorLabel", newInitiator.getInitiatorPort()), ComputeSystemDialogProperties.getMessage("ComputeSystem.addInitiatorDescription", newInitiator.getInitiatorPort()), ComputeSystemDialogProperties.getMessage("ComputeSystem.addInitiatorWarning"), host, Lists.newArrayList(host.getId(), newInitiator.getId()), EventUtils.addInitiator, new Object[] { newInitiator.getId() }, EventUtils.addInitiatorDecline, new Object[] { newInitiator.getId() });
            }
        } else {
            for (Initiator oldInitiator : oldInitiatorObjects) {
                info("Deleting Initiator %s because it was not re-discovered and is not in use by any export groups", oldInitiator.getId());
                dbClient.removeObject(oldInitiator);
            }
        }
    }
    log.info("Number of undiscovered hosts: " + deletedHosts.size());
    Set<URI> incorrectDeletedHosts = Sets.newHashSet();
    for (URI deletedHost : deletedHosts) {
        Host host = dbClient.queryObject(Host.class, deletedHost);
        URI clusterId = host.getCluster();
        List<URI> clusterHosts = Lists.newArrayList();
        if (!NullColumnValueGetter.isNullURI(clusterId)) {
            clusterHosts = ComputeSystemHelper.getChildrenUris(dbClient, clusterId, Host.class, "cluster");
        }
        if (clusterHosts.contains(deletedHost) && deletedHosts.containsAll(clusterHosts)) {
            incorrectDeletedHosts.add(deletedHost);
            DiscoveryStatusUtils.markAsFailed(getModelClient(), host, "Error discovering host cluster", null);
            log.info("Host " + host.getId() + " is part of a cluster that was not re-discovered. Fail discovery and keep the host in our database");
        } else {
            Vcenter vcenter = ComputeSystemHelper.getHostVcenter(dbClient, host);
            EventUtils.createActionableEvent(dbClient, EventUtils.EventCode.UNASSIGN_HOST_FROM_VCENTER, host.getTenant(), ComputeSystemDialogProperties.getMessage("ComputeSystem.hostVcenterUnassignLabel", vcenter == null ? "N/A" : vcenter.getLabel()), ComputeSystemDialogProperties.getMessage("ComputeSystem.hostVcenterUnassignDescription", host.getLabel(), vcenter == null ? "N/A" : vcenter.getLabel()), ComputeSystemDialogProperties.getMessage("ComputeSystem.hostVcenterUnassignWarning"), host, Lists.newArrayList(host.getId(), host.getCluster()), EventUtils.hostVcenterUnassign, new Object[] { deletedHost }, EventUtils.hostVcenterUnassignDecline, new Object[] { deletedHost });
        }
    }
    // delete clusters that don't contain any hosts, don't have any exports, and don't have any pending events
    for (URI clusterId : deletedClusters) {
        List<URI> hostUris = ComputeSystemHelper.getChildrenUris(dbClient, clusterId, Host.class, "cluster");
        if (hostUris.isEmpty() && !ComputeSystemHelper.isClusterInExport(dbClient, clusterId) && EventUtils.findAffectedResourcePendingEvents(dbClient, clusterId).isEmpty()) {
            Cluster cluster = dbClient.queryObject(Cluster.class, clusterId);
            info("Deactivating Cluster: " + clusterId);
            ComputeSystemHelper.doDeactivateCluster(dbClient, cluster);
        } else {
            info("Unable to delete cluster " + clusterId);
        }
    }
}
Also used : Vcenter(com.emc.storageos.db.client.model.Vcenter) Initiator(com.emc.storageos.db.client.model.Initiator) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) DataObject(com.emc.storageos.db.client.model.DataObject) URI(java.net.URI)

Example 23 with Cluster

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

the class AbstractHostDiscoveryAdapter method createNewCluster.

protected URI createNewCluster(URI tenant, String clusterName) {
    Cluster cluster = new Cluster();
    cluster.setLabel(clusterName);
    cluster.setTenant(tenant);
    getModelClient().save(cluster);
    return cluster.getId();
}
Also used : Cluster(com.emc.storageos.db.client.model.Cluster)

Example 24 with Cluster

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

the class ClusterCompleter method complete.

@Override
protected void complete(DbClient dbClient, Status status, ServiceCoded coded) throws DeviceControllerException {
    switch(status) {
        case error:
            dbClient.error(Cluster.class, this.getId(), getOpId(), coded);
            break;
        default:
            dbClient.ready(Cluster.class, this.getId(), getOpId());
    }
    if (deactivateOnComplete && status.equals(Status.ready)) {
        Cluster cluster = dbClient.queryObject(Cluster.class, this.getId());
        ComputeSystemHelper.doDeactivateCluster(dbClient, cluster);
        _logger.info("Deactivating Cluster: " + this.getId());
    }
}
Also used : Cluster(com.emc.storageos.db.client.model.Cluster)

Example 25 with Cluster

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

Aggregations

Cluster (com.emc.storageos.db.client.model.Cluster)67 Host (com.emc.storageos.db.client.model.Host)38 URI (java.net.URI)26 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)20 VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)19 Initiator (com.emc.storageos.db.client.model.Initiator)15 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)15 Path (javax.ws.rs.Path)14 Produces (javax.ws.rs.Produces)14 VcenterControllerException (com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException)13 VcenterObjectConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException)13 VcenterObjectNotFoundException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException)13 ArrayList (java.util.ArrayList)13 Vcenter (com.emc.storageos.db.client.model.Vcenter)12 VcenterServerConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException)11 HashSet (java.util.HashSet)9 MapCluster (com.emc.storageos.api.mapper.functions.MapCluster)8 VcenterApiClient (com.emc.storageos.vcentercontroller.VcenterApiClient)8 GET (javax.ws.rs.GET)8 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)6