Search in sources :

Example 11 with Client

use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.

the class HAC method select.

/**
 * Selects a set of closest nodes from specified list.
 * The proximity between nodes is defined by distance function.
 *
 * @param number desired nodes number
 * @param from list of "free" nodes
 * @return list of nodes to be provided to the client
 */
public List<Node> select(int number, List<Node> from) {
    if (from.size() == 0) {
        // return empty list
        return new LinkedList<>();
    }
    // initializing cluster distances map
    // cluster is a group of nodes, initially each cluster consist of one node
    logger.debug("Initializing clusters map");
    HashMap<Cluster<Node>, HashMap<Cluster<Node>, Long>> clusterDistances = initClusterDistances(from);
    // no topology information for provided nodes
    if (from.size() > 0 && clusterDistances.size() == 0) {
        throw new TopologyException("Topology information is not available");
    }
    Cluster<Node> target = null;
    if (pivot.size() > 0) {
        // fixed orientation clustering
        Iterator<Node> it = pivot.iterator();
        Node pivotNode = it.next();
        target = new Cluster<>(getNodeId(pivotNode), pivotNode);
        // merging pivot nodes into one cluster and recalculating distances
        logger.debug("Merging pivot nodes into one cluster");
        while (it.hasNext()) {
            // merging clusters and recalculating distances between others
            pivotNode = it.next();
            Cluster<Node> pivotCluster = new Cluster<>(getNodeId(pivotNode), pivotNode);
            target = recalculateDistances(target, pivotCluster, clusterDistances);
        }
        // clustering centralized to the pivot
        logger.debug("Begin centralized hierarchical agglomerative clustering");
        while (clusterDistances.size() > 1 && target.size() < (number + pivot.size())) {
            Cluster<Node> closest = findClosestClustersTo(target, clusterDistances);
            if (closest == null) {
                // no clusters found => cannot merge anything => stop where we are
                break;
            }
            // merging clusters and recalculating distances between others
            target = recalculateDistances(target, closest, clusterDistances);
        }
        // removing pivot nodes from the result
        target.remove(pivot);
    } else {
        logger.debug("Begin hierarchical agglomerative clustering");
        target = (Cluster<Node>) clusterDistances.keySet().iterator().next();
        Cluster<Node> largest = target;
        // floating clustering
        while (clusterDistances.size() > 1) {
            // finding two clusters to merge according
            Cluster<Node>[] clustersToMerge = findClosestClusters(clusterDistances);
            if (clustersToMerge == null) {
                // stop the process
                break;
            }
            // merging clusters and recalculating distances between others
            target = recalculateDistances(clustersToMerge[0], clustersToMerge[1], clusterDistances);
            if (target.size() >= largest.size()) {
                largest = target;
            }
            if (target.size() == number) {
                // found all the nodes we need
                break;
            } else if (target.size() > number) {
                // found more nodes that we need,
                // target cluster contains all nodes from another cluster
                // largest is the target here
                logger.debug("Number of node in the cluster exceeded required node number " + target.size() + " vs " + number);
                Cluster<Node> anotherCluster = clustersToMerge[0] == target ? clustersToMerge[1] : clustersToMerge[0];
                target.removeLast(anotherCluster.size());
                final Cluster<Node> finalTarget = target;
                Comparator<Node> nodeDistanceComparator = new Comparator<Node>() {

                    public int compare(Node n1, Node n2) {
                        long res = getDistance(n1, finalTarget) - getDistance(n2, finalTarget);
                        if (res < 0) {
                            return -1;
                        } else if (res > 0) {
                            return 1;
                        } else {
                            return 0;
                        }
                    }
                };
                // sorting nodes in the smaller cluster according to their distances to target
                Collections.sort(anotherCluster.getElements(), nodeDistanceComparator);
                int neededNodesNumber = number - target.size();
                target.add(anotherCluster.getElements().subList(0, neededNodesNumber));
                break;
            }
        }
        target = largest;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Found " + target.size() + " nodes out of " + number + ": " + target);
    }
    return target.getElements();
}
Also used : HashMap(java.util.HashMap) Node(org.objectweb.proactive.core.node.Node) LinkedList(java.util.LinkedList) TopologyException(org.ow2.proactive.resourcemanager.frontend.topology.TopologyException) Comparator(java.util.Comparator)

