Search in sources :

Example 86 with Session

use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.

the class RMRest method checkAccess.

private RMProxyUserInterface checkAccess(String sessionId) throws NotConnectedException {
    Session session = sessionStore.get(sessionId);
    if (session == null) {
        throw new NotConnectedException("you are not connected to the scheduler, you should log on first");
    }
    RMProxyUserInterface s = session.getRM();
    if (s == null) {
        throw new NotConnectedException("you are not connected to the scheduler, you should log on first");
    }
    return session.getRM();
}
Also used : NotConnectedException(org.ow2.proactive.scheduler.common.exception.NotConnectedException) RMProxyUserInterface(org.ow2.proactive.resourcemanager.common.util.RMProxyUserInterface) Session(org.ow2.proactive_grid_cloud_portal.common.Session)

Example 87 with Session

use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.

the class RMRest method createNodeSource.

/**
 * @deprecated  As of version 8.1, replaced by {@link #defineNodeSource(String, String,String, String[], String[],
 * String, String[], String[], String)} and {@link #deployNodeSource(String, String)}
 *
 * Create a NodeSource
 * <p>
 *
 * @param sessionId
 *            current session id
 * @param nodeSourceName
 *            name of the node source to create
 * @param infrastructureType
 *            fully qualified class name of the infrastructure to create
 * @param infrastructureParameters
 *            String parameters of the infrastructure, without the
 *            parameters containing files or credentials
 * @param infrastructureFileParameters
 *            File or credential parameters
 * @param policyType
 *            fully qualified class name of the policy to create
 * @param policyParameters
 *            String parameters of the policy, without the parameters
 *            containing files or credentials
 * @param policyFileParameters
 *            File or credential parameters
 * @param nodesRecoverable
 *            Whether the nodes can be recovered after a crash of the RM
 * @return true if a node source has been created
 * @throws NotConnectedException
 */
@Deprecated
@Override
@POST
@Path("nodesource/create/recovery")
@Produces("application/json")
public NSState createNodeSource(@HeaderParam("sessionid") String sessionId, @FormParam("nodeSourceName") String nodeSourceName, @FormParam("infrastructureType") String infrastructureType, @FormParam("infrastructureParameters") String[] infrastructureParameters, @FormParam("infrastructureFileParameters") String[] infrastructureFileParameters, @FormParam("policyType") String policyType, @FormParam("policyParameters") String[] policyParameters, @FormParam("policyFileParameters") String[] policyFileParameters, @FormParam("nodesRecoverable") String nodesRecoverable) throws NotConnectedException {
    ResourceManager rm = checkAccess(sessionId);
    NSState nsState = new NSState();
    Object[] allInfrastructureParameters = this.getAllInfrastructureParameters(infrastructureType, infrastructureParameters, infrastructureFileParameters, rm);
    Object[] allPolicyParameters = this.getAllPolicyParameters(policyType, policyParameters, policyFileParameters, rm);
    try {
        nsState.setResult(rm.createNodeSource(nodeSourceName, infrastructureType, allInfrastructureParameters, policyType, allPolicyParameters, Boolean.parseBoolean(nodesRecoverable)).getBooleanValue());
    } catch (RuntimeException ex) {
        nsState.setResult(false);
        nsState.setErrorMessage(cleanDisplayedErrorMessage(ex.getMessage()));
        nsState.setStackTrace(StringEscapeUtils.escapeJson(getStackTrace(ex)));
    } finally {
        return nsState;
    }
}
Also used : ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) NSState(org.ow2.proactive.resourcemanager.common.NSState) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Example 88 with Session

use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.

the class RMRest method getStatHistory.

/**
 * Return the statistic history contained in the RM's RRD database,
 * without redundancy, in a friendly JSON format.
 *
 * The following sources will be queried from the RRD DB :<pre>
 * 	{ "BusyNodesCount",
 *    "FreeNodesCount",
 *    "DownNodesCount",
 *    "AvailableNodesCount",
 *    "AverageActivity" }</pre>
 *
 * @param sessionId a valid session
 * @param range a String of 5 chars, one for each stat history source, indicating the time range to fetch
 *      for each source. Each char can be:<ul>
 *            <li>'a' 1 minute
 *            <li>'m' 10 minutes
 *            <li>'h' 1 hour
 *            <li>'H' 8 hours
 *            <li>'d' 1 day
 *            <li>'w' 1 week
 *            <li>'M' 1 month
 *            <li>'y' 1 year</ul>
 * @return a JSON object containing a key for each source
 * @throws InstanceNotFoundException
 * @throws IntrospectionException
 * @throws ReflectionException
 * @throws IOException
 * @throws MalformedObjectNameException
 * @throws NullPointerException
 * @throws InterruptedException
 * @throws NotConnectedException
 */
