Search in sources :

Example 1 with DeploymentEvent

use of org.apache.ignite.events.DeploymentEvent in project ignite by apache.

the class GridCommandHandlerInterruptCommandTest method waitForTaskEvent.

/**
 * Method subscribe on task event and return a latch for waiting.
 *
 * @param ignite Ignite.
 * @param taskName Task name.
 * @return Latch which will open after event received.
 */
private CountDownLatch waitForTaskEvent(IgniteEx ignite, String taskName) {
    CountDownLatch startTaskLatch = new CountDownLatch(1);
    ignite.events().localListen((evt) -> {
        assertTrue(evt instanceof DeploymentEvent);
        if (taskName.equals(((DeploymentEvent) evt).alias())) {
            startTaskLatch.countDown();
            return false;
        }
        return true;
    }, EventType.EVT_TASK_DEPLOYED);
    return startTaskLatch;
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) DeploymentEvent(org.apache.ignite.events.DeploymentEvent)

Example 2 with DeploymentEvent

use of org.apache.ignite.events.DeploymentEvent in project ignite by apache.

the class GridDeploymentLocalStore method recordDeploy.

/**
 * Records deploy event.
 * <p>
 * This needs to be called in synchronized block.
 *
 * @param cls Deployed class.
 * @param alias Class alias.
 * @param recordEvt Flag indicating whether to record events.
 */
private void recordDeploy(Class<?> cls, String alias, boolean recordEvt) {
    assert cls != null;
    boolean isTask = isTask(cls);
    String msg = (isTask ? "Task" : "Class") + " locally deployed: " + cls;
    if (recordEvt && ctx.event().isRecordable(isTask ? EVT_TASK_DEPLOYED : EVT_CLASS_DEPLOYED)) {
        DeploymentEvent evt = new DeploymentEvent();
        evt.message(msg);
        evt.node(ctx.discovery().localNode());
        evt.type(isTask ? EVT_TASK_DEPLOYED : EVT_CLASS_DEPLOYED);
        evt.alias(alias);
        ctx.event().record(evt);
    }
    // Don't record JDK or Grid classes.
    if (U.isGrid(cls) || U.isJdk(cls))
        return;
    if (log.isInfoEnabled())
        log.info(msg);
}
Also used : DeploymentEvent(org.apache.ignite.events.DeploymentEvent)

Example 3 with DeploymentEvent

use of org.apache.ignite.events.DeploymentEvent in project ignite by apache.

the class GridDeploymentLocalStore method recordDeployFailed.

/**
 * Records deploy event.
 *
 * @param cls Deployed class.
 * @param clsLdr Class loader.
 * @param recordEvt Flag indicating whether to record events.
 */
private void recordDeployFailed(Class<?> cls, ClassLoader clsLdr, boolean recordEvt) {
    assert cls != null;
    assert clsLdr != null;
    boolean isTask = isTask(cls);
    String msg = "Failed to deploy " + (isTask ? "task" : "class") + " [cls=" + cls + ", clsLdr=" + clsLdr + ']';
    if (recordEvt && ctx.event().isRecordable(isTask ? EVT_CLASS_DEPLOY_FAILED : EVT_TASK_DEPLOY_FAILED)) {
        String taskName = isTask ? U.getTaskName((Class<? extends ComputeTask<?, ?>>) cls) : null;
        DeploymentEvent evt = new DeploymentEvent();
        evt.message(msg);
        evt.node(ctx.discovery().localNode());
        evt.type(isTask ? EVT_CLASS_DEPLOY_FAILED : EVT_TASK_DEPLOY_FAILED);
        evt.alias(taskName);
        ctx.event().record(evt);
    }
    if (log.isInfoEnabled())
        log.info(msg);
}
Also used : ComputeTask(org.apache.ignite.compute.ComputeTask) DeploymentEvent(org.apache.ignite.events.DeploymentEvent)

Example 4 with DeploymentEvent

use of org.apache.ignite.events.DeploymentEvent in project ignite by apache.

the class GridP2PUserVersionChangeSelfTest method testRedeployOnNodeRestartContinuousMode.