Example 12 with Client

use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.

the class RestFuncTHelper method startRestfulSchedulerWebapp.

public static void startRestfulSchedulerWebapp(int nbNodes) throws Exception {
    // Kill all children processes on exit
    org.apache.log4j.BasicConfigurator.configure(new org.apache.log4j.varia.NullAppender());
    CookieBasedProcessTreeKiller.registerKillChildProcessesOnShutdown("rest_tests");
    List<String> cmd = new ArrayList<>();
    String javaPath = RestFuncTUtils.getJavaPathFromSystemProperties();
    cmd.add(javaPath);
    cmd.add("-Djava.security.manager");
    cmd.add("-Dresteasy.allowGzip=true");
    cmd.add("-Dfile.encoding=UTF-8");
    cmd.add(CentralPAPropertyRepository.JAVA_SECURITY_POLICY.getCmdLine() + toPath(serverJavaPolicy));
    cmd.add(CentralPAPropertyRepository.PA_HOME.getCmdLine() + getSchedHome());
    cmd.add(PASchedulerProperties.SCHEDULER_HOME.getCmdLine() + getSchedHome());
    cmd.add(PAResourceManagerProperties.RM_HOME.getCmdLine() + getRmHome());
    cmd.add(PAResourceManagerProperties.RM_DB_HIBERNATE_DROPDB.getCmdLine() + System.getProperty("rm.deploy.dropDB", "true"));
    cmd.add(PAResourceManagerProperties.RM_DB_HIBERNATE_CONFIG.getCmdLine() + toPath(rmHibernateConfig));
    cmd.add(PASchedulerProperties.SCHEDULER_DB_HIBERNATE_DROPDB.getCmdLine() + System.getProperty("scheduler.deploy.dropDB", "true"));
    cmd.add(PASchedulerProperties.SCHEDULER_DB_HIBERNATE_CONFIG.getCmdLine() + toPath(schedHibernateConfig));
    cmd.add(WebProperties.WEB_HTTPS.getCmdLine() + "true");
    cmd.add(CentralPAPropertyRepository.PA_COMMUNICATION_PROTOCOL.getCmdLine() + "pnp");
    cmd.add(PNPConfig.PA_PNP_PORT.getCmdLine() + "1200");
    cmd.add("-cp");
    cmd.add(getClassPath());
    cmd.add(SchedulerStarter.class.getName());
    cmd.add("-ln");
    cmd.add("" + nbNodes);
    ProcessBuilder processBuilder = new ProcessBuilder(cmd);
    processBuilder.redirectErrorStream(true);
    schedProcess = processBuilder.start();
    ProcessStreamReader out = new ProcessStreamReader("scheduler-output: ", schedProcess.getInputStream());
    out.start();
    // RM and scheduler are on the same url
    String port = "1200";
    String url = "pnp://localhost:" + port + "/";
    // Connect a scheduler client
    SchedulerAuthenticationInterface schedAuth = SchedulerConnection.waitAndJoin(url, TimeUnit.SECONDS.toMillis(120));
    schedulerPublicKey = schedAuth.getPublicKey();
    Credentials schedCred = RestFuncTUtils.createCredentials("admin", "admin", schedulerPublicKey);
    scheduler = schedAuth.login(schedCred);
    // Connect a rm client
    RMAuthentication rmAuth = RMConnection.waitAndJoin(url, TimeUnit.SECONDS.toMillis(120));
    Credentials rmCredentials = getRmCredentials();
    rm = rmAuth.login(rmCredentials);
    restServerUrl = "https://localhost:8443/rest/";
    restfulSchedulerUrl = restServerUrl + "scheduler";
    restfulRmUrl = restServerUrl + "rm";
    await().atMost(new Duration(900, TimeUnit.SECONDS)).until(restIsStarted());
}
Also used : SchedulerAuthenticationInterface(org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface) Duration(com.jayway.awaitility.Duration) SchedulerStarter(org.ow2.proactive.scheduler.util.SchedulerStarter) RMAuthentication(org.ow2.proactive.resourcemanager.authentication.RMAuthentication) ProcessStreamReader(functionaltests.utils.ProcessStreamReader) Credentials(org.ow2.proactive.authentication.crypto.Credentials)

