Java Code Examples for org.apache.ignite.configuration.IgniteConfiguration#setWorkDirectory()

The following examples show how to use org.apache.ignite.configuration.IgniteConfiguration#setWorkDirectory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IgniteConfigVariationsAbstractTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    IgniteConfiguration resCfg = testsCfg.configurationFactory().getConfiguration(igniteInstanceName, cfg);

    resCfg.setWorkDirectory(workDir.getAbsolutePath());

    if (testsCfg.withClients())
        resCfg.setClientMode(expectedClient(igniteInstanceName));

    resCfg.setDataStorageConfiguration(
        new DataStorageConfiguration()
            .setDefaultDataRegionConfiguration(
                new DataRegionConfiguration()
                    .setMaxSize(200L * 1024 * 1024)
            ));

    return resCfg;
}
 
Example 2
Source File: IgniteMock.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override public IgniteConfiguration configuration() {
    if (staticCfg != null)
        return staticCfg;

    IgniteConfiguration cfg = new IgniteConfiguration();

    cfg.setMarshaller(marshaller);
    cfg.setNodeId(nodeId);
    cfg.setMBeanServer(jmx);
    cfg.setIgniteHome(home);
    cfg.setLocalHost(locHost);

    try {
        cfg.setWorkDirectory(U.defaultWorkDirectory());
    }
    catch (IgniteCheckedException e) {
        throw new IgniteException("Failed to get default work directory.", e);
    }

    return cfg;
}
 
Example 3
Source File: IgniteNodeRunner.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * Stores {@link IgniteConfiguration} to file as xml.
 *
 * @param cfg Ignite Configuration.
 * @param fileName A name of file where the configuration was stored.
 * @param resetMarshaller Reset marshaller configuration to default.
 * @param resetDiscovery Reset discovery configuration to default.
 * @throws IOException If failed.
 * @see #readCfgFromFileAndDeleteFile(String)
 */
public static void storeToFile(IgniteConfiguration cfg, String fileName,
    boolean resetMarshaller,
    boolean resetDiscovery) throws IOException, IgniteCheckedException {
    try (OutputStream out = new BufferedOutputStream(new FileOutputStream(fileName))) {
        IgniteConfiguration cfg0 = new IgniteConfiguration(cfg);

        if (resetMarshaller)
            cfg0.setMarshaller(null);

        if (resetDiscovery)
            cfg0.setDiscoverySpi(null);

        cfg0.setWorkDirectory(U.defaultWorkDirectory());
        cfg0.setMBeanServer(null);
        cfg0.setGridLogger(null);

        new XStream().toXML(cfg0, out);
    }
}
 
Example 4
Source File: OptimizedMarshallerNodeFailoverTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);

    cfg.setMarshaller(new OptimizedMarshaller());

    cfg.setWorkDirectory(workDir);

    if (cache) {
        CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

        ccfg.setCacheMode(PARTITIONED);
        ccfg.setBackups(1);
        ccfg.setWriteSynchronizationMode(FULL_SYNC);

        cfg.setCacheConfiguration(ccfg);
    }
    else
        cfg.setClientMode(true);

    return cfg;
}
 
Example 5
Source File: PersistenceDirectoryWarningLoggingTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @throws Exception If failed.
 */
@Test
public void testPdsDirWarningIsLogged() throws Exception {
    IgniteConfiguration cfg = getConfiguration("0");

    String tempDir = System.getProperty("java.io.tmpdir");

    assertNotNull(tempDir);

    // Emulates that Ignite work directory has not been calculated,
    // and IgniteUtils#workDirectory resolved directory into "java.io.tmpdir"
    cfg.setWorkDirectory(tempDir);

    startGrid(cfg);

    assertTrue(log0.toString().contains(WARN_MSG_PREFIX));
}
 
Example 6
Source File: IgnitePdsMarshallerMappingRestoreOnNodeStartTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    int gridIndex = getTestIgniteInstanceIndex(gridName);

    IgniteConfiguration cfg = super.getConfiguration(gridName);

    String tmpDir = System.getProperty("java.io.tmpdir");

    cfg.setWorkDirectory(Paths.get(tmpDir, "srv" + gridIndex).toString());

    cfg.setDataStorageConfiguration(
        new DataStorageConfiguration()
    );

    cfg.setCacheConfiguration(new CacheConfiguration()
        .setName(DEFAULT_CACHE_NAME)
        .setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC)
        .setCacheMode(CacheMode.REPLICATED));

    return cfg;
}
 
Example 7
Source File: AbstractSnapshotSelfTest.java    From ignite with Apache License 2.0 6 votes vote down vote up
/**
 * @param cnt Number of grids to start.
 * @param path Snapshot path resolver.
 * @param snpName Snapshot to start grids from.
 * @return Coordinator ignite instance.
 * @throws Exception If fails.
 */
