Search in sources :

Example 1 with LicenseType

use of com.emc.storageos.coordinator.client.service.CoordinatorClient.LicenseType in project coprhd-controller by CoprHD.

the class LicenseManagerImpl method updateCoordinatorWithLicenseFeatures.

/**
 * Build the coordinator service version of the license features from the
 * License object.
 *
 * @param license license to update
 * @param checkClusterUpgradable check if cluster is upgradable
 * @throws CoordinatorClientException
 */
private void updateCoordinatorWithLicenseFeatures(License license, boolean checkClusterUpgradable) throws CoordinatorClientException {
    LicenseInfoListExt licenseList = null;
    List<LicenseInfoExt> licenseInfoList = new ArrayList<LicenseInfoExt>();
    for (LicenseFeature licenseFeature : license.getLicenseFeatures()) {
        LicenseType licenseType;
        if (licenseFeature.getModelId().startsWith(LicenseConstants.VIPR_CONTROLLER)) {
            licenseType = LicenseType.CONTROLLER;
        } else {
            throw APIException.internalServerErrors.licenseInfoNotFoundForType("invalid license model id" + licenseFeature.getModelId());
        }
        LicenseInfoExt licenseInfo = new LicenseInfoExt();
        licenseInfo.setLicenseType(licenseType);
        licenseInfo.setExpirationDate(licenseFeature.getDateExpires());
        licenseInfo.setStorageCapacity(licenseFeature.getStorageCapacity());
        licenseInfo.setProductId(licenseFeature.getProductId());
        licenseInfo.setModelId(licenseFeature.getModelId());
        licenseInfo.setIssuedDate(licenseFeature.getDateIssued());
        licenseInfo.setLicenseTypeIndicator(licenseFeature.getLicenseIdIndicator());
        licenseInfo.setVersion(licenseFeature.getVersion());
        licenseInfo.setNotice(licenseFeature.getNotice());
        if (licenseFeature.isTrialLicense()) {
            licenseInfo.setTrialLicense(true);
        }
        licenseInfoList.add(licenseInfo);
    }
    if (!licenseInfoList.isEmpty()) {
        licenseList = new LicenseInfoListExt(licenseInfoList);
        _coordinator.setTargetInfo(licenseList, checkClusterUpgradable);
    }
}
Also used : LicenseFeature(com.emc.vipr.model.sys.licensing.LicenseFeature) LicenseType(com.emc.storageos.coordinator.client.service.CoordinatorClient.LicenseType)

Example 2 with LicenseType

use of com.emc.storageos.coordinator.client.service.CoordinatorClient.LicenseType 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)

Example 3 with LicenseType

use of com.emc.storageos.coordinator.client.service.CoordinatorClient.LicenseType in project coprhd-controller by CoprHD.

the class LicenseInfoExt method decodeFromString.

@Override
public LicenseInfoExt decodeFromString(String infoStr) throws DecodingException {
    if (infoStr != null && !infoStr.isEmpty()) {
        for (String licenseProps : infoStr.split(ENCODING_SEPARATOR)) {
            String[] licenseProp = licenseProps.split(ENCODING_EQUAL);
            if (licenseProp.length < 2) {
                continue;
            }
            if (licenseProp[0].equalsIgnoreCase(LICENSE_TYPE)) {
                LicenseType licenseType = LicenseType.findByValue(licenseProp[1]);
                this.setLicenseType(licenseType);
            }
            if (licenseProp[0].equalsIgnoreCase(EXPIRATION_DATE)) {
                this.setExpirationDate(licenseProp[1]);
            } else if (licenseProp[0].equalsIgnoreCase(ISSUED_DATE)) {
                this.setIssuedDate(licenseProp[1]);
            } else if (licenseProp[0].equalsIgnoreCase(STORAGE_CAPACITY)) {
                this.setStorageCapacity(licenseProp[1]);
            } else if (licenseProp[0].equalsIgnoreCase(PRODUCT_ID)) {
                this.setProductId(licenseProp[1]);
            } else if (licenseProp[0].equalsIgnoreCase(MODEL_ID)) {
                this.setModelId(licenseProp[1]);
            } else if (licenseProp[0].equalsIgnoreCase(LICENSE_TYPE_INDICATOR)) {
                this.setLicenseTypeIndicator(licenseProp[1]);
            } else if (licenseProp[0].equalsIgnoreCase(VERSION)) {
                this.setVersion(licenseProp[1]);
            } else if (licenseProp[0].equalsIgnoreCase(NOTICE)) {
                this.setNotice(licenseProp[1]);
            } else if (licenseProp[0].equalsIgnoreCase(IS_TRIAL_LICENSE)) {
                this.setTrialLicense(Boolean.valueOf(licenseProp[1]));
            } else if (licenseProp[0].equalsIgnoreCase(LAST_REGISTRATION_EVENT_DATE)) {
                this.setLastRegistrationEventDate(licenseProp[1]);
            } else if (licenseProp[0].equalsIgnoreCase(LAST_HEARBEAT_EVENT_DATE)) {
                this.setLastHeartbeatEventDate(licenseProp[1]);
            } else if (licenseProp[0].equalsIgnoreCase(LAST_EXPIRATION_EVENT_DATE)) {
                this.setLastLicenseExpirationDateEventDate(licenseProp[1]);
            } else if (licenseProp[0].equalsIgnoreCase(LAST_CAPACITY_EXCEEDED_EVENT_DATE)) {
                this.setLastCapacityExceededEventDate(licenseProp[1]);
            }
        }
    }
    return this;
}
Also used : LicenseType(com.emc.storageos.coordinator.client.service.CoordinatorClient.LicenseType)

Example 4 with LicenseType

use of com.emc.storageos.coordinator.client.service.CoordinatorClient.LicenseType in project coprhd-controller by CoprHD.

the class LicenseInfo method decodeLicenses.

/**
 * Method used for decoding a list of licenses from the string.
 *
 * @param infoStr
 * @return a list of decoded license info
 * @throws Exception
 */
public static List<LicenseInfo> decodeLicenses(String infoStr) throws Exception {
    _log.info("Retrieving licenses from coordinator service");
    List<LicenseInfo> licenseList = new ArrayList<LicenseInfo>();
    if (infoStr != null && !infoStr.isEmpty()) {
        for (String licenseStr : infoStr.split(LICENSE_SEPARATOR)) {
            String expireDate = null;
            LicenseType licenseType = null;
            for (String licenseProps : licenseStr.split(ENCODING_SEPARATOR)) {
                String[] licenseProp = licenseProps.split(ENCODING_EQUAL);
                if (licenseProp.length < 2) {
                    continue;
                }
                if (licenseProp[0].equalsIgnoreCase(LICENSE_TYPE)) {
                    licenseType = LicenseType.findByValue(licenseProp[1]);
                }
                if (licenseProp[0].equalsIgnoreCase(EXPIRATION_DATE)) {
                    expireDate = licenseProp[1];
                }
                if (licenseType != null && expireDate != null) {
                    licenseList.add(new LicenseInfo(licenseType, expireDate));
                    break;
                }
            }
        }
    }
    return licenseList;
}
Also used : ArrayList(java.util.ArrayList) LicenseType(com.emc.storageos.coordinator.client.service.CoordinatorClient.LicenseType)

Aggregations

LicenseType (com.emc.storageos.coordinator.client.service.CoordinatorClient.LicenseType)4 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 LicenseFeature (com.emc.vipr.model.sys.licensing.LicenseFeature)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1