Search in sources :

Example 1 with SysEvent

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

the class SendAlertEvent method run.

@Override
public void run() {
    try {
        super.callEMCHome();
        dbClient.ready(SysEvent.class, sysEventId, operationId);
        alertsLog.warn("Alert event initiated by " + _eventParameters.getContact() + " is sent successfully");
    } catch (APIException api) {
        dbClient.error(SysEvent.class, sysEventId, operationId, api);
        alertsLog.error("Failed to send alert event initiated by " + _eventParameters.getContact() + ". " + api.getMessage());
    } finally {
        SysEvent sysEvent = permissionsHelper.getObjectById(sysEventId, SysEvent.class);
        dbClient.removeObject(sysEvent);
    }
}
Also used : APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) SysEvent(com.emc.storageos.db.client.model.SysEvent)

Example 2 with SysEvent

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

the class CallHomeServiceImpl method createSysEventRecord.

/**
 * Creates sysevent record after checking if there are any existing records.
 * If force is 1 will not check for existing records.
 */
private synchronized SysEvent createSysEventRecord(URI sysEventId, String opID, Operation op, int force) {
    if (force != 1) {
        List sysEvents = dbClient.queryByType(SysEvent.class, true);
        if (sysEvents != null && sysEvents.iterator().hasNext()) {
            throw APIException.serviceUnavailable.sendEventBusy();
        }
    }
    _log.info("Event id is {} and operation id is {}", sysEventId, opID);
    SysEvent sysEvent = new SysEvent();
    sysEvent.setId(sysEventId);
    sysEvent.setLabel("System Event");
    dbClient.createObject(sysEvent);
    dbClient.createTaskOpStatus(SysEvent.class, sysEventId, opID, op);
    return sysEvent;
}
Also used : SysEvent(com.emc.storageos.db.client.model.SysEvent) List(java.util.List)

Example 3 with SysEvent

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

the class CallHomeServiceImpl method sendAlert.

@Override
public TaskResourceRep sendAlert(String source, int eventId, List<String> nodeIds, List<String> nodeNames, List<String> logNames, int severity, String start, String end, String msgRegex, int maxCount, boolean forceAttachLogs, int force, EventParameters eventParameters) throws Exception {
    if (LogService.runningRequests.get() >= LogService.MAX_THREAD_COUNT) {
        _log.info("Current running requests: {} vs maximum allowed {}", LogService.runningRequests, LogService.MAX_THREAD_COUNT);
        throw APIException.serviceUnavailable.logServiceIsBusy();
    }
    // if not configured for callhome, do not continue.
    _callHomeEventManager.validateSendEvent();
    // validate event id
    if (!CallHomeConstants.VALID_ALERT_EVENT_IDS.contains(eventId)) {
        throw APIException.badRequests.parameterIsNotOneOfAllowedValues("event_id", CallHomeConstants.VALID_ALERT_EVENT_IDS.toString());
    }
    LicenseInfoExt licenseInfo = null;
    // Otherwise check if controller or unstructured is licensed
    if (source != null && !source.isEmpty()) {
        // validate source
        LicenseType licenseType = LicenseType.findByValue(source);
        if (licenseType == null) {
            throw APIException.badRequests.parameterIsNotOneOfAllowedValues("source", LicenseType.getValuesAsStrings().toString());
        }
        // get an instance of the requested license information
        licenseInfo = _licenseManager.getLicenseInfoFromCoordinator(licenseType);
        if (licenseInfo == null) {
            throw APIException.internalServerErrors.licenseInfoNotFoundForType(licenseType.toString());
        }
    } else {
        licenseInfo = _licenseManager.getLicenseInfoFromCoordinator(LicenseType.CONTROLLER);
        if (licenseInfo == null) {
            licenseInfo = _licenseManager.getLicenseInfoFromCoordinator(LicenseType.UNSTRUCTURED);
        }
    }
    if (licenseInfo == null) {
        throw ForbiddenException.forbidden.licenseNotFound(LicenseType.CONTROLLER.toString() + " or " + LicenseType.UNSTRUCTURED.toString());
    }
    if (licenseInfo.isTrialLicense()) {
        _log.warn("Cannot send alert to SYR for trial license {} ", licenseInfo.getLicenseType().toString());
        throw APIException.forbidden.permissionDeniedForTrialLicense(licenseInfo.getLicenseType().toString());
    }
    // invoke get-logs api for the dry run
    List<String> logNamesToUse = getLogNamesFromAlias(logNames);
    try {
        logService.getLogs(nodeIds, nodeNames, logNamesToUse, severity, start, end, msgRegex, maxCount, true);
    } catch (Exception e) {
        _log.error("Failed to dry run get-logs, exception: {}", e);
        throw e;
    }
    URI sysEventId = URIUtil.createId(SysEvent.class);
    String opID = UUID.randomUUID().toString();
    SendAlertEvent sendAlertEvent = new SendAlertEvent(serviceInfo, dbClient, _logSvcPropertiesLoader, sysEventId, opID, getMediaType(), licenseInfo, permissionsHelper, coordinator);
    sendAlertEvent.setEventId(eventId);
    sendAlertEvent.setNodeIds(nodeIds);
    sendAlertEvent.setLogNames(logNamesToUse);
    sendAlertEvent.setSeverity(severity);
    sendAlertEvent.setStart(TimeUtils.getDateTimestamp(start));
    sendAlertEvent.setEnd(TimeUtils.getDateTimestamp(end));
    validateMsgRegex(msgRegex);
    sendAlertEvent.setMsgRegex(msgRegex);
    sendAlertEvent.setEventParameters(eventParameters);
    sendAlertEvent.setMaxCount(maxCount);
    sendAlertEvent.setForceAttachLogs(forceAttachLogs);
    // Persisting this operation
    Operation op = new Operation();
    op.setName("SEND ALERT " + eventId);
    op.setDescription("SEND ALERT EVENT code:" + eventId + ", severity:" + severity);
    op.setResourceType(ResourceOperationTypeEnum.SYS_EVENT);
    SysEvent sysEvent = createSysEventRecord(sysEventId, opID, op, force);
    // Starting send event job
    getExecutorServiceInstance().submit(sendAlertEvent);
    auditCallhome(OperationTypeEnum.SEND_ALERT, AuditLogManager.AUDITOP_BEGIN, null, nodeIds, logNames, start, end);
    return toTask(sysEvent, opID, op);
}
Also used : LicenseInfoExt(com.emc.storageos.systemservices.impl.licensing.LicenseInfoExt) SysEvent(com.emc.storageos.db.client.model.SysEvent) SendAlertEvent(com.emc.storageos.systemservices.impl.eventhandler.connectemc.SendAlertEvent) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) ForbiddenException(com.emc.storageos.svcs.errorhandling.resources.ForbiddenException) LicenseType(com.emc.storageos.coordinator.client.service.CoordinatorClient.LicenseType)

Aggregations

SysEvent (com.emc.storageos.db.client.model.SysEvent)3 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)2 LicenseType (com.emc.storageos.coordinator.client.service.CoordinatorClient.LicenseType)1 NamedURI (com.emc.storageos.db.client.model.NamedURI)1 Operation (com.emc.storageos.db.client.model.Operation)1 ForbiddenException (com.emc.storageos.svcs.errorhandling.resources.ForbiddenException)1 SendAlertEvent (com.emc.storageos.systemservices.impl.eventhandler.connectemc.SendAlertEvent)1 LicenseInfoExt (com.emc.storageos.systemservices.impl.licensing.LicenseInfoExt)1 URI (java.net.URI)1 List (java.util.List)1