protected IgniteEx startGridsFromSnapshot(int cnt,
    Function<IgniteConfiguration, String> path,
    String snpName,
    boolean activate
) throws Exception {
    IgniteEx crd = null;

    for (int i = 0; i < cnt; i++) {
        IgniteConfiguration cfg = optimize(getConfiguration(getTestIgniteInstanceName(i)));

        cfg.setWorkDirectory(Paths.get(path.apply(cfg), snpName).toString());

        if (crd == null)
            crd = startGrid(cfg);
        else
            startGrid(cfg);
    }

    crd.cluster().baselineAutoAdjustEnabled(false);

    if (activate)
        crd.cluster().state(ACTIVE);

    return crd;
}
 
Example 8
Source File: GridCommandHandlerTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/** @throws Exception If failed. */
@Test
public void testClusterSnapshotCreate() throws Exception {
    int keysCnt = 100;
    String snpName = "snapshot_02052020";

    IgniteEx ig = startGrid(0);
    ig.cluster().state(ACTIVE);

    createCacheAndPreload(ig, keysCnt);

    CommandHandler h = new CommandHandler();

    assertEquals(EXIT_CODE_OK, execute(h, "--snapshot", "create", snpName));

    assertTrue("Waiting for snapshot operation end failed.",
        waitForCondition(() ->
                ig.context().metric().registry(SNAPSHOT_METRICS)
                    .<LongMetric>findMetric("LastSnapshotEndTime").value() > 0,
            getTestTimeout()));

    assertContains(log, (String)h.getLastOperationResult(), snpName);

    stopAllGrids();

    IgniteConfiguration cfg = optimize(getConfiguration(getTestIgniteInstanceName(0)));
    cfg.setWorkDirectory(Paths.get(resolveSnapshotWorkDirectory(cfg).getAbsolutePath(), snpName).toString());

    Ignite snpIg = startGrid(cfg);
    snpIg.cluster().state(ACTIVE);

    List<Integer> range = IntStream.range(0, keysCnt).boxed().collect(Collectors.toList());

    snpIg.cache(DEFAULT_CACHE_NAME).forEach(e -> range.remove((Integer)e.getKey()));
    assertTrue("Snapshot must contains cache data [left=" + range + ']', range.isEmpty());
}
 
Example 9
Source File: GridMarshallerMappingConsistencyTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration igniteCfg = super.getConfiguration(igniteInstanceName);

    igniteCfg.setConsistentId(igniteInstanceName);

    DataRegionConfiguration drCfg = new DataRegionConfiguration();
    drCfg.setPersistenceEnabled(true).setMaxSize(DataStorageConfiguration.DFLT_DATA_REGION_INITIAL_SIZE);

    DataStorageConfiguration dsCfg = new DataStorageConfiguration();
    dsCfg.setDefaultDataRegionConfiguration(drCfg);

    igniteCfg.setDataStorageConfiguration(dsCfg);

    igniteCfg.setWorkDirectory(WORK_DIR + File.separator + igniteInstanceName);

    return igniteCfg;
}
 
Example 10
Source File: IgnitePdsBinaryMetadataOnClusterRestartTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);

    cfg.setConsistentId(gridName);

    if (customWorkSubDir != null)
        cfg.setWorkDirectory(Paths.get(U.defaultWorkDirectory(), customWorkSubDir).toString());

    cfg.setDataStorageConfiguration(
        new DataStorageConfiguration()
            .setWalMode(WALMode.LOG_ONLY)
            .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
                .setPersistenceEnabled(true)
                .setMaxSize(100L * 1024 * 1024))
    );

    BinaryConfiguration bCfg = new BinaryConfiguration();

    BinaryTypeConfiguration binaryEnumCfg = new BinaryTypeConfiguration(EnumType.class.getName());

    binaryEnumCfg.setEnum(true);
    binaryEnumCfg.setEnumValues(F.asMap(EnumType.ENUM_VAL_0.name(),
        EnumType.ENUM_VAL_0.ordinal(),
        EnumType.ENUM_VAL_1.name(),
        EnumType.ENUM_VAL_1.ordinal()));

    bCfg.setTypeConfigurations(Arrays.asList(binaryEnumCfg));

    cfg.setBinaryConfiguration(bCfg);

    CacheKeyConfiguration dynamicMetaKeyCfg = new CacheKeyConfiguration(DYNAMIC_TYPE_NAME, DYNAMIC_INT_FIELD_NAME);

    cfg.setCacheKeyConfiguration(dynamicMetaKeyCfg);

    cfg.setCacheConfiguration(new CacheConfiguration()
        .setName(CACHE_NAME)
        .setAffinity(new RendezvousAffinityFunction())
        .setCacheMode(CacheMode.REPLICATED));

    return cfg;
}
 
Example 11
Source File: PersistenceDirectoryWarningLoggingTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/**
 * Test that temporary work directory warning is not printed, if PDS is not actually in temporary directory
 * @throws Exception If failed.
 */
