Search in sources :

Example 1 with SendAlertEvent

use of com.emc.storageos.systemservices.impl.eventhandler.connectemc.SendAlertEvent 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

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 SysEvent (com.emc.storageos.db.client.model.SysEvent)1 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)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