use of com.emc.storageos.db.client.model.ActionableEvent in project coprhd-controller by CoprHD.
the class AbstractDiscoveryAdapter method processHostChanges.
@SuppressWarnings("unchecked")
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()) && (!oldInitiatorObjects.isEmpty() || !newInitiatorObjects.isEmpty())) {
ActionableEvent duplicateEvent = EventUtils.getDuplicateEvent(dbClient, EventUtils.EventCode.HOST_INITIATOR_UPDATES.getCode(), host.getId(), null);
List<URI> duplicateEventAddInitiators = Lists.newArrayList();
List<URI> duplicateEventRemoveInitiators = Lists.newArrayList();
if (duplicateEvent != null) {
info("Found duplicate event %s for %s to update initiators", duplicateEvent.forDisplay(), host.forDisplay());
ActionableEvent.Method eventMethod = ActionableEvent.Method.deserialize(duplicateEvent.getApproveMethod());
if (eventMethod == null) {
log.info("Event method is null or empty for event " + duplicateEvent.getId());
} else if (eventMethod.getArgs() == null) {
log.info("Event method arguments are null for event " + duplicateEvent.getId());
} else {
// Parameters for updateInitiators are hostId, addInitiatorIds, removeInitiatorIds
Object[] parameters = eventMethod.getArgs();
if (parameters != null && parameters.length == EventUtils.UPDATE_INITIATORS_METHOD_PARAMETERS) {
duplicateEventAddInitiators = (List<URI>) parameters[EventUtils.UPDATE_INITIATORS_METHOD_ADD_INITIATOR_INDEX];
duplicateEventRemoveInitiators = (List<URI>) parameters[EventUtils.UPDATE_INITIATORS_METHOD_REMOVE_INITIATOR_INDEX];
}
}
}
// if there are old HOST_INITIATOR_DELETE events for the same deleted initiators, then mark those events as declined
if (oldInitiatorObjects != null) {
for (Initiator initiator : oldInitiatorObjects) {
List<ActionableEvent> hostEvents = EventUtils.findAffectedResourcePendingEvents(dbClient, initiator.getId());
for (ActionableEvent hostEvent : hostEvents) {
if (hostEvent.getEventCode().equals(EventCode.HOST_INITIATOR_DELETE.getCode())) {
hostEvent.setEventStatus(ActionableEvent.Status.system_declined.name());
log.info("Marking old initiator delete event " + hostEvent.forDisplay() + " as system declined because we will merge it with a batched initiator event");
dbClient.updateObject(hostEvent);
}
}
}
}
newInitiatorObjects.addAll(dbClient.queryObject(Initiator.class, duplicateEventAddInitiators));
oldInitiatorObjects.addAll(dbClient.queryObject(Initiator.class, duplicateEventRemoveInitiators));
Set<String> oldInitiatorPorts = Sets.newHashSet();
Set<String> newInitiatorPorts = Sets.newHashSet();
Set<URI> oldInitiatorIds = Sets.newHashSet();
Set<URI> newInitiatorIds = Sets.newHashSet();
for (Initiator oldInitiator : oldInitiatorObjects) {
oldInitiatorPorts.add(oldInitiator.getInitiatorPort());
oldInitiatorIds.add(oldInitiator.getId());
}
for (Initiator newInitiator : newInitiatorObjects) {
newInitiatorPorts.add(newInitiator.getInitiatorPort());
newInitiatorIds.add(newInitiator.getId());
}
List<URI> allAffectedResources = Lists.newArrayList();
allAffectedResources.add(host.getId());
allAffectedResources.addAll(newInitiatorIds);
allAffectedResources.addAll(oldInitiatorIds);
String name = ComputeSystemDialogProperties.getMessage("ComputeSystem.updateInitiatorsLabelAddAndRemove", StringUtils.join(newInitiatorPorts, ","), StringUtils.join(oldInitiatorPorts, ","));
String description = ComputeSystemDialogProperties.getMessage("ComputeSystem.updateInitiatorsDescriptionAddAndRemove", StringUtils.join(newInitiatorPorts, ","), StringUtils.join(oldInitiatorPorts, ","));
if (!newInitiatorPorts.isEmpty() && oldInitiatorPorts.isEmpty()) {
name = ComputeSystemDialogProperties.getMessage("ComputeSystem.updateInitiatorsLabelAddOnly", StringUtils.join(newInitiatorPorts, ","));
description = ComputeSystemDialogProperties.getMessage("ComputeSystem.updateInitiatorsDescriptionAddOnly", StringUtils.join(newInitiatorPorts, ","), StringUtils.join(oldInitiatorPorts, ","));
} else if (newInitiatorPorts.isEmpty() && !oldInitiatorPorts.isEmpty()) {
name = ComputeSystemDialogProperties.getMessage("ComputeSystem.updateInitiatorsLabelRemoveOnly", StringUtils.join(oldInitiatorPorts, ","));
description = ComputeSystemDialogProperties.getMessage("ComputeSystem.updateInitiatorsDescriptionRemoveOnly", StringUtils.join(newInitiatorPorts, ","), StringUtils.join(oldInitiatorPorts, ","));
}
EventUtils.createActionableEvent(dbClient, EventUtils.EventCode.HOST_INITIATOR_UPDATES, host.getTenant(), name, description, ComputeSystemDialogProperties.getMessage("ComputeSystem.updateInitiatorsWarning"), host, allAffectedResources, EventUtils.updateInitiators, new Object[] { host.getId(), Lists.newArrayList(newInitiatorIds), Lists.newArrayList(oldInitiatorIds) }, EventUtils.updateInitiatorsDecline, new Object[] { host.getId(), Lists.newArrayList(newInitiatorIds), Lists.newArrayList(oldInitiatorIds) });
} 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);
}
}
}
use of com.emc.storageos.db.client.model.ActionableEvent in project coprhd-controller by CoprHD.
the class InitiatorCompleter method complete.
@Override
protected void complete(DbClient dbClient, Status status, ServiceCoded coded) throws DeviceControllerException {
super.complete(dbClient, status, coded);
for (URI id : getIds()) {
switch(status) {
case error:
dbClient.error(Initiator.class, this.getId(), getOpId(), coded);
if (!NullColumnValueGetter.isNullURI(eventId)) {
ActionableEvent event = dbClient.queryObject(ActionableEvent.class, eventId);
if (event != null) {
event.setEventStatus(ActionableEvent.Status.failed.name());
dbClient.updateObject(event);
}
}
// be removed if it is no longer in use.
if (op == InitiatorOperation.ADD) {
removeInitiator(id, dbClient);
}
break;
default:
dbClient.ready(Initiator.class, this.getId(), getOpId());
// be removed if it is no longer in use.
if (op == InitiatorOperation.REMOVE) {
removeInitiator(id, dbClient);
}
}
}
}
use of com.emc.storageos.db.client.model.ActionableEvent in project coprhd-controller by CoprHD.
the class ExportGroupService method validateExportGroupNoPendingEvents.
/**
* Validate there are no pending or failed events (actionable events) against the hosts or clusters
* associated with this export group.
*
* @param exportGroup
* export group we wish to update/delete
*/
private void validateExportGroupNoPendingEvents(ExportGroup exportGroup) {
// Find the compute resource and see if there are any pending or failed events
List<URI> computeResourceIDs = new ArrayList<>();
if (exportGroup == null) {
return;
}
// Grab all clusters from the export group
if (exportGroup.getClusters() != null && !exportGroup.getClusters().isEmpty()) {
computeResourceIDs.addAll(URIUtil.toURIList(exportGroup.getClusters()));
}
// Grab all hosts from the export group
if (exportGroup.getHosts() != null && !exportGroup.getHosts().isEmpty()) {
computeResourceIDs.addAll(URIUtil.toURIList(exportGroup.getHosts()));
}
StringBuffer errMsg = new StringBuffer();
// Query for actionable events with these resources
for (URI computeResourceID : computeResourceIDs) {
List<ActionableEvent> events = EventUtils.findAffectedResourceEvents(_dbClient, computeResourceID);
if (events != null && !events.isEmpty()) {
for (ActionableEvent event : events) {
if (event.getEventStatus().equalsIgnoreCase(ActionableEvent.Status.pending.name()) || event.getEventStatus().equalsIgnoreCase(ActionableEvent.Status.failed.name())) {
errMsg.append(event.forDisplay() + "\n");
}
}
}
}
if (errMsg.length() != 0) {
throw APIException.badRequests.cannotExecuteOperationWhilePendingOrFailedEvent(errMsg.toString());
}
}
use of com.emc.storageos.db.client.model.ActionableEvent in project coprhd-controller by CoprHD.
the class EventService method getOtherSearchResults.
@Override
protected SearchResults getOtherSearchResults(Map<String, List<String>> parameters, boolean authorized) {
SearchResults searchResults = new SearchResults();
if (parameters.containsKey(RESOURCE_QUERY_PARAM)) {
URI resourceId = URI.create(parameters.get(RESOURCE_QUERY_PARAM).get(0));
List<ActionableEvent> events = EventUtils.findResourceEvents(_dbClient, resourceId);
searchResults.getResource().addAll(toSearchResults(events));
}
return searchResults;
}
use of com.emc.storageos.db.client.model.ActionableEvent in project coprhd-controller by CoprHD.
the class EventService method getEventDetails.
/**
* Gets details for an event
*
* @param event the event to get details for
* @param approve if true, get the approve details, if false the get the decline details
* @return event details
*/
public List<String> getEventDetails(ActionableEvent event, boolean approve) {
byte[] method = approve ? event.getApproveMethod() : event.getDeclineMethod();
if (method == null || method.length == 0) {
_log.info("Method is null or empty for event " + event.getId());
return Lists.newArrayList("N/A");
}
ActionableEvent.Method eventMethod = ActionableEvent.Method.deserialize(method);
if (eventMethod == null) {
_log.info("Event method is null or empty for event " + event.getId());
return Lists.newArrayList("N/A");
}
String eventMethodName = eventMethod.getMethodName() + DETAILS_SUFFIX;
try {
Method classMethod = getMethod(ActionableEventExecutor.class, eventMethodName);
if (classMethod == null) {
return Lists.newArrayList("N/A");
} else {
ComputeSystemController controller = getController(ComputeSystemController.class, null);
ActionableEventExecutor executor = new ActionableEventExecutor(_dbClient, controller);
return (List<String>) classMethod.invoke(executor, eventMethod.getArgs());
}
} catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
_log.error(e.getMessage(), e.getCause());
throw APIException.badRequests.errorInvokingEventMethod(event.getId(), eventMethodName);
}
}
Aggregations