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