Search in sources :

Example 46 with Host

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

the class AbstractDiscoveryAdapter method removeOldHostsFromExport.

protected void removeOldHostsFromExport(URI clusterURI, List<Host> hosts) {
    // update export if host is in use
    if (ComputeSystemHelper.isClusterInExport(dbClient, clusterURI)) {
        String taskId = UUID.randomUUID().toString();
        ComputeSystemController controller = getController(ComputeSystemController.class, null);
        List<URI> hostIds = Lists.newArrayList();
        for (Host host : hosts) {
            hostIds.add(host.getId());
        }
        controller.removeHostsFromExport(hostIds, clusterURI, false, NullColumnValueGetter.getNullURI(), taskId);
    }
}
Also used : ComputeSystemController(com.emc.storageos.computesystemcontroller.ComputeSystemController) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI)

Example 47 with Host

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

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

the class AbstractDiscoveryAdapter method getOrCreateInitiator.

protected Initiator getOrCreateInitiator(URI hostId, List<Initiator> initiators, String port) {
    Initiator initiator = findInitiatorByPort(initiators, port);
    if (initiator == null) {
        initiator = new Initiator();
        initiator.setInitiatorPort(port);
        initiator.setLabel(EndpointUtility.changeCase(port));
    } else {
        initiators.remove(initiator);
    }
    if (!NullColumnValueGetter.isNullURI(initiator.getHost()) && !initiator.getHost().equals(hostId)) {
        Host host = dbClient.queryObject(Host.class, hostId);
        Host initiatorHost = dbClient.queryObject(Host.class, initiator.getHost());
        throw ComputeSystemControllerException.exceptions.illegalInitiator(host != null ? host.forDisplay() : hostId.toString(), initiator.getInitiatorPort(), initiatorHost != null ? initiatorHost.forDisplay() : initiator.getHost().toString());
    }
    initiator.setIsManualCreation(false);
    return initiator;
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) Host(com.emc.storageos.db.client.model.Host)

Example 49 with Host

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

the class AbstractHostDiscoveryAdapter method discoverTarget.

@Override
public void discoverTarget(String targetId) {
    Host host = getModelClient().hosts().findById(targetId);
    HostStateChange changes = new HostStateChange(host, host.getCluster());
    changes.setNewCluster(host.getCluster());
    discoverHost(host, changes);
    processHostChanges(changes);
}
Also used : Host(com.emc.storageos.db.client.model.Host)

Example 50 with Host

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

the class EsxHostDiscoveryAdapter method discoverTarget.

/**
 * (non-Javadoc)
 *
 * @see com.emc.storageos.computesystemcontroller.impl.ComputeSystemDiscoveryAdapter #discoverTarget(java.lang.String)
 */
@Override
public void discoverTarget(String targetId) {
    Host host = getModelClient().hosts().findById(targetId);
    HostStateChange changes = new HostStateChange(host, host.getCluster());
    if (checkHostCredentials(host)) {
        discoverEsxHost(host, changes);
    } else {
        debug("Skipping Esx host discovery, credentials not found for host - %s", host.getHostName());
    }
}
Also used : Host(com.emc.storageos.db.client.model.Host)

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