Search in sources :

Example 1 with Parameter

use of com.emc.vipr.model.catalog.Parameter in project coprhd-controller by CoprHD.

the class OrderTextCreator method writeRequestParameters.

private void writeRequestParameters() {
    writeHeader("Parameters");
    List<Parameter> parameters = order.getParameters();
    for (Parameter parameter : parameters) {
        writeField(parameter.getFriendlyLabel(), parameter.getFriendlyValue());
    }
}
Also used : Parameter(com.emc.vipr.model.catalog.Parameter)

Example 2 with Parameter

use of com.emc.vipr.model.catalog.Parameter in project coprhd-controller by CoprHD.

the class OrderExecution method createScheduledOrder.

protected static ScheduledEventCreateParam createScheduledOrder(OrderCreateParam orderParam) {
    if (!isSchedulerEnabled()) {
        return null;
    }
    ScheduleInfo scheduleInfo = new ScheduleInfo();
    String cycleFrequency = params.get("scheduler.cycleFrequency");
    if (cycleFrequency != null) {
        scheduleInfo.setCycleFrequency(Integer.parseInt(cycleFrequency));
    } else {
        scheduleInfo.setCycleFrequency(1);
    }
    String cycleType = params.get("scheduler.cycleType");
    if (cycleType != null) {
        ScheduleCycleType cycleTypeEnum = ScheduleCycleType.valueOf(cycleType);
        scheduleInfo.setCycleType(cycleTypeEnum);
        List<String> sectionsInCycleList = Lists.newArrayList();
        if (cycleTypeEnum == ScheduleCycleType.WEEKLY) {
            String sectionsInCycle = params.get("scheduler.dayOfWeek");
            sectionsInCycleList.add(sectionsInCycle);
        } else if (cycleTypeEnum == ScheduleCycleType.MONTHLY) {
            String sectionsInCycle = params.get("scheduler.dayOfMonth");
            sectionsInCycleList.add(sectionsInCycle);
        }
        scheduleInfo.setSectionsInCycle(sectionsInCycleList);
    } else {
        scheduleInfo.setCycleType(ScheduleCycleType.DAILY);
    }
    String currentTimezoneOffsetInMins = params.get("scheduler.currentTimezoneOffsetInMins");
    Integer timezoneOffset = Integer.parseInt(currentTimezoneOffsetInMins);
    String startDate = params.get("scheduler.startDate");
    String startTime = params.get("scheduler.startTime");
    String isoDateTimeStr = String.format("%sT%s", startDate, startTime);
    DateTime startDateTime = DateTime.parse(isoDateTimeStr, ISODateTimeFormat.localDateOptionalTimeParser().withZone(TimeUtils.getLocalTimeZone(timezoneOffset)));
    startDateTime = startDateTime.withZone(DateTimeZone.UTC);
    scheduleInfo.setHourOfDay(startDateTime.getHourOfDay());
    scheduleInfo.setMinuteOfHour(startDateTime.getMinuteOfHour());
    scheduleInfo.setStartDate(String.format("%d-%02d-%02d", startDateTime.getYear(), startDateTime.getMonthOfYear(), startDateTime.getDayOfMonth()));
    String recurrence = params.get("scheduler.recurrence");
    int recurrenceNum = 1;
    if (recurrence != null) {
        recurrenceNum = Integer.parseInt(recurrence);
        if (recurrenceNum == -1) {
            String range = params.get("scheduler.rangeOfRecurrence");
            recurrenceNum = Integer.parseInt(range);
        }
    }
    scheduleInfo.setReoccurrence(recurrenceNum);
    /*
         * if reoccurence number large than 1, we must make sure the name contains patten {datetime},
         * with the pattern in the name, vipr know how to generate dynamic name for each snaphot/fullcopy.
         */
    if (recurrenceNum != 1) {
        List<Parameter> parameters = orderParam.getParameters();
        CatalogServiceRestRep service = CatalogServiceUtils.getCatalogService(orderParam.getCatalogService());
        Logger.info("creating order with parameter for: " + service.getBaseService());
        String nameToValidate = SCHEDULED_SERVICE.get(service.getBaseService());
        for (Parameter parameter : parameters) {
            if (parameter.getLabel().equals(nameToValidate) && !parameter.getValue().contains("{datetime}")) {
                Validation.addError(nameToValidate, "need to add patten '{datetime}' in the name for reoccuring scheduled operation");
            }
            Logger.info(parameter.getLabel() + " = " + parameter.getValue() + ", " + parameter.getFriendlyLabel() + " = " + parameter.getFriendlyValue());
        }
    }
    String maxNumOfCopies = params.get("scheduler.maxNumOfCopies");
    if (maxNumOfCopies != null) {
        orderParam.setAdditionalScheduleInfo(maxNumOfCopies);
    }
    scheduleInfo.setDurationLength(3600);
    ScheduledEventCreateParam eventParam = new ScheduledEventCreateParam();
    eventParam.setOrderCreateParam(orderParam);
    eventParam.setScheduleInfo(scheduleInfo);
    return eventParam;
}
Also used : Parameter(com.emc.vipr.model.catalog.Parameter) CatalogServiceRestRep(com.emc.vipr.model.catalog.CatalogServiceRestRep) ScheduledEventCreateParam(com.emc.vipr.model.catalog.ScheduledEventCreateParam) ScheduleInfo(com.emc.vipr.model.catalog.ScheduleInfo) DateTime(org.joda.time.DateTime) ScheduleCycleType(com.emc.vipr.model.catalog.ScheduleCycleType)

