Search in sources :

Example 6 with LicenseInfoExt

use of com.emc.storageos.systemservices.impl.licensing.LicenseInfoExt in project coprhd-controller by CoprHD.

the class CallHomeEventManagerTest method testRegistrationEventFalse.

/**
 * Test case which recognizes that a registration event should not be sent.
 */
@Test
public void testRegistrationEventFalse() throws Exception {
    MockCallHomeEventManager manager = new MockCallHomeEventManager();
    LicenseInfoExt licenseInfo = new LicenseInfoExt();
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    String stringDate = sdf.format(new java.util.Date());
    licenseInfo.setLastRegistrationEventDate(stringDate);
    manager.setLicenseInfo(licenseInfo);
    Assert.assertFalse(manager.doSendRegistration(licenseInfo));
}
Also used : LicenseInfoExt(com.emc.storageos.systemservices.impl.licensing.LicenseInfoExt) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 7 with LicenseInfoExt

use of com.emc.storageos.systemservices.impl.licensing.LicenseInfoExt in project coprhd-controller by CoprHD.

the class CallHomeEventManagerTest method testHeartbeatEventNoHeartbeatDate.

/**
 * test that a heartbeat event is sent if no heartbeat date exists in zookeeper.
 */
@Test
public void testHeartbeatEventNoHeartbeatDate() throws Exception {
    MockCallHomeEventManager manager = new MockCallHomeEventManager();
    LicenseInfoExt licenseInfo = new LicenseInfoExt();
    manager.setLicenseInfo(licenseInfo);
    Assert.assertTrue(manager.doSendHeartBeat(licenseInfo));
}
Also used : LicenseInfoExt(com.emc.storageos.systemservices.impl.licensing.LicenseInfoExt) Test(org.junit.Test)

Example 8 with LicenseInfoExt

use of com.emc.storageos.systemservices.impl.licensing.LicenseInfoExt in project coprhd-controller by CoprHD.

the class CallHomeEventManagerTest method testLicenseExpirationEventTrue.

/**
 * Test case which recognizes that a license expiration event should be sent.
 */
@Test
public void testLicenseExpirationEventTrue() throws Exception {
    MockCallHomeEventManager manager = new MockCallHomeEventManager();
    LicenseInfoExt licenseInfo = new LicenseInfoExt();
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DAY_OF_MONTH, CallHomeConstants.LICENSE_EXPIRATION_EVENT_THRESHOLD * -1);
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    String stringDate = sdf.format(cal.getTime());
    licenseInfo.setLastLicenseExpirationDateEventDate(stringDate);
    manager.setLicenseInfo(licenseInfo);
    Assert.assertTrue(manager.doSendLicenseExpiration(licenseInfo));
}
Also used : LicenseInfoExt(com.emc.storageos.systemservices.impl.licensing.LicenseInfoExt) Calendar(java.util.Calendar) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 9 with LicenseInfoExt

use of com.emc.storageos.systemservices.impl.licensing.LicenseInfoExt in project coprhd-controller by CoprHD.

the class CallHomeServiceImpl method internalSendRegistrationEvent.

void internalSendRegistrationEvent() {
    _callHomeEventManager.validateSendEvent();
    LicenseInfoListExt licenseList = null;
    try {
        licenseList = _licenseManager.getLicenseInfoListFromCoordinator();
    } catch (Exception e) {
        throw APIException.internalServerErrors.licenseInfoNotFoundForType("all license types");
    }
    if (licenseList != null) {
        // send registration events for each registered license type
        for (LicenseInfoExt licenseInfo : licenseList.getLicenseList()) {
            if (licenseInfo.isTrialLicense()) {
                _log.warn("Cannot send regisration event to SYR for trial license {}", licenseInfo.getLicenseType().toString());
                throw APIException.forbidden.permissionDeniedForTrialLicense(licenseInfo.getLicenseType().toString());
            }
            _callHomeEventsFacade.sendRegistrationEvent(licenseInfo, getMediaType());
        }
    }
    auditCallhome(OperationTypeEnum.SEND_REGISTRATION, AuditLogManager.AUDITLOG_SUCCESS, null);
}
Also used : LicenseInfoExt(com.emc.storageos.systemservices.impl.licensing.LicenseInfoExt) LicenseInfoListExt(com.emc.storageos.systemservices.impl.licensing.LicenseInfoListExt) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) ForbiddenException(com.emc.storageos.svcs.errorhandling.resources.ForbiddenException)

Example 10 with LicenseInfoExt

use of com.emc.storageos.systemservices.impl.licensing.LicenseInfoExt 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

LicenseInfoExt (com.emc.storageos.systemservices.impl.licensing.LicenseInfoExt)15 Test (org.junit.Test)11 SimpleDateFormat (java.text.SimpleDateFormat)5 Calendar (java.util.Calendar)4 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)3 ForbiddenException (com.emc.storageos.svcs.errorhandling.resources.ForbiddenException)3 LicenseInfoListExt (com.emc.storageos.systemservices.impl.licensing.LicenseInfoListExt)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 SysEvent (com.emc.storageos.db.client.model.SysEvent)1 SendAlertEvent (com.emc.storageos.systemservices.impl.eventhandler.connectemc.SendAlertEvent)1 Device (com.emc.vipr.model.sys.eventhandler.Device)1 URI (java.net.URI)1