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));
}
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));
}
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));
}
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);
}
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);
}
Aggregations