/**
 * @throws Exception If failed.
 */
@Test
public void testRedeployOnNodeRestartContinuousMode() throws Exception {
    depMode = DeploymentMode.CONTINUOUS;
    try {
        Ignite ignite1 = startGrid(1);
        Ignite ignite2 = startGrid(2);
        GridTestExternalClassLoader ldr = new GridTestExternalClassLoader(new URL[] { new URL(GridTestProperties.getProperty("p2p.uri.cls")) });
        Class task1 = ldr.loadClass(TEST_TASK_NAME);
        final CountDownLatch undeployed = new CountDownLatch(1);
        ignite2.events().localListen(new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event evt) {
                if (evt.type() == EVT_TASK_UNDEPLOYED && ((DeploymentEvent) evt).alias().equals(TEST_TASK_NAME))
                    undeployed.countDown();
                return true;
            }
        }, EVT_TASK_UNDEPLOYED);
        Integer res1 = (Integer) ignite1.compute().execute(task1, ignite2.cluster().localNode().id());
        stopGrid(1);
        ignite1 = startGrid(1);
        Integer res2 = (Integer) ignite1.compute().execute(task1, ignite2.cluster().localNode().id());
        assert !undeployed.await(3000, MILLISECONDS);
        assert res1.equals(res2);
    } finally {
        stopGrid(1);
        stopGrid(2);
    }
}
Also used : GridTestExternalClassLoader(org.apache.ignite.testframework.GridTestExternalClassLoader) Event(org.apache.ignite.events.Event) DeploymentEvent(org.apache.ignite.events.DeploymentEvent) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) URL(java.net.URL) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 5 with DeploymentEvent

use of org.apache.ignite.events.DeploymentEvent in project ignite by apache.

the class GridP2PUserVersionChangeSelfTest method checkRedeployVersionChange.

/**
 * @throws Exception If failed.
 */
private void checkRedeployVersionChange() throws Exception {
    try {
        Ignite ignite1 = startGrid(1);
        Ignite ignite2 = startGrid(2);
        GridTestExternalClassLoader ldr = new GridTestExternalClassLoader(new URL[] { new URL(GridTestProperties.getProperty("p2p.uri.cls")) }, Collections.singletonMap("META-INF/ignite.xml", makeUserVersion("1").getBytes()));
        Class task1 = ldr.loadClass(TEST_TASK_NAME);
        final CountDownLatch undeployed = new CountDownLatch(1);
        ignite2.events().localListen(new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event evt) {
                if (evt.type() == EVT_TASK_UNDEPLOYED && ((DeploymentEvent) evt).alias().equals(TEST_TASK_NAME))
                    undeployed.countDown();
                return true;
            }
        }, EVT_TASK_UNDEPLOYED);
        Integer res1 = (Integer) ignite1.compute().execute(task1, ignite2.cluster().localNode().id());
        stopGrid(1);
        ldr.setResourceMap(Collections.singletonMap("META-INF/ignite.xml", makeUserVersion("2").getBytes()));
        ignite1 = startGrid(1);
        Integer res2 = (Integer) ignite1.compute().execute(task1, ignite2.cluster().localNode().id());
        assert !res1.equals(res2);
        // Allow P2P timeout to expire.
        assert undeployed.await(30000, MILLISECONDS);
    } finally {
        stopGrid(1);
        stopGrid(2);
    }
}
Also used : GridTestExternalClassLoader(org.apache.ignite.testframework.GridTestExternalClassLoader) Event(org.apache.ignite.events.Event) DeploymentEvent(org.apache.ignite.events.DeploymentEvent) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch) URL(java.net.URL)

Aggregations

DeploymentEvent (org.apache.ignite.events.DeploymentEvent)7 CountDownLatch (java.util.concurrent.CountDownLatch)4 URL (java.net.URL)3 Ignite (org.apache.ignite.Ignite)3 Event (org.apache.ignite.events.Event)3 GridTestExternalClassLoader (org.apache.ignite.testframework.GridTestExternalClassLoader)3 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)2 Test (org.junit.Test)2 ComputeTask (org.apache.ignite.compute.ComputeTask)1