Example 13 with Client

use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.

the class RMDeployingNodeTest method createDeployingNode.

private RMDeployingNode createDeployingNode(String name) {
    Client client = Mockito.mock(Client.class);
    NodeSource nodeSource = Mockito.mock(NodeSource.class);
    return new RMDeployingNode(name, nodeSource, "command", client);
}
Also used : NodeSource(org.ow2.proactive.resourcemanager.nodesource.NodeSource) Client(org.ow2.proactive.resourcemanager.authentication.Client)

Example 14 with Client

use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.

the class RMNodeImplTest method testSetConfiguringRmNodeIniatiallyDown.

@Test
public void testSetConfiguringRmNodeIniatiallyDown() {
    rmNode.setDown();
    Client owner = rmNode.getOwner();
    long stateChangeTime = rmNode.getStateChangeTime();
    assertThat(owner).isNotEqualTo(client);
    assertThat(rmNode.isConfiguring()).isFalse();
    assertThat(rmNode.getState()).isEqualTo(NodeState.DOWN);
    rmNode.setConfiguring(client);
    assertThat(owner).isEqualTo(owner);
    assertThat(rmNode.isConfiguring()).isFalse();
    assertThat(rmNode.getState()).isEqualTo(NodeState.DOWN);
    assertThat(rmNode.getStateChangeTime()).isEqualTo(stateChangeTime);
}
Also used : Client(org.ow2.proactive.resourcemanager.authentication.Client) Test(org.junit.Test)

Example 15 with Client

use of org.ow2.proactive.resourcemanager.authentication.Client in project scheduling by ow2-proactive.

the class RMNodeImplTest method testSetConfiguring.

@Test
public void testSetConfiguring() throws InterruptedException {
    Client owner = rmNode.getOwner();
    long stateChangeTime = rmNode.getStateChangeTime();
    assertThat(owner).isNotEqualTo(client);
    assertThat(rmNode.isConfiguring()).isFalse();
    assertThat(rmNode.getState()).isNotEqualTo(NodeState.CONFIGURING);
    assertThat(rmNode.getState()).isNotEqualTo(NodeState.DOWN);
    TimeUnit.MILLISECONDS.sleep(1);
    rmNode.setConfiguring(client);
    // Not sure to understand why Client instance is passed to setConfiguring since
    // the internal value is not updated based on the parameter. However, the
    // behaviour has not changed since years, so there might be some reasons (or not)
    assertThat(owner).isEqualTo(owner);
    assertThat(rmNode.isConfiguring()).isTrue();
    assertThat(rmNode.getState()).isEqualTo(NodeState.CONFIGURING);
    assertThat(rmNode.getStateChangeTime()).isGreaterThan(stateChangeTime);
}
Also used : Client(org.ow2.proactive.resourcemanager.authentication.Client) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)69 ISchedulerClient (org.ow2.proactive.scheduler.rest.ISchedulerClient)36 Client (org.ow2.proactive.resourcemanager.authentication.Client)31 JobId (org.ow2.proactive.scheduler.common.job.JobId)30 TaskFlowJob (org.ow2.proactive.scheduler.common.job.TaskFlowJob)28 NonTerminatingJob (functionaltests.jobs.NonTerminatingJob)25 SimpleJob (functionaltests.jobs.SimpleJob)25 Job (org.ow2.proactive.scheduler.common.job.Job)25 ResteasyClient (org.jboss.resteasy.client.jaxrs.ResteasyClient)18 ResteasyWebTarget (org.jboss.resteasy.client.jaxrs.ResteasyWebTarget)18 ListFile (org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile)18 File (java.io.File)17 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)13 TaskResult (org.ow2.proactive.scheduler.common.task.TaskResult)13 NotConnectedRestException (org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException)11 Node (org.objectweb.proactive.core.node.Node)9 IOException (java.io.IOException)8 NotConnectedException (org.ow2.proactive.scheduler.common.exception.NotConnectedException)8 JobInfo (org.ow2.proactive.scheduler.common.job.JobInfo)8 NodeSet (org.ow2.proactive.utils.NodeSet)7