Search in sources :

Example 1 with ShutdownPolicy

use of org.apache.ignite.ShutdownPolicy in project ignite by apache.

the class GridCommandHandlerTest method testShutdownPolicyChange.

/**
 * Change shutdown policy through command.
 *
 * @throws Exception If failed.
 */
@Test
public void testShutdownPolicyChange() throws Exception {
    Ignite ignite = startGrids(1);
    assertFalse(ignite.cluster().active());
    ignite.cluster().active(true);
    ShutdownPolicy policyToChange = null;
    for (ShutdownPolicy policy : ShutdownPolicy.values()) {
        if (policy != ignite.cluster().shutdownPolicy())
            policyToChange = policy;
    }
    assertNotNull(policyToChange);
    injectTestSystemOut();
    assertEquals(EXIT_CODE_OK, execute("--shutdown-policy", policyToChange.name()));
    assertSame(policyToChange, ignite.cluster().shutdownPolicy());
    String out = testOut.toString();
    assertContains(log, out, "Cluster shutdown policy is " + policyToChange);
}
Also used : ShutdownPolicy(org.apache.ignite.ShutdownPolicy) Ignite(org.apache.ignite.Ignite) IgniteCacheGroupsWithRestartsTest(org.apache.ignite.internal.processors.cache.persistence.db.IgniteCacheGroupsWithRestartsTest) AbstractSnapshotSelfTest.doSnapshotCancellationTest(org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.doSnapshotCancellationTest) Test(org.junit.Test)

Example 2 with ShutdownPolicy

use of org.apache.ignite.ShutdownPolicy in project ignite by apache.

the class GridDiscoveryManager method checkAttributes.

/**
 * Checks whether attributes of the local node are consistent with remote nodes.
 *
 * @param nodes List of remote nodes to check attributes on.
 * @throws IgniteCheckedException In case of error.
 */