@Override
@GET
@GZIP
@Path("stathistory")
@Produces("application/json")
public String getStatHistory(@HeaderParam("sessionid") String sessionId, @QueryParam("range") String range) throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException, MalformedObjectNameException, NullPointerException, InterruptedException, NotConnectedException {
    RMProxyUserInterface rm = checkAccess(sessionId);
    // to make it recognizable by StatHistoryCaching
    if (range.length() > dataSources.length) {
        range = range.substring(0, dataSources.length);
    }
    // complete range if too short
    while (range.length() < dataSources.length) {
        range += 'a';
    }
    StatHistoryCacheEntry cache = StatHistoryCaching.getInstance().getEntry(range);
    // found unexpired cache entry matching the parameters: return it immediately
    if (cache != null) {
        return cache.getValue();
    }
    long l1 = System.currentTimeMillis();
    ObjectName on = new ObjectName(RMJMXBeans.RUNTIMEDATA_MBEAN_NAME);
    AttributeList attrs = rm.getMBeanAttributes(on, new String[] { "StatisticHistory" });
    Attribute attr = (Attribute) attrs.get(0);
    // content of the RRD4J database backing file
    byte[] rrd4j = (byte[]) attr.getValue();
    File rrd4jDb = File.createTempFile("database", "rr4dj");
    rrd4jDb.deleteOnExit();
    try (OutputStream out = new FileOutputStream(rrd4jDb)) {
        out.write(rrd4j);
    }
    // create RRD4J DB, should be identical to the one held by the RM
    RrdDb db = new RrdDb(rrd4jDb.getAbsolutePath(), true);
    long timeEnd = db.getLastUpdateTime();
    // force float separator for JSON parsing
    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.US);
    otherSymbols.setDecimalSeparator('.');
    // formatting will greatly reduce response size
    DecimalFormat formatter = new DecimalFormat("###.###", otherSymbols);
    // construct the JSON response directly in a String
    StringBuilder result = new StringBuilder();
    result.append("{");
    for (int i = 0; i < dataSources.length; i++) {
        String dataSource = dataSources[i];
        char zone = range.charAt(i);
        long timeStart;
        switch(zone) {
            default:
            case // 1 minute
            'a':
                timeStart = timeEnd - 60;
                break;
            case // 10 minute
            'm':
                timeStart = timeEnd - 60 * 10;
                break;
            case // 1 hours
            'h':
                timeStart = timeEnd - 60 * 60;
                break;
            case // 8 hours
            'H':
                timeStart = timeEnd - 60 * 60 * 8;
                break;
            case // 1 day
            'd':
                timeStart = timeEnd - 60 * 60 * 24;
                break;
            case // 1 week
            'w':
                timeStart = timeEnd - 60 * 60 * 24 * 7;
                break;
            case // 1 month
            'M':
                timeStart = timeEnd - 60 * 60 * 24 * 28;
                break;
            case // 1 year
            'y':
                timeStart = timeEnd - 60 * 60 * 24 * 365;
                break;
        }
        FetchRequest req = db.createFetchRequest(ConsolFun.AVERAGE, timeStart, timeEnd);
        req.setFilter(dataSource);
        FetchData fetchData = req.fetchData();
        result.append("\"").append(dataSource).append("\":[");
        double[] values = fetchData.getValues(dataSource);
        for (int j = 0; j < values.length; j++) {
            if (Double.compare(Double.NaN, values[j]) == 0) {
                result.append("null");
            } else {
                result.append(formatter.format(values[j]));
            }
            if (j < values.length - 1)
                result.append(',');
        }
        result.append(']');
        if (i < dataSources.length - 1)
            result.append(',');
    }
    result.append("}");
    db.close();
    rrd4jDb.delete();
    String ret = result.toString();
    StatHistoryCaching.getInstance().addEntry(range, l1, ret);
    return ret;
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) DecimalFormat(java.text.DecimalFormat) FetchData(org.rrd4j.core.FetchData) ObjectName(javax.management.ObjectName) StatHistoryCacheEntry(org.ow2.proactive_grid_cloud_portal.common.StatHistoryCaching.StatHistoryCacheEntry) FileOutputStream(java.io.FileOutputStream) RMProxyUserInterface(org.ow2.proactive.resourcemanager.common.util.RMProxyUserInterface) FetchRequest(org.rrd4j.core.FetchRequest) RrdDb(org.rrd4j.core.RrdDb) File(java.io.File) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) GZIP(org.jboss.resteasy.annotations.GZIP)

