Search in sources :

Example 6 with SOSFailure

use of com.emc.storageos.vasa.fault.SOSFailure 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)

Example 7 with SOSFailure

use of com.emc.storageos.vasa.fault.SOSFailure in project coprhd-controller by CoprHD.

the class SyncManager method fetchStoragePoolByHref.

public synchronized StoragePool fetchStoragePoolByHref(String href) throws SOSFailure {
    final String methodName = "fetchStoragePoolByHref(): ";
    log.trace(methodName + "Entry with href[" + href + "]");
    StoragePool storagePool = null;
    try {
        storagePool = _client.queryObject(href, StoragePool.class);
    } catch (NoSuchAlgorithmException e) {
        log.error(methodName + "NoSuchAlgorithmException occured", e);
        throw new SOSFailure(e);
    } catch (UniformInterfaceException e) {
        log.error(methodName + "UniformInterfaceException occured", e);
        throw new SOSFailure(e);
    }
    log.trace(methodName + "Exit returning storagePool[ " + storagePool + "]");
    return storagePool;
}
Also used : StoragePool(com.emc.storageos.vasa.data.internal.StoragePool) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) SOSFailure(com.emc.storageos.vasa.fault.SOSFailure) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 8 with SOSFailure

use of com.emc.storageos.vasa.fault.SOSFailure in project coprhd-controller by CoprHD.

the class SyncManager method fetchFileCosIdList.

/**
 * Returns list of file Cos Ids
 *
 * @return list of file CoS ids
 * @throws SOSFailure
 */
private List<String> fetchFileCosIdList() throws SOSFailure {
    final String methodName = "fetchFileCosIdList(): ";
    log.trace(methodName + "Entry");
    final String FILE_COS_URI = "/file/vpools";
    List<String> fileCosIdList = new ArrayList<String>();
    try {
        CoSList cosElemList = _client.queryObject(FILE_COS_URI, CoSList.class);
        if (cosElemList != null && cosElemList.getCosElements() != null) {
            for (CoSElement elem : cosElemList.getCosElements()) {
                if (elem != null) {
                    fileCosIdList.add(elem.getId());
                }
            }
        }
        log.trace(methodName + "File CoS Ids: " + fileCosIdList);
        if (cosElemList != null && fileCosIdList != null) {
            log.trace(methodName + "Exit returning cos list of size[" + fileCosIdList.size() + "]");
            return fileCosIdList;
        }
        log.trace(methodName + "Exit returning cos list of size[0]");
        return new ArrayList<String>();
    } catch (NoSuchAlgorithmException e) {
        log.error(methodName + "NoSuchAlgorithmException occured", e);
        throw new SOSFailure(e);
    } catch (UniformInterfaceException e) {
        log.error(methodName + "UniformInterfaceException occured", e);
        throw new SOSFailure(e);
    }
}
Also used : UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) CoSList(com.emc.storageos.vasa.data.internal.CoS.CoSList) CoSElement(com.emc.storageos.vasa.data.internal.CoS.CoSElement) SOSFailure(com.emc.storageos.vasa.fault.SOSFailure) ArrayList(java.util.ArrayList) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 9 with SOSFailure

use of com.emc.storageos.vasa.fault.SOSFailure in project coprhd-controller by CoprHD.

the class SyncManager method fetchVolumeDetailsById.

/**
 * Returns details of all active volumes
 *
 * @return list of <code>Volume</code>
 * @throws SOSFailure
 */
