Search in sources :

Example 1 with ConfigurableField

use of org.ow2.proactive.resourcemanager.nodesource.common.ConfigurableField in project scheduling by ow2-proactive.

the class PluginDescriptor method packParameters.

/**
 * Packs parameters inputed by user into appropriate parameters set required for this plugin.
 * Performs some operations such as file loading on user side.
 *
 * @param parameters input parameters
 * @return output parameters
 * @throws RMException when error occurs
 */
public Object[] packParameters(Object[] parameters) throws RMException {
    int configurableFieldsSize = configurableFields.size();
    List<Object> resultParams = new ArrayList<>(configurableFieldsSize);
    if (parameters.length != configurableFieldsSize) {
        throw new RMException("Incorrect number of parameters: expected " + configurableFieldsSize + ", provided " + parameters.length);
    }
    int counter = 0;
    for (ConfigurableField field : configurableFields) {
        Object value = parameters[counter++];
        Configurable configurable = field.getMeta();
        boolean credentialsFilePath = configurable.credential() && value instanceof String;
        if (configurable.fileBrowser() || credentialsFilePath) {
            try {
                if (value.toString().length() > 0) {
                    value = FileToBytesConverter.convertFileToByteArray(new File(value.toString()));
                } else {
                    // in case if file path is not specified propagate null to plugin
                    // it will decide then if it's acceptable or not
                    value = null;
                }
            } catch (IOException e) {
                throw new RMException("Cannot load file", e);
            }
        }
        resultParams.add(value);
    }
    return resultParams.toArray();
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) RMException(org.ow2.proactive.resourcemanager.exception.RMException)

Example 2 with ConfigurableField

use of org.ow2.proactive.resourcemanager.nodesource.common.ConfigurableField in project scheduling by ow2-proactive.

the class NodeSourceParameterHelper method getPluginConfigurableFields.

public Collection<ConfigurableField> getPluginConfigurableFields(String pluginClassName) throws PluginNotFoundException {
    Class<NodeSourcePlugin> pluginClass = this.getPluginClassOrFail(pluginClassName);
    PluginDescriptor policyPluginDescriptor = new PluginDescriptor(pluginClass, AddonClassUtils.instantiateAddon(pluginClass), new HashMap<>());
    return policyPluginDescriptor.getConfigurableFields();
}
Also used : PluginDescriptor(org.ow2.proactive.resourcemanager.nodesource.common.PluginDescriptor) NodeSourcePlugin(org.ow2.proactive.resourcemanager.nodesource.NodeSourcePlugin)

Example 3 with ConfigurableField

use of org.ow2.proactive.resourcemanager.nodesource.common.ConfigurableField in project scheduling by ow2-proactive.

the class NodeSourceParameterHelper method getParametersWithDynamicParametersUpdatedOnly.

public List<Serializable> getParametersWithDynamicParametersUpdatedOnly(Collection<ConfigurableField> configurableFields, Object[] newParameters, List<Serializable> oldParameters) {
    List<Serializable> mergedParameters = new LinkedList<>();
    mergedParameters.addAll(oldParameters);
    Lambda.forEachWithIndex(configurableFields, (configurableField, index) -> {
        Configurable meta = configurableField.getMeta();
        String newValue = getStringValue(newParameters, index, meta);
        String oldValue = getStringValue(oldParameters.toArray(), index, meta);
        this.updateDynamicParameterIfNotEqual(mergedParameters, newValue, oldValue, index, configurableField);
    });
    return mergedParameters;
}
Also used : Serializable(java.io.Serializable) Configurable(org.ow2.proactive.resourcemanager.nodesource.common.Configurable) LinkedList(java.util.LinkedList)

Example 4 with ConfigurableField

use of org.ow2.proactive.resourcemanager.nodesource.common.ConfigurableField in project scheduling by ow2-proactive.

the class RMRest method concatenateParametersAndFileParameters.

private Object[] concatenateParametersAndFileParameters(String[] parameters, String[] fileParameters, Collection<ConfigurableField> fields) {
    int parametersLength = this.getParametersLength(parameters);
    int fileParametersLength = this.getParametersLength(fileParameters);
    Object[] concatenatedParameters = new Object[parametersLength + fileParametersLength];
    int parametersIndex = 0;
    int fileParametersIndex = 0;
    int concatenatedParametersIndex = 0;
    for (ConfigurableField field : fields) {
        if (field.getMeta().credential() || field.getMeta().fileBrowser()) {
            concatenatedParameters[concatenatedParametersIndex] = fileParameters[fileParametersIndex].getBytes();
            fileParametersIndex++;
        } else {
            concatenatedParameters[concatenatedParametersIndex] = parameters[parametersIndex];
            parametersIndex++;
        }
        concatenatedParametersIndex++;
    }
    return concatenatedParameters;
}
Also used : ConfigurableField(org.ow2.proactive.resourcemanager.nodesource.common.ConfigurableField) JSONObject(org.json.simple.JSONObject)

Example 5 with ConfigurableField

use of org.ow2.proactive.resourcemanager.nodesource.common.ConfigurableField in project scheduling by ow2-proactive.

the class PluginDescriptor method findConfigurableFileds.

/*
     * Looks through cls which represents a plugin. Collects a configurable
     * skeleton of the plugin.
     */
private void findConfigurableFileds(Class<?> cls, Object instance) {
    if (cls.getSuperclass() != null && cls.getSuperclass() != Object.class) {
        findConfigurableFileds(cls.getSuperclass(), instance);
    }
    for (Field f : cls.getDeclaredFields()) {
        Configurable configurable = f.getAnnotation(Configurable.class);
        if (configurable != null) {
            String name = f.getName();
            f.setAccessible(true);
            Object valueObj = null;
            try {
                valueObj = f.get(instance);
            } catch (Exception e) {
            }
            String value = valueObj == null ? (this.defaultValues.get(name) != null ? this.defaultValues.get(name) : "") : valueObj.toString();
            configurableFields.add(new ConfigurableField(name, value, configurable));
        }
    }
}
Also used : Field(java.lang.reflect.Field) IOException(java.io.IOException) RMException(org.ow2.proactive.resourcemanager.exception.RMException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

IOException (java.io.IOException)2 RMException (org.ow2.proactive.resourcemanager.exception.RMException)2 File (java.io.File)1 Serializable (java.io.Serializable)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 JSONObject (org.json.simple.JSONObject)1 NodeSourcePlugin (org.ow2.proactive.resourcemanager.nodesource.NodeSourcePlugin)1 Configurable (org.ow2.proactive.resourcemanager.nodesource.common.Configurable)1 ConfigurableField (org.ow2.proactive.resourcemanager.nodesource.common.ConfigurableField)1 PluginDescriptor (org.ow2.proactive.resourcemanager.nodesource.common.PluginDescriptor)1