Example 89 with Session

use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.

the class RMRest method undeployNodeSource.

/**
 * Remove the nodes of the node source and keep the node source undeployed
 *
 * @param sessionId a valid session id
 * @param nodeSourceName the name of the node source to undeploy
 * @return the result of the action, possibly containing the error message
 * @throws NotConnectedException
 */
@Override
@PUT
@Path("nodesource/undeploy")
@Produces("application/json")
public NSState undeployNodeSource(@HeaderParam("sessionid") String sessionId, @FormParam("nodeSourceName") String nodeSourceName, @FormParam("preempt") boolean preempt) throws NotConnectedException {
    ResourceManager rm = checkAccess(sessionId);
    NSState nsState = new NSState();
    try {
        nsState.setResult(rm.undeployNodeSource(nodeSourceName, preempt).getBooleanValue());
    } catch (RuntimeException ex) {
        nsState.setResult(false);
        nsState.setErrorMessage(cleanDisplayedErrorMessage(ex.getMessage()));
        nsState.setStackTrace(StringEscapeUtils.escapeJson(getStackTrace(ex)));
    }
    return nsState;
}
Also used : ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) NSState(org.ow2.proactive.resourcemanager.common.NSState) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 90 with Session

use of org.ow2.proactive_grid_cloud_portal.common.Session in project scheduling by ow2-proactive.

the class SchedulerRestClient method list.

public ListFile list(String sessionId, String dataspacePath, String pathname) throws Exception {
    StringBuffer uriTmpl = (new StringBuffer()).append(restEndpointURL).append(addSlashIfMissing(restEndpointURL)).append("data/").append(dataspacePath).append('/');
    ResteasyClient client = new ResteasyClientBuilder().httpEngine(httpEngine).providerFactory(providerFactory).build();
    ResteasyWebTarget target = client.target(uriTmpl.toString()).path(pathname).queryParam("comp", "list");
    Response response = null;
    try {
        response = target.request().header("sessionid", sessionId).get();
        if (response.getStatus() != HttpURLConnection.HTTP_OK) {
            if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) {
                throw new NotConnectedRestException("User not authenticated or session timeout.");
            } else {
                throwException(String.format("Cannot list the specified location: %s", pathname), response);
            }
        }
        return response.readEntity(ListFile.class);
    } finally {
        if (response != null) {
            response.close();
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) ResteasyClient(org.jboss.resteasy.client.jaxrs.ResteasyClient) ResteasyWebTarget(org.jboss.resteasy.client.jaxrs.ResteasyWebTarget) NotConnectedRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)

Aggregations

Path (javax.ws.rs.Path)49 Produces (javax.ws.rs.Produces)47 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)39 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)37 Scheduler (org.ow2.proactive.scheduler.common.Scheduler)36 PermissionException (org.ow2.proactive.scheduler.common.exception.PermissionException)34 GET (javax.ws.rs.GET)32 PermissionRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException)29 UnknownJobException (org.ow2.proactive.scheduler.common.exception.UnknownJobException)25 UnknownJobRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.UnknownJobRestException)24 GZIP (org.jboss.resteasy.annotations.GZIP)23 Session (org.ow2.proactive_grid_cloud_portal.common.Session)18 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)17 ArrayList (java.util.ArrayList)16 ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)15 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)15 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)15 JobState (org.ow2.proactive.scheduler.common.job.JobState)12 IOException (java.io.IOException)11 POST (javax.ws.rs.POST)11