private void checkAttributes(Iterable<ClusterNode> nodes) throws IgniteCheckedException {
    ClusterNode locNode = getSpi().getLocalNode();
    assert locNode != null;
    // Fetch local node attributes once.
    String locPreferIpV4 = locNode.attribute("java.net.preferIPv4Stack");
    Object locMode = locNode.attribute(ATTR_DEPLOYMENT_MODE);
    int locJvmMajVer = nodeJavaMajorVersion(locNode);
    boolean locP2pEnabled = locNode.attribute(ATTR_PEER_CLASSLOADING);
    ShutdownPolicy locShutdownPolicy = ShutdownPolicy.fromOrdinal(locNode.attribute(ATTR_SHUTDOWN_POLICY));
    boolean ipV4Warned = false;
    boolean jvmMajVerWarned = false;
    Boolean locMarshUseDfltSuid = locNode.attribute(ATTR_MARSHALLER_USE_DFLT_SUID);
    boolean locMarshUseDfltSuidBool = locMarshUseDfltSuid == null ? true : locMarshUseDfltSuid;
    Boolean locMarshStrSerVer2 = locNode.attribute(ATTR_MARSHALLER_USE_BINARY_STRING_SER_VER_2);
    boolean locMarshStrSerVer2Bool = locMarshStrSerVer2 == null ? false : /* turned on and added to the attributes list by default only when BinaryMarshaller is used. */
    locMarshStrSerVer2;
    boolean locDelayAssign = locNode.attribute(ATTR_LATE_AFFINITY_ASSIGNMENT);
    Boolean locSecurityCompatibilityEnabled = locNode.attribute(ATTR_SECURITY_COMPATIBILITY_MODE);
    for (ClusterNode n : nodes) {
        int rmtJvmMajVer = nodeJavaMajorVersion(n);
        if (locJvmMajVer != rmtJvmMajVer && !jvmMajVerWarned) {
            U.warn(log, "Local java version is different from remote [loc=" + locJvmMajVer + ", rmt=" + rmtJvmMajVer + "]");
            jvmMajVerWarned = true;
        }
        String rmtPreferIpV4 = n.attribute("java.net.preferIPv4Stack");
        if (!F.eq(rmtPreferIpV4, locPreferIpV4)) {
            if (!ipV4Warned)
                U.warn(log, "Local node's value of 'java.net.preferIPv4Stack' " + "system property differs from remote node's " + "(all nodes in topology should have identical value) " + "[locPreferIpV4=" + locPreferIpV4 + ", rmtPreferIpV4=" + rmtPreferIpV4 + ", locId8=" + U.id8(locNode.id()) + ", rmtId8=" + U.id8(n.id()) + ", rmtAddrs=" + U.addressesAsString(n) + ", rmtNode=" + U.toShortString(n) + "]");
            ipV4Warned = true;
        }
        // Skip data center ID check for daemon nodes.
        if (!isLocDaemon && !n.isDaemon()) {
            Object rmtMode = n.attribute(ATTR_DEPLOYMENT_MODE);
            if (!locMode.equals(rmtMode))
                throw new IgniteCheckedException("Remote node has deployment mode different from local " + "[locId8=" + U.id8(locNode.id()) + ", locMode=" + locMode + ", rmtId8=" + U.id8(n.id()) + ", rmtMode=" + rmtMode + ", rmtAddrs=" + U.addressesAsString(n) + ", rmtNode=" + U.toShortString(n) + "]");
            boolean rmtP2pEnabled = n.attribute(ATTR_PEER_CLASSLOADING);
            if (locP2pEnabled != rmtP2pEnabled)
                throw new IgniteCheckedException("Remote node has peer class loading enabled flag different from" + " local [locId8=" + U.id8(locNode.id()) + ", locPeerClassLoading=" + locP2pEnabled + ", rmtId8=" + U.id8(n.id()) + ", rmtPeerClassLoading=" + rmtP2pEnabled + ", rmtAddrs=" + U.addressesAsString(n) + ", rmtNode=" + U.toShortString(n) + "]");
        }
        Boolean rmtMarshUseDfltSuid = n.attribute(ATTR_MARSHALLER_USE_DFLT_SUID);
        boolean rmtMarshUseDfltSuidBool = rmtMarshUseDfltSuid == null ? true : rmtMarshUseDfltSuid;
        if (locMarshUseDfltSuidBool != rmtMarshUseDfltSuidBool) {
            throw new IgniteCheckedException("Local node's " + IGNITE_OPTIMIZED_MARSHALLER_USE_DEFAULT_SUID + " property value differs from remote node's value " + "(to make sure all nodes in topology have identical marshaller settings, " + "configure system property explicitly) " + "[locMarshUseDfltSuid=" + locMarshUseDfltSuid + ", rmtMarshUseDfltSuid=" + rmtMarshUseDfltSuid + ", locNodeAddrs=" + U.addressesAsString(locNode) + ", rmtNodeAddrs=" + U.addressesAsString(n) + ", locNodeId=" + locNode.id() + ", rmtNodeId=" + n.id() + ", rmtNode=" + U.toShortString(n) + "]");
        }
        Boolean rmtMarshStrSerVer2 = n.attribute(ATTR_MARSHALLER_USE_BINARY_STRING_SER_VER_2);
        boolean rmtMarshStrSerVer2Bool = rmtMarshStrSerVer2 == null ? false : rmtMarshStrSerVer2;
        if (locMarshStrSerVer2Bool != rmtMarshStrSerVer2Bool) {
            throw new IgniteCheckedException("Local node's " + IGNITE_BINARY_MARSHALLER_USE_STRING_SERIALIZATION_VER_2 + " property value differs from remote node's value " + "(to make sure all nodes in topology have identical marshaller settings, " + "configure system property explicitly) " + "[locMarshStrSerVer2=" + locMarshStrSerVer2 + ", rmtMarshStrSerVer2=" + rmtMarshStrSerVer2 + ", locNodeAddrs=" + U.addressesAsString(locNode) + ", rmtNodeAddrs=" + U.addressesAsString(n) + ", locNodeId=" + locNode.id() + ", rmtNodeId=" + n.id() + ", rmtNode=" + U.toShortString(n) + "]");
        }
        boolean rmtLateAssign = n.attribute(ATTR_LATE_AFFINITY_ASSIGNMENT);
        if (locDelayAssign != rmtLateAssign) {
            throw new IgniteCheckedException("Remote node has cache affinity assignment mode different from local " + "[locId8=" + U.id8(locNode.id()) + ", locDelayAssign=" + locDelayAssign + ", rmtId8=" + U.id8(n.id()) + ", rmtLateAssign=" + rmtLateAssign + ", rmtAddrs=" + U.addressesAsString(n) + ", rmtNode=" + U.toShortString(n) + "]");
        }
        ShutdownPolicy rmtShutdownPolicy = n.attribute(ATTR_SHUTDOWN_POLICY) == null ? null : ShutdownPolicy.fromOrdinal(n.attribute(ATTR_SHUTDOWN_POLICY));
        if (rmtShutdownPolicy != null && !F.eq(locShutdownPolicy, rmtShutdownPolicy)) {
            throw new IgniteCheckedException("Remote node has shutdoun policy different from local" + " local [locId8=" + U.id8(locNode.id()) + ", locShutdownPolicy=" + locShutdownPolicy + ", rmtId8=" + U.id8(n.id()) + ", rmtShutdownPolicy=" + rmtShutdownPolicy + ", rmtAddrs=" + U.addressesAsString(n) + ", rmtNode=" + U.toShortString(n) + "]");
        }
        if (ctx.security().enabled()) {
            Boolean rmtSecurityCompatibilityEnabled = n.attribute(ATTR_SECURITY_COMPATIBILITY_MODE);
            if (!F.eq(locSecurityCompatibilityEnabled, rmtSecurityCompatibilityEnabled)) {
                throw new IgniteCheckedException("Local node's " + IGNITE_SECURITY_COMPATIBILITY_MODE + " property value differs from remote node's value " + "(to make sure all nodes in topology have identical Ignite security compatibility mode enabled, " + "configure system property explicitly) " + "[locSecurityCompatibilityEnabled=" + locSecurityCompatibilityEnabled + ", rmtSecurityCompatibilityEnabled=" + rmtSecurityCompatibilityEnabled + ", locNodeAddrs=" + U.addressesAsString(locNode) + ", rmtNodeAddrs=" + U.addressesAsString(n) + ", locNodeId=" + locNode.id() + ", rmtNode=" + U.toShortString(n) + "]");
            }
        }
    }
    if (log.isDebugEnabled())
        log.debug("Finished node attributes consistency check.");
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ShutdownPolicy(org.apache.ignite.ShutdownPolicy) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 3 with ShutdownPolicy

use of org.apache.ignite.ShutdownPolicy in project ignite by apache.

the class CommandHandlerParsingTest method testParseShutdownPolicyParameters.

/**
 * Tets checks a parser of shutdown policy command.
 */
@Test
public void testParseShutdownPolicyParameters() {
    ConnectionAndSslParameters args = parseArgs(asList(SHUTDOWN_POLICY.text()));
    assertEquals(SHUTDOWN_POLICY.command(), args.command());
    assertNull(((ShutdownPolicyCommand) args.command()).arg().getShutdown());
    for (ShutdownPolicy policy : ShutdownPolicy.values()) {
        args = parseArgs(asList(SHUTDOWN_POLICY.text(), String.valueOf(policy)));
        assertEquals(SHUTDOWN_POLICY.command(), args.command());
        assertSame(policy, ((ShutdownPolicyCommand) args.command()).arg().getShutdown());
    }
}
Also used : ShutdownPolicy(org.apache.ignite.ShutdownPolicy) Test(org.junit.Test)

Example 4 with ShutdownPolicy

use of org.apache.ignite.ShutdownPolicy in project ignite by apache.

the class GridCommandHandlerTest method testShutdownPolicy.

/**
 * Test is checking how to --shutdown-policy command works through control.sh.
 *
 * @throws Exception If failed.
 */
@Test
public void testShutdownPolicy() throws Exception {
    Ignite ignite = startGrids(1);
    assertFalse(ignite.cluster().active());
    ignite.cluster().active(true);
    ShutdownPolicy policy = ignite.cluster().shutdownPolicy();
    injectTestSystemOut();
    assertEquals(EXIT_CODE_OK, execute("--shutdown-policy"));
    String out = testOut.toString();
    assertContains(log, out, "Cluster shutdown policy is " + policy);
}
Also used : ShutdownPolicy(org.apache.ignite.ShutdownPolicy) Ignite(org.apache.ignite.Ignite) IgniteCacheGroupsWithRestartsTest(org.apache.ignite.internal.processors.cache.persistence.db.IgniteCacheGroupsWithRestartsTest) AbstractSnapshotSelfTest.doSnapshotCancellationTest(org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.doSnapshotCancellationTest) Test(org.junit.Test)

Example 5 with ShutdownPolicy

use of org.apache.ignite.ShutdownPolicy in project ignite by apache.

the class GracefulShutdownTest method testRestartWithDynamicConfiguredPolicy.

/**
 * Check dynamic configuration of shutdown policy.
 *
 * @throws Exception If failed.
 */
@Test
public void testRestartWithDynamicConfiguredPolicy() throws Exception {
    Ignite ignite0 = startGrid(0);
    ignite0.cluster().active(true);
    assertSame(ignite0.cluster().shutdownPolicy(), ignite0.configuration().getShutdownPolicy());
    ShutdownPolicy configuredPolicy = ignite0.cluster().shutdownPolicy();
    ShutdownPolicy policyToChange = null;
    for (ShutdownPolicy policy : ShutdownPolicy.values()) {
        if (policy != ignite0.cluster().shutdownPolicy())
            policyToChange = policy;
    }
    assertNotNull(policyToChange);
    ignite0.cluster().shutdownPolicy(policyToChange);
    forceCheckpoint();
    info("Policy to change: " + policyToChange);
    ignite0.close();
    ignite0 = startGrid(0);
    info("Policy after restart: " + ignite0.cluster().shutdownPolicy());
    assertNotSame(ignite0.cluster().shutdownPolicy(), ignite0.configuration().getShutdownPolicy());
    assertSame(ignite0.cluster().shutdownPolicy(), policyToChange);
}
Also used : ShutdownPolicy(org.apache.ignite.ShutdownPolicy) Ignite(org.apache.ignite.Ignite) Test(org.junit.Test)

Aggregations

ShutdownPolicy (org.apache.ignite.ShutdownPolicy)5 Test (org.junit.Test)4 Ignite (org.apache.ignite.Ignite)3 IgniteCacheGroupsWithRestartsTest (org.apache.ignite.internal.processors.cache.persistence.db.IgniteCacheGroupsWithRestartsTest)2 AbstractSnapshotSelfTest.doSnapshotCancellationTest (org.apache.ignite.internal.processors.cache.persistence.snapshot.AbstractSnapshotSelfTest.doSnapshotCancellationTest)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1