Example 3 with Parameter

use of com.emc.vipr.model.catalog.Parameter in project coprhd-controller by CoprHD.

the class OrderExecution method createOrder.

@Util
public static OrderCreateParam createOrder(CatalogServiceRestRep service, ServiceDescriptorRestRep descriptor, Map<String, String> parameters) {
    OrderCreateParam order = new OrderCreateParam();
    order.setTenantId(uri(Models.currentAdminTenant()));
    order.setCatalogService(service.getId());
    List<Parameter> orderParameters = Lists.newArrayList();
    List<ServiceFieldRestRep> fields = ServiceDescriptorUtils.getAllFieldList(descriptor.getItems());
    for (ServiceFieldRestRep field : fields) {
        String value = parameters.get(field.getName());
        if (StringUtils.isNotBlank(value)) {
            orderParameters.add(createOrderParameter(field, value));
        }
    }
    order.setParameters(orderParameters);
    return order;
}
Also used : CatalogServiceFieldRestRep(com.emc.vipr.model.catalog.CatalogServiceFieldRestRep) ServiceFieldRestRep(com.emc.vipr.model.catalog.ServiceFieldRestRep) OrderCreateParam(com.emc.vipr.model.catalog.OrderCreateParam) Parameter(com.emc.vipr.model.catalog.Parameter) Util(play.mvc.Util)

Example 4 with Parameter

use of com.emc.vipr.model.catalog.Parameter in project coprhd-controller by CoprHD.

the class OrderExecution method createOrderParameter.

private static Parameter createOrderParameter(ServiceFieldRestRep field, String value) {
    Parameter parameter = new Parameter();
    parameter.setLabel(field.getName());
    if (value != null) {
        parameter.setValue(value.trim());
    } else {
        // NOSONAR
        parameter.setValue(value);
    // ("Suppressing Sonar violation of Load of known null value. Value can be null and it needs to be set when null")
    }
    parameter.setUserInput(true);
    if (StringUtils.equals(field.getType(), ServiceField.TYPE_PASSWORD)) {
        parameter.setEncrypted(true);
    }
    return parameter;
}
Also used : Parameter(com.emc.vipr.model.catalog.Parameter)

Example 5 with Parameter

use of com.emc.vipr.model.catalog.Parameter in project coprhd-controller by CoprHD.

the class OrderService method addLockedFields.

private void addLockedFields(URI catalogServiceId, ServiceDescriptor serviceDescriptor, OrderCreateParam createParam) {
    Map<String, String> locked = catalogServiceManager.getLockedFields(catalogServiceId);
    for (ServiceField field : serviceDescriptor.getAllFieldList()) {
        if (locked.containsKey(field.getName())) {
            String lockedValue = locked.get(field.getName());
            Parameter parameter = createParam.findParameterByLabel(field.getName());
            if (parameter != null) {
                parameter.setValue(lockedValue);
            } else {
                Parameter newLockedParameter = new Parameter();
                newLockedParameter.setLabel(field.getName());
                newLockedParameter.setValue(lockedValue);
                createParam.getParameters().add(newLockedParameter);
            }
        }
    }
}
Also used : ServiceField(com.emc.sa.descriptor.ServiceField) OrderParameter(com.emc.storageos.db.client.model.uimodels.OrderParameter) Parameter(com.emc.vipr.model.catalog.Parameter) URIUtil.asString(com.emc.storageos.db.client.URIUtil.asString)

Aggregations

Parameter (com.emc.vipr.model.catalog.Parameter)8 OrderParameter (com.emc.storageos.db.client.model.uimodels.OrderParameter)3 CatalogServiceRestRep (com.emc.vipr.model.catalog.CatalogServiceRestRep)2 ServiceFieldRestRep (com.emc.vipr.model.catalog.ServiceFieldRestRep)2 Util (play.mvc.Util)2 ServiceField (com.emc.sa.descriptor.ServiceField)1 URIUtil.asString (com.emc.storageos.db.client.URIUtil.asString)1 TaskUtil (com.emc.vipr.client.core.impl.TaskUtil)1 CatalogServiceFieldRestRep (com.emc.vipr.model.catalog.CatalogServiceFieldRestRep)1 OrderCreateParam (com.emc.vipr.model.catalog.OrderCreateParam)1 OrderRestRep (com.emc.vipr.model.catalog.OrderRestRep)1 ScheduleCycleType (com.emc.vipr.model.catalog.ScheduleCycleType)1 ScheduleInfo (com.emc.vipr.model.catalog.ScheduleInfo)1 ScheduledEventCreateParam (com.emc.vipr.model.catalog.ScheduledEventCreateParam)1 ServiceFieldTableRestRep (com.emc.vipr.model.catalog.ServiceFieldTableRestRep)1 ServiceItemRestRep (com.emc.vipr.model.catalog.ServiceItemRestRep)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 DateTime (org.joda.time.DateTime)1 BourneUtil (util.BourneUtil)1