use of com.vmware.vim.vasa._1_0.data.xsd.StorageEvent in project coprhd-controller by CoprHD.
the class SOSManager method getEvents.
/**
* Provides event data that describes changes in storageOS configuration.
*
* Returns the List of data objects describing events. The first element in
* the list describes the event that follows lastEventId.
*
* @param lastEventId
* Identifier for the most recent event known to the vCenter
* Server. The value zero indicates a request for all available
* events
* @throws InvalidArgument
* Thrown if the specified event identifier (lastEventId) is not
* valid
* @throws InvalidSession
* Thrown if the VASA Provider determines that the session is
* not valid.
* @throws LostEvent
* Thrown if the VASA Provider determines that the vCenter
* Server has lost event data, based on the lastEventId
* parameter.
* @throws StorageFault
* Thrown for an error that is not covered by the other faults.
*/
public synchronized StorageEvent[] getEvents(long lastEventId) throws LostEvent, InvalidArgument, InvalidSession, StorageFault {
// Mandatory function
final String methodName = "getEvents(): ";
final long hoursInMillis = 60L * 60L * 1000L;
boolean eventRecorded = false;
log.debug(methodName + "Entry with lastEventId[" + lastEventId + "]");
long inputLastEventId = lastEventId;
if (inputLastEventId < -1) {
log.error("Inavlid value of input lastEventId[" + inputLastEventId + "]");
throw FaultUtil.InvalidArgument("Inavlid value of input lastEventId[" + inputLastEventId + "]");
}
if ((inputLastEventId != -1) && (inputLastEventId < this._lastEventId)) {
throw FaultUtil.LostEvent("Got unexpected last event id[" + inputLastEventId + "]");
}
if (inputLastEventId > this._lastEventId) {
log.error("Inavlid value of input lastEventId[" + inputLastEventId + "]");
throw FaultUtil.InvalidArgument("Inavlid value of input lastEventId[" + inputLastEventId + "]");
}
List<StorageEvent> storageEventList = new ArrayList<StorageEvent>();
StorageEvent storageEvent = null;
// Get the events from Q from lastEventId.
Iterator<StorageEvent> it = _eventManager.getEventQ().iterator();
// long eventId = lastEventId;
while (it.hasNext()) {
storageEvent = it.next();
if (storageEvent.getEventId() > inputLastEventId) {
storageEventList.add(storageEvent);
lastEventId = storageEvent.getEventId();
}
}
// Get when we query last time.
Calendar last = _eventManager.getLastEventEnqTime();
if (last == null) {
last = Calendar.getInstance();
}
Calendar now = Calendar.getInstance();
Calendar lastEnqTime = null;
while (last.compareTo(now) <= 0) {
lastEnqTime = _eventManager.getLastEventEnqTime();
if (lastEnqTime == null) {
lastEnqTime = Calendar.getInstance();
}
// Clean up the Q, if the Q holds last hour events.
if (lastEnqTime.get(Calendar.HOUR_OF_DAY) != last.get(Calendar.HOUR_OF_DAY)) {
_eventManager.getEventQ().clear();
}
EventList eventListObj = null;
try {
eventListObj = _syncManager.getEvents(last);
} catch (SOSFailure e) {
log.debug(methodName + "StorageOSFailure occured", e);
throw FaultUtil.StorageFault(e);
}
// Set the query time to current enquired time
_eventManager.setLastEventEnqTime(last);
last.setTimeInMillis(last.getTimeInMillis() + hoursInMillis);
storageEvent = null;
if (eventListObj != null && eventListObj.getEvents() != null) {
for (Event event : eventListObj.getEvents()) {
eventRecorded = false;
// Does this event already captured?.
if (_eventManager.isEventExistsInQueue(event)) {
continue;
}
// Is it a Required event?
if (!_eventManager.isEventRequired(event.getEventType())) {
continue;
}
if (event.getResourceId() == null) {
continue;
}
String resourceId = event.getResourceId().toString();
log.debug(methodName + " Event occurred on resourceId[" + resourceId + "]");
if (resourceId.startsWith(FILESYSTEM_IDENTIFIER_PREFIX)) {
this.setFileSystemIds();
List<String> currentFSList = new ArrayList<String>(_reportedFileSystemIdList);
if (_reportedFileSystemIdList.contains(resourceId)) {
this.setFileSystemIds(true);
} else {
this.setFileSystemIds(true);
List<String> newFSList = new ArrayList<String>(_reportedFileSystemIdList);
if (Util.areListsEqual(currentFSList, newFSList)) {
continue;
}
}
} else if (resourceId.startsWith(VOLUME_IDENTIFIER_PREFIX) || resourceId.startsWith(EXPORTGROUP_IDENTIFIER_PREFIX)) {
log.debug(methodName + " Event occurred on Volume/Export group[" + resourceId + "]");
this.setVolumeIds();
List<String> currentVolumeList = new ArrayList<String>(_reportedVolumeIdList);
if (_reportedVolumeIdList.contains(resourceId)) {
this.setStoragePorts(true);
this.setVolumeIds(true);
} else {
this.setStoragePorts(true);
this.setVolumeIds(true);
List<String> newVolumeList = new ArrayList<String>(_reportedVolumeIdList);
if (Util.areListsEqual(currentVolumeList, newVolumeList)) {
log.debug(methodName + " Current and new volume lists are same");
continue;
} else if (newVolumeList.size() > currentVolumeList.size()) {
// Volume exported
log.debug(methodName + "A Volume got exported");
storageEvent = _eventManager.createNewEvent(event.getEventId(), event.getTimeOccurred(), ++lastEventId, event.getResourceId().toString(), EntityTypeEnum.StorageLun.getValue(), EventTypeEnum.Config.getValue(), EventConfigTypeEnum.New.getValue(), "StorageOS.VolumeExported");
eventRecorded = true;
} else {
// Volume un-exported
log.debug(methodName + "A Volume got un-exported");
storageEvent = _eventManager.createNewEvent(event.getEventId(), event.getTimeOccurred(), ++lastEventId, event.getResourceId().toString(), EntityTypeEnum.StorageLun.getValue(), EventTypeEnum.Config.getValue(), EventConfigTypeEnum.Delete.getValue(), "StorageOS.VolumeUnexported");
eventRecorded = true;
}
}
} else if (resourceId.startsWith(STORAGEPORT_IDENTIFIER_PREFIX)) {
this.setStoragePorts(true);
} else if (resourceId.startsWith(COS_IDENTIFIER_PREFIX)) {
_syncManager.resetCoS();
}
if (false == eventRecorded) {
// Set the StorageEvent parameters.
storageEvent = _eventManager.createNewEvent(event.getEventId(), event.getTimeOccurred(), ++lastEventId, event.getResourceId().toString(), _eventManager.getEventObjectType(event.getEventType()), _eventManager.getVasaEventType(event.getEventType()), _eventManager.getVasaConfigType(event.getEventType()), _eventManager.getMessageIdForEvent(event.getEventType()));
/*
* storageEvent = new StorageEvent();
* storageEvent.setEventId(++lastEventId);
* storageEvent.setObjectId(event.getResourceId()
* .toString());
* storageEvent.setEventObjType(_eventManager
* .getEventObjectType(event.getEventType()));
*
* storageEvent.setEventType(_eventManager
* .getVasaEventType(event.getEventType()));
*
* storageEvent.setEventConfigType(_eventManager
* .getVasaConfigType(event.getEventType()));
*
* GregorianCalendar gc = new GregorianCalendar();
* gc.setTimeInMillis(Long.parseLong(event
* .getTimeOccurred()));
* storageEvent.setEventTimeStamp(gc);
*
* storageEvent.setMessageId(_eventManager
* .getMessageIdForEvent(event.getEventType()));
*
* // Storageos generated eventid is used to check the
* // duplicates in the Q!!. NameValuePair nvp = new
* NameValuePair(); nvp.setParameterName("SOSEventId");
* nvp.setParameterValue(event.getEventId().toString());
* storageEvent.addParameterList(nvp);
*
* NameValuePair nvp2 = new NameValuePair();
* nvp2.setParameterName("resId");
* nvp2.setParameterValue
* (event.getResourceId().toString());
* storageEvent.addParameterList(nvp2);
*/
}
log.info(methodName + "Event[" + storageEvent.getMessageId() + "] of type[" + storageEvent.getEventConfigType() + "] occured");
// Add the Event to the list as well as in Q!!.
_eventManager.setEventRecord(storageEvent);
storageEventList.add(storageEvent);
}
}
}
this._lastEventId = lastEventId;
log.debug(methodName + "Exit returning events of size[" + storageEventList.size() + "]");
return storageEventList.toArray(new StorageEvent[0]);
}
use of com.vmware.vim.vasa._1_0.data.xsd.StorageEvent in project coprhd-controller by CoprHD.
the class SOSEventManager method createNewEvent.
public StorageEvent createNewEvent(String bourneEventId, String bourneEventTimestamp, long lastEventId, String resourceId, String resourceType, String eventType, String eventConfigType, String messageId) {
StorageEvent storageEvent = new StorageEvent();
storageEvent.setEventId(lastEventId);
storageEvent.setObjectId(resourceId);
storageEvent.setEventObjType(resourceType);
storageEvent.setEventType(eventType);
storageEvent.setEventConfigType(eventConfigType);
GregorianCalendar gc = new GregorianCalendar();
gc.setTimeInMillis(Long.parseLong(bourneEventTimestamp));
storageEvent.setEventTimeStamp(gc);
storageEvent.setMessageId(messageId);
// Storageos generated eventid is used to check the
// duplicates in the Q!!.
NameValuePair nvp = new NameValuePair();
nvp.setParameterName("SOSEventId");
nvp.setParameterValue(bourneEventId);
storageEvent.addParameterList(nvp);
NameValuePair nvp2 = new NameValuePair();
nvp2.setParameterName("resId");
nvp2.setParameterValue(resourceId);
storageEvent.addParameterList(nvp2);
return storageEvent;
}
use of com.vmware.vim.vasa._1_0.data.xsd.StorageEvent in project coprhd-controller by CoprHD.
the class SOSEventManager method isEventExistsInQueue.
/**
* It searches the given event in the Q.
*
* @return - true, if the event already exists in the Q, false, otherwise.
* @param event
* -The Event generated in StorageOS
*/
public boolean isEventExistsInQueue(Event event) {
Iterator<StorageEvent> it = getEventQ().iterator();
while (it.hasNext()) {
StorageEvent storageEvent = it.next();
NameValuePair[] nvpList = storageEvent.getParameterList();
String eventId = event.getEventId().toString();
for (NameValuePair nvp : nvpList) {
if (nvp.getParameterName().equalsIgnoreCase("SOSEventId") && nvp.getParameterValue().equalsIgnoreCase(eventId)) {
return true;
}
}
}
return false;
}
Aggregations