private List<Volume> fetchVolumeDetailsById(List<String> volumeIdList) throws SOSFailure {
    final String methodName = "fetchVolumeDetailsById(): ";
    final String VOLUME_DETAIL_URI = "/block/volumes/%s";
    log.trace(methodName + "Entry with input: volumeIdList[" + volumeIdList + "]");
    List<Volume> volumeDetailList = new ArrayList<Volume>();
    try {
        if (volumeIdList != null) {
            for (String volumeId : volumeIdList) {
                Volume volume = _client.queryObject(String.format(VOLUME_DETAIL_URI, volumeId), Volume.class);
                if (volume != null) {
                    if (!volume.isInactive() && volume.getId() != null) {
                        volumeDetailList.add(volume);
                        log.trace(methodName + volume);
                    }
                }
            }
        }
    } catch (NoSuchAlgorithmException e) {
        log.error(methodName + "NoSuchAlgorithmException occured", e);
        throw new SOSFailure(e);
    } catch (UniformInterfaceException e) {
        log.error(methodName + "UniformInterfaceException occured", e);
        throw new SOSFailure(e);
    }
    log.trace(methodName + "Exit returning volume list of size[" + volumeDetailList.size() + "]");
    return volumeDetailList;
}
Also used : UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) Volume(com.emc.storageos.vasa.data.internal.Volume) SOSFailure(com.emc.storageos.vasa.fault.SOSFailure) ArrayList(java.util.ArrayList) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 10 with SOSFailure

use of com.emc.storageos.vasa.fault.SOSFailure in project coprhd-controller by CoprHD.

the class SyncManager method getEvents.

/**
 * Returns Bourne event list based on given timestamp
 *
 * @param timestamp
 *            of the format <code>YYYY-MM-DDYHH:mm</code>
 * @return Object of <code>EventList</code>
 * @throws SOSFailure
 *             if call(s) to Bourne fails
 */
public synchronized EventList getEvents(String timestamp) throws SOSFailure {
    final String methodName = "getEvents(): ";
    final String MONITOR_URI = "/monitoring/events.xml/?time_bucket=%s";
    log.trace(methodName + "Entry with timestamp[" + timestamp + "]");
    EventList eventListObj = null;
    try {
        eventListObj = _client.queryObject(String.format(MONITOR_URI, timestamp), EventList.class);
    } catch (NoSuchAlgorithmException e) {
        log.error(methodName + "NoSuchAlgorithmException occured", e);
        throw new SOSFailure(e);
    } catch (UniformInterfaceException e) {
        if (e.toString().contains("403 Forbidden")) {
            log.warn(methodName + " The call to REST API: " + String.format(MONITOR_URI, timestamp) + " returned response of \"403 Forbidden\"");
            return null;
        }
        log.error(methodName + "UniformInterfaceException occured", e);
        throw new SOSFailure(e);
    }
    log.trace(methodName + "Exit returing eventListObj[" + eventListObj + "]");
    return eventListObj;
}
Also used : UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) EventList(com.emc.storageos.vasa.data.internal.Event.EventList) SOSFailure(com.emc.storageos.vasa.fault.SOSFailure) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Aggregations

SOSFailure (com.emc.storageos.vasa.fault.SOSFailure)29 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)18 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)18 ArrayList (java.util.ArrayList)15 InvalidArgument (com.vmware.vim.vasa._1_0.InvalidArgument)7 NotImplemented (com.vmware.vim.vasa._1_0.NotImplemented)6 FileShare (com.emc.storageos.vasa.data.internal.FileShare)5 CoS (com.emc.storageos.vasa.data.internal.CoS)4 StoragePool (com.emc.storageos.vasa.data.internal.StoragePool)4 Volume (com.emc.storageos.vasa.data.internal.Volume)4 AssociatedPool (com.emc.storageos.vasa.data.internal.Volume.AssociatedPool)4 EventList (com.emc.storageos.vasa.data.internal.Event.EventList)3 BaseStorageEntity (com.vmware.vim.vasa._1_0.data.xsd.BaseStorageEntity)3 VasaAssociationObject (com.vmware.vim.vasa._1_0.data.xsd.VasaAssociationObject)3 CoSElement (com.emc.storageos.vasa.data.internal.CoS.CoSElement)2 CoSList (com.emc.storageos.vasa.data.internal.CoS.CoSList)2 FileSystemExports (com.emc.storageos.vasa.data.internal.FileShare.FileSystemExports)2 List (java.util.List)2 Event (com.emc.storageos.vasa.data.internal.Event)1 AssociatedResource (com.emc.storageos.vasa.data.internal.FileShare.AssociatedResource)1