Search in sources :

Example 1 with Event

use of com.emc.storageos.vasa.data.internal.Event 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]);
}
Also used : StorageEvent(com.vmware.vim.vasa._1_0.data.xsd.StorageEvent) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) EventList(com.emc.storageos.vasa.data.internal.Event.EventList) SOSFailure(com.emc.storageos.vasa.fault.SOSFailure) Event(com.emc.storageos.vasa.data.internal.Event) StorageEvent(com.vmware.vim.vasa._1_0.data.xsd.StorageEvent) LostEvent(com.vmware.vim.vasa._1_0.LostEvent) List(java.util.List) ArrayList(java.util.ArrayList) EventList(com.emc.storageos.vasa.data.internal.Event.EventList)

Aggregations

Event (com.emc.storageos.vasa.data.internal.Event)1 EventList (com.emc.storageos.vasa.data.internal.Event.EventList)1 SOSFailure (com.emc.storageos.vasa.fault.SOSFailure)1 LostEvent (com.vmware.vim.vasa._1_0.LostEvent)1 StorageEvent (com.vmware.vim.vasa._1_0.data.xsd.StorageEvent)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 List (java.util.List)1