Search in sources :

Example 51 with Initiator

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

the class AbstractDiscoveryAdapter method removeOldInitiatorFromExport.

protected void removeOldInitiatorFromExport(Host host, List<Initiator> oldInitiators) {
    // update export if host is in use
    if (!oldInitiators.isEmpty() && ComputeSystemHelper.isHostInUse(dbClient, host.getId())) {
        String taskId = UUID.randomUUID().toString();
        ComputeSystemController controller = getController(ComputeSystemController.class, null);
        List<URI> uris = Lists.newArrayList();
        for (Initiator initiator : oldInitiators) {
            uris.add(initiator.getId());
        }
        controller.removeInitiatorsFromExport(host.getId(), uris, taskId);
    }
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) ComputeSystemController(com.emc.storageos.computesystemcontroller.ComputeSystemController) URI(java.net.URI)

Example 52 with Initiator

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

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

the class AbstractDiscoveryAdapter method removeInitiators.

protected void removeInitiators(Iterable<Initiator> initiators) {
    for (Initiator initiator : initiators) {
        initiator.setHost(NullColumnValueGetter.getNullURI());
        initiator.setHostName("");
        initiator.setClusterName("");
        save(initiator);
    }
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator)

Example 54 with Initiator

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

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

the class AixHostDiscoveryAdapter method discoverInitiators.

@Override
protected void discoverInitiators(Host host, List<Initiator> oldInitiators, HostStateChange changes) {
    AixSystem aix = getCli(host);
    List<Initiator> addedInitiators = Lists.newArrayList();
    try {
        for (HBAInfo hba : aix.listInitiators()) {
            Initiator initiator;
            String wwpn = SanUtils.normalizeWWN(hba.getWwpn());
            if (findInitiatorByPort(oldInitiators, wwpn) == null) {
                initiator = getOrCreateInitiator(host.getId(), oldInitiators, wwpn);
                addedInitiators.add(initiator);
            } else {
                initiator = getOrCreateInitiator(host.getId(), oldInitiators, wwpn);
            }
            discoverFCInitiator(host, initiator, hba);
        }
    } catch (DeviceControllerException e) {
        throw e;
    } catch (Exception e) {
        LOG.error("Failed to list FC Ports, skipping");
    }
    try {
        for (String iqn : aix.listIQNs()) {
            Initiator initiator;
            if (findInitiatorByPort(oldInitiators, iqn) == null) {
                initiator = getOrCreateInitiator(host.getId(), oldInitiators, iqn);
                addedInitiators.add(initiator);
            } else {
                initiator = getOrCreateInitiator(host.getId(), oldInitiators, iqn);
            }
            discoverISCSIInitiator(host, initiator, iqn);
        }
    } catch (DeviceControllerException e) {
        throw e;
    } catch (Exception e) {
        LOG.error("Failed to list iSCSI Ports, skipping");
    }
    // update export groups with new initiators if host is in use.
    if (!addedInitiators.isEmpty()) {
        Collection<URI> addedInitiatorIds = Lists.newArrayList(Collections2.transform(addedInitiators, CommonTransformerFunctions.fctnDataObjectToID()));
        changes.setNewInitiators(addedInitiatorIds);
    }
}
Also used : HBAInfo(com.iwave.ext.linux.model.HBAInfo) Initiator(com.emc.storageos.db.client.model.Initiator) AixSystem(com.emc.aix.AixSystem) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) URI(java.net.URI) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) CommandException(com.iwave.ext.command.CommandException) JSchException(com.jcraft.jsch.JSchException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)

Aggregations

Initiator (com.emc.storageos.db.client.model.Initiator)487 URI (java.net.URI)345 ArrayList (java.util.ArrayList)266 HashMap (java.util.HashMap)170 HashSet (java.util.HashSet)161 ExportMask (com.emc.storageos.db.client.model.ExportMask)156 List (java.util.List)119 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)102 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)98 Map (java.util.Map)85 StringSet (com.emc.storageos.db.client.model.StringSet)83 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)82 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)81 StoragePort (com.emc.storageos.db.client.model.StoragePort)78 NamedURI (com.emc.storageos.db.client.model.NamedURI)73 Set (java.util.Set)72 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)58 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)57 StringMap (com.emc.storageos.db.client.model.StringMap)55 Host (com.emc.storageos.db.client.model.Host)54