use of org.ow2.proactive_grid_cloud_portal.cli.json.FieldMetaDataView.Type in project scheduling by ow2-proactive.
the class NodeSource method buildRMNode.
/**
* Builds a RMNode from a raw Node
* @param node the node object
* @param provider the client of the request
* @return the expected RMNode
*/
private RMNode buildRMNode(Node node, Client provider) {
// creating a node access permission
// it could be either PROVIDER/PROVIDER_GROUPS and in this case
// the provider principals will be taken or
// ME/MY_GROUPS (ns creator/ns creator groups) and in this case
// creator's principals will be used
Client permissionOwner = administrator;
if (nodeUserAccessType.equals(AccessType.PROVIDER) || nodeUserAccessType.equals(AccessType.PROVIDER_GROUPS)) {
permissionOwner = provider;
}
// now selecting the type (user or group) and construct the permission
Set<IdentityPrincipal> principals = (Set<IdentityPrincipal>) nodeUserAccessType.getIdentityPrincipals(permissionOwner);
boolean tokenInNode = false;
boolean tokenInNodeSource = nodeUserAccessType.getTokens() != null && nodeUserAccessType.getTokens().length > 0;
try {
String nodeAccessToken = node.getProperty(RMNodeStarter.NODE_ACCESS_TOKEN);
tokenInNode = nodeAccessToken != null && nodeAccessToken.length() > 0;
if (tokenInNode) {
logger.debug("Node " + node.getNodeInformation().getURL() + " is protected by access token " + nodeAccessToken);
// it overrides all other principals
principals.clear();
principals.add(new TokenPrincipal(nodeAccessToken));
}
} catch (Exception e) {
throw new AddingNodesException(e);
}
PrincipalPermission nodeAccessPermission = new PrincipalPermission(node.getNodeInformation().getURL(), principals);
RMNodeImpl rmnode = new RMNodeImpl(node, stub, provider, nodeAccessPermission);
rmnode.setProtectedByToken(tokenInNode || tokenInNodeSource);
return rmnode;
}
use of org.ow2.proactive_grid_cloud_portal.cli.json.FieldMetaDataView.Type in project scheduling by ow2-proactive.
the class SSHInfrastructure method configure.
/**
* Configures the Infrastructure
*
* @param parameters
* parameters[4] : ssh Options, see {@link SSHClient}
* parameters[5] : java path on the remote machines parameters[6]
* : Scheduling path on remote machines parameters[7] : target
* OS' type (Linux, Windows or Cygwin) parameters[8] : extra java
* options parameters[9] : rm cred
* @throws IllegalArgumentException
* configuration failed
*/
@Override
public void configure(Object... parameters) {
super.configure(parameters);
int index = 4;
if (parameters != null && parameters.length >= 10) {
this.sshOptions = parameters[index++].toString();
this.javaPath = parameters[index++].toString();
if (this.javaPath == null || this.javaPath.equals("")) {
throw new IllegalArgumentException("A valid Java path must be supplied.");
}
this.schedulingPath = parameters[index++].toString();
// target OS
if (parameters[index] != null) {
OperatingSystem configuredTargetOs = OperatingSystem.getOperatingSystem(parameters[index++].toString());
if (configuredTargetOs == null) {
throw new IllegalArgumentException("Only 'Linux', 'Windows' and 'Cygwin' are valid values for Target OS Property.");
}
persistedInfraVariables.put(TARGET_OS_OBJ_KEY, configuredTargetOs);
} else {
throw new IllegalArgumentException("Target OS parameter cannot be null");
}
this.javaOptions = parameters[index++].toString();
// credentials
if (parameters[index] == null) {
throw new IllegalArgumentException("Credentials must be specified");
}
try {
persistedInfraVariables.put(CREDENTIALS_KEY, Credentials.getCredentialsBase64((byte[]) parameters[index++]));
} catch (KeyException e) {
throw new IllegalArgumentException("Could not retrieve base64 credentials", e);
}
} else {
throw new IllegalArgumentException("Invalid parameters for infrastructure creation");
}
}
use of org.ow2.proactive_grid_cloud_portal.cli.json.FieldMetaDataView.Type in project scheduling by ow2-proactive.
the class RMStatistics method nodeEvent.
/**
* Handle incoming node events of the Resource Manager
* @param event incoming event
*/
public void nodeEvent(final RMNodeEvent event) {
// Update cumulative times based on activity and inactivity during the last time interval
final long currentTimeStamp = System.nanoTime();
final long timeInterval = currentTimeStamp - this.previousTimeStamp;
this.cumulativeActivityTime += this.busyNodesCount * timeInterval;
this.cumulativeInactivityTime += this.freeNodesCount * timeInterval;
// Update the previous time stamp to the current
this.previousTimeStamp = currentTimeStamp;
// Depending on the event type update nodes count
switch(event.getEventType()) {
case NODE_ADDED:
// Increment the available nodes count
this.availableNodesCount++;
// We define the state of the added node
final NodeState addNodeState = event.getNodeState();
switch(addNodeState) {
case FREE:
this.incrementFreeNodesCount();
break;
case CONFIGURING:
this.incrementConfiguringNodesCount();
break;
case DEPLOYING:
this.incrementDeployingNodesCount();
break;
case LOST:
this.incrementLostNodesCount();
break;
case BUSY:
this.incrementBusyNodesCount();
break;
case DOWN:
this.incrementDownNodesCount();
break;
case TO_BE_REMOVED:
this.incrementToBeRemovedNodesCount();
break;
default:
}
break;
case NODE_REMOVED:
// Get the state of the node before it was removed
final NodeState nodeState = event.getNodeState();
switch(nodeState) {
case FREE:
this.decrementFreeNodesCount();
break;
case BUSY:
this.decrementBusyNodesCount();
break;
case TO_BE_REMOVED:
this.decrementToBeRemovedNodesCount();
break;
case DOWN:
this.decrementDownNodesCount();
break;
case CONFIGURING:
this.decrementConfiguringNodesCount();
break;
case LOST:
this.decrementLostNodesCount();
break;
case DEPLOYING:
this.decrementDeployingNodesCount();
break;
default:
}
this.decrementAvailableNodesCount();
break;
case NODE_STATE_CHANGED:
// Depending on the previous state decrement counters
final NodeState previousNodeState = event.getPreviousNodeState();
if (previousNodeState != null) {
switch(previousNodeState) {
case FREE:
this.decrementFreeNodesCount();
break;
case BUSY:
this.decrementBusyNodesCount();
break;
case TO_BE_REMOVED:
this.decrementToBeRemovedNodesCount();
break;
case DOWN:
this.decrementDownNodesCount();
break;
case CONFIGURING:
this.decrementConfiguringNodesCount();
break;
case LOST:
this.decrementLostNodesCount();
break;
case DEPLOYING:
this.decrementDeployingNodesCount();
break;
default:
}
}
// can't be null
final NodeState currentNodeState = event.getNodeState();
// Depending on the current state increment counters
switch(currentNodeState) {
case FREE:
this.incrementFreeNodesCount();
break;
case BUSY:
this.incrementBusyNodesCount();
break;
case TO_BE_REMOVED:
this.incrementToBeRemovedNodesCount();
break;
case DOWN:
this.incrementDownNodesCount();
break;
case CONFIGURING:
this.incrementConfiguringNodesCount();
break;
case LOST:
this.incrementLostNodesCount();
break;
case DEPLOYING:
this.incrementDeployingNodesCount();
break;
default:
}
default:
}
}
use of org.ow2.proactive_grid_cloud_portal.cli.json.FieldMetaDataView.Type in project scheduling by ow2-proactive.
the class RestDataspaceImpl method retrieve.
/**
* Retrieves single or multiple files from specified location of the server.
* The format of the GET URI is:
* <P>
* {@code http://<rest-server-path>/data/<dataspace>/<path-name>}
* <p>
* Example:
* <p>
* {@code http://localhost:8080/rest/rest/data/user/my-files/my-text-file.txt}
* <ul>
* <li>dataspace: can have two possible values, 'user' or 'global',
* depending on the target <i>DATASPACE</i></li>
* <li>path-name: location from which the file will be retrieved.</li>
* </ul>
* <b>Notes:</b>
* <ul>
* <li>If 'list' is specified as the 'comp' query parameter, an
* {@link ListFile} type object will be return in JSON format. It will contain a list of files and folder contained in the selected
* path.
* </li>
* <li>If 'recursive' is specified as the 'comp' query parameter, an
* {@link ListFile} type object will be return in JSON format. It will contain a list of files and folder contained in the selected
* path and all subfolders.
* </li>
* <li>If the pathname represents a file its contents will be returned as:
* <ul>
* <li>an octet stream, if its a compressed file or the client doesn't
* accept encoded content</li>
* <li>a 'gzip' encoded stream, if the client accepts 'gzip' encoded content
* </li>
* <li>a 'zip' encoded stream, if the client accepts 'zip' encoded contents</li>
* </ul>
* </li>
* <li>If the pathname represents a directory, its contents will be returned
* as 'zip' encoded stream.</li>
* <li>file names or regular expressions can be used as 'includes' and
* 'excludes' query parameters, in order to select which files to be
* returned can be used to select the files returned.</li>
* </ul>
*/
@GET
@Path("/{dataspace}/{path-name:.*}")
public Response retrieve(@HeaderParam("sessionid") String sessionId, @HeaderParam("Accept-Encoding") String encoding, @PathParam("dataspace") String dataspace, @PathParam("path-name") String pathname, @QueryParam("comp") String component, @QueryParam("includes") List<String> includes, @QueryParam("excludes") List<String> excludes) throws NotConnectedRestException, PermissionRestException {
Session session = checkSessionValidity(sessionId);
try {
checkPathParams(dataspace, pathname);
FileObject fo = resolveFile(session, dataspace, pathname);
if (!fo.exists()) {
return notFoundRes();
}
if (!Strings.isNullOrEmpty(component)) {
return componentResponse(component, fo, includes, excludes);
}
if (fo.getType() == FileType.FILE) {
if (VFSZipper.isZipFile(fo)) {
logger.debug(String.format("Retrieving file %s in %s", pathname, dataspace));
return fileComponentResponse(fo);
} else if (Strings.isNullOrEmpty(encoding) || encoding.contains("*") || encoding.contains("gzip")) {
logger.debug(String.format("Retrieving file %s as gzip in %s", pathname, dataspace));
return gzipComponentResponse(pathname, fo);
} else if (encoding.contains("zip")) {
logger.debug(String.format("Retrieving file %s as zip in %s", pathname, dataspace));
return zipComponentResponse(fo, null, null);
} else {
logger.debug(String.format("Retrieving file %s in %s", pathname, dataspace));
return fileComponentResponse(fo);
}
} else {
// folder
if (Strings.isNullOrEmpty(encoding) || encoding.contains("*") || encoding.contains("zip")) {
logger.debug(String.format("Retrieving folder %s as zip in %s", pathname, dataspace));
return zipComponentResponse(fo, includes, excludes);
} else {
return badRequestRes("Folder retrieval only supported with zip encoding.");
}
}
} catch (Throwable error) {
logger.error(String.format("Cannot retrieve %s in %s.", pathname, dataspace), error);
throw rethrow(error);
}
}
use of org.ow2.proactive_grid_cloud_portal.cli.json.FieldMetaDataView.Type in project scheduling by ow2-proactive.
the class FlowScript method getResult.
@Override
protected ScriptResult<FlowAction> getResult(Object evalResult, Bindings bindings) {
try {
FlowAction act = new FlowAction();
/*
* no action defined
*/
if (this.actionType == null || this.actionType.equals(FlowActionType.CONTINUE.toString())) {
act.setType(FlowActionType.CONTINUE);
} else /*
* loop
*/
if (this.actionType.equals(FlowActionType.LOOP.toString())) {
if (this.target == null) {
String msg = "LOOP control flow action requires a target";
logger.error(msg);
return new ScriptResult<FlowAction>(new Exception(msg));
} else {
if (bindings.containsKey(loopVariable)) {
Boolean enabled;
String loopValue = bindings.get(loopVariable).toString();
if ("true".equalsIgnoreCase(loopValue)) {
enabled = Boolean.TRUE;
} else if ("false".equalsIgnoreCase(loopValue)) {
enabled = Boolean.FALSE;
} else {
try {
(new Predictor(loopValue)).nextMatchingDate();
enabled = Boolean.TRUE;
act.setCronExpr(loopValue);
} catch (InvalidPatternException e) {
enabled = Boolean.FALSE;
}
}
if (enabled) {
act.setType(FlowActionType.LOOP);
act.setTarget(this.target);
} else {
act.setType(FlowActionType.CONTINUE);
}
} else {
String msg = "Script environment for LOOP action needs to define variable " + loopVariable;
logger.error(msg);
return new ScriptResult<FlowAction>(new Exception(msg));
}
}
} else /*
* replicate
*/
if (this.actionType.equals(FlowActionType.REPLICATE.toString())) {
if (bindings.containsKey(replicateRunsVariable)) {
act.setType(FlowActionType.REPLICATE);
int args = 1;
Object o = bindings.get(replicateRunsVariable);
try {
args = Integer.parseInt("" + o);
} catch (NumberFormatException e) {
try {
args = (int) Math.floor(Double.parseDouble("" + o));
} catch (Exception e2) {
String msg = "REPLICATE action: could not parse value for variable " + replicateRunsVariable;
logger.error(msg);
return new ScriptResult<FlowAction>(new Exception(msg, e2));
}
}
if (args < 0) {
String msg = "REPLICATE action: value of variable " + replicateRunsVariable + " cannot be negative";
logger.error(msg);
return new ScriptResult<FlowAction>(new Exception(msg));
}
act.setDupNumber(args);
} else {
String msg = "Script environment for REPLICATE action needs to define variable " + replicateRunsVariable;
logger.error(msg);
return new ScriptResult<FlowAction>(new Exception(msg));
}
} else /*
* if
*/
if (this.actionType.equals(FlowActionType.IF.toString())) {
if (this.target == null) {
String msg = "IF action requires a target ";
logger.error(msg);
return new ScriptResult<FlowAction>(new Exception(msg));
} else if (this.targetElse == null) {
String msg = "IF action requires an ELSE target ";
logger.error(msg);
return new ScriptResult<FlowAction>(new Exception(msg));
} else {
act.setType(FlowActionType.IF);
if (bindings.containsKey(branchSelectionVariable)) {
String val = new String((String) bindings.get(branchSelectionVariable));
if (val.toLowerCase().equals(ifBranchSelectedVariable)) {
act.setTarget(this.target);
act.setTargetElse(this.targetElse);
} else if (val.toLowerCase().equals(elseBranchSelectedVariable)) {
act.setTarget(this.targetElse);
act.setTargetElse(this.target);
} else {
String msg = "IF action: value for " + branchSelectionVariable + " needs to be one of " + ifBranchSelectedVariable + " or " + elseBranchSelectedVariable;
logger.error(msg);
return new ScriptResult<FlowAction>(new Exception(msg));
}
} else {
String msg = "Environment for IF action needs to define variable " + branchSelectionVariable;
logger.error(msg);
return new ScriptResult<FlowAction>(new Exception(msg));
}
if (this.targetContinuation != null) {
act.setTargetContinuation(this.targetContinuation);
}
}
} else /*
* unknown action
*/
{
String msg = actionType + " action type unknown";
logger.error(msg);
return new ScriptResult<FlowAction>(new Exception(msg));
}
return new ScriptResult<FlowAction>(act);
} catch (Throwable th) {
return new ScriptResult<FlowAction>(th);
}
}
Aggregations