@Test
public void testPdsDirWarningIsNotLogged() throws Exception {
    IgniteConfiguration cfg = getConfiguration("0");

    String tempDir = System.getProperty("java.io.tmpdir");

    assertNotNull(tempDir);

    File workDir = new File(U.defaultWorkDirectory(), tempDir);

    // set working directory to file not in tmp directory, but with temp directory folder name in path
    cfg.setWorkDirectory(workDir.getAbsolutePath());

    startGrid(cfg);

    assertFalse(log0.toString().contains(WARN_MSG_PREFIX));
}
 
Example 12
Source File: IgniteMarshallerCacheClientRequestsMappingOnMissTest.java    From ignite with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(gridName);

    if (cfg.isClientMode())
        cfg.setWorkDirectory(TMP_DIR);

    TcpDiscoverySpi disco = new TestTcpDiscoverySpi();
    disco.setIpFinder(ipFinder);

    cfg.setDiscoverySpi(disco);

    CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);

    ccfg.setCacheMode(REPLICATED);
    ccfg.setRebalanceMode(SYNC);
    ccfg.setWriteSynchronizationMode(FULL_SYNC);

    cfg.setCacheConfiguration(ccfg);

    return cfg;
}
 
Example 13
Source File: AgentClusterDemo.java    From ignite with Apache License 2.0 2 votes vote down vote up
/**
 * Configure node.
 *
 * @param basePort Base port.
 * @param gridIdx Ignite instance name index.
 * @param client If {@code true} then start client node.
 * @return IgniteConfiguration
 */
private static IgniteConfiguration igniteConfiguration(int basePort, int gridIdx, boolean client)
    throws IgniteCheckedException {
    IgniteConfiguration cfg = new IgniteConfiguration();

    cfg.setGridLogger(new Slf4jLogger());

    cfg.setIgniteInstanceName((client ? CLN_NODE_NAME : SRV_NODE_NAME) + gridIdx);
    cfg.setLocalHost("127.0.0.1");
    cfg.setEventStorageSpi(new MemoryEventStorageSpi());
    cfg.setConsistentId(cfg.getIgniteInstanceName());

    File workDir = new File(U.workDirectory(null, null), "demo-work");

    cfg.setWorkDirectory(workDir.getAbsolutePath());

    int[] evts = new int[EVTS_DISCOVERY.length + VISOR_TASK_EVTS.length];

    System.arraycopy(EVTS_DISCOVERY, 0, evts, 0, EVTS_DISCOVERY.length);
    System.arraycopy(VISOR_TASK_EVTS, 0, evts, EVTS_DISCOVERY.length, VISOR_TASK_EVTS.length);

    cfg.setIncludeEventTypes(evts);

    cfg.getConnectorConfiguration().setPort(basePort);

    System.setProperty(IGNITE_JETTY_PORT, String.valueOf(basePort + 10));

    TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();

    int discoPort = basePort + 20;

    ipFinder.setAddresses(Collections.singletonList("127.0.0.1:" + discoPort + ".." + (discoPort + NODE_CNT - 1)));

    // Configure discovery SPI.
    TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();

    discoSpi.setLocalPort(discoPort);
    discoSpi.setIpFinder(ipFinder);

    cfg.setDiscoverySpi(discoSpi);

    TcpCommunicationSpi commSpi = new TcpCommunicationSpi();

    commSpi.setSharedMemoryPort(-1);
    commSpi.setMessageQueueLimit(10);

    int commPort = basePort + 30;

    commSpi.setLocalPort(commPort);

    cfg.setCommunicationSpi(commSpi);
    cfg.setGridLogger(new Slf4jLogger(log));
    cfg.setMetricsLogFrequency(0);

    DataRegionConfiguration dataRegCfg = new DataRegionConfiguration();
    dataRegCfg.setName("demo");
    dataRegCfg.setMetricsEnabled(true);
    dataRegCfg.setMaxSize(DFLT_DATA_REGION_INITIAL_SIZE);
    dataRegCfg.setPersistenceEnabled(true);

    DataStorageConfiguration dataStorageCfg = new DataStorageConfiguration();
    dataStorageCfg.setMetricsEnabled(true);
    dataStorageCfg.setStoragePath(PdsConsistentIdProcessor.DB_DEFAULT_FOLDER);
    dataStorageCfg.setDefaultDataRegionConfiguration(dataRegCfg);
    dataStorageCfg.setSystemRegionMaxSize(DFLT_DATA_REGION_INITIAL_SIZE);

    dataStorageCfg.setWalMode(LOG_ONLY);
    dataStorageCfg.setWalSegments(WAL_SEGMENTS);
    dataStorageCfg.setWalSegmentSize(WAL_SEGMENT_SZ);

    cfg.setDataStorageConfiguration(dataStorageCfg);

    cfg.setClientMode(client);

    return cfg;
}