use of org.elasticsearch.env.NodeEnvironment in project elasticsearch by elastic.
the class IndicesServiceTests method testVerifyIfIndexContentDeleted.
public void testVerifyIfIndexContentDeleted() throws Exception {
final Index index = new Index("test", UUIDs.randomBase64UUID());
final IndicesService indicesService = getIndicesService();
final NodeEnvironment nodeEnv = getNodeEnvironment();
final MetaStateService metaStateService = getInstanceFromNode(MetaStateService.class);
final ClusterService clusterService = getInstanceFromNode(ClusterService.class);
final Settings idxSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetaData.SETTING_INDEX_UUID, index.getUUID()).build();
final IndexMetaData indexMetaData = new IndexMetaData.Builder(index.getName()).settings(idxSettings).numberOfShards(1).numberOfReplicas(0).build();
metaStateService.writeIndex("test index being created", indexMetaData);
final MetaData metaData = MetaData.builder(clusterService.state().metaData()).put(indexMetaData, true).build();
final ClusterState csWithIndex = new ClusterState.Builder(clusterService.state()).metaData(metaData).build();
try {
indicesService.verifyIndexIsDeleted(index, csWithIndex);
fail("Should not be able to delete index contents when the index is part of the cluster state.");
} catch (IllegalStateException e) {
assertThat(e.getMessage(), containsString("Cannot delete index"));
}
final ClusterState withoutIndex = new ClusterState.Builder(csWithIndex).metaData(MetaData.builder(csWithIndex.metaData()).remove(index.getName())).build();
indicesService.verifyIndexIsDeleted(index, withoutIndex);
assertFalse("index files should be deleted", FileSystemUtils.exists(nodeEnv.indexPaths(index)));
}
use of org.elasticsearch.env.NodeEnvironment in project crate by crate.
the class SysNodesExpressionsOnHandlerTest method setup.
@BeforeClass
public static void setup() throws IOException {
// jvm
JvmStats jvmStats = mock(JvmStats.class);
JvmStats.Mem jvmStatsMem = mock(JvmStats.Mem.class);
ByteSizeValue heapByteSizeValueMax = new ByteSizeValue(123456L);
when(jvmStatsMem.getHeapMax()).thenReturn(heapByteSizeValueMax);
when(jvmStatsMem.getHeapUsed()).thenReturn(heapByteSizeValueMax);
when(jvmStats.getMem()).thenReturn(jvmStatsMem);
// mem
ByteSizeValue byteSizeValue = new ByteSizeValue(12345342234L);
// os service
OsService osService = mock(OsService.class);
OsStats osStats = mock(OsStats.class);
when(osService.stats()).thenReturn(osStats);
OsStats.Mem mem = mock(OsStats.Mem.class);
when(osStats.getMem()).thenReturn(mem);
when(mem.getFree()).thenReturn(byteSizeValue);
when(mem.getUsed()).thenReturn(byteSizeValue);
when(mem.getUsedPercent()).thenReturn((short) 22);
when(mem.getFreePercent()).thenReturn((short) 78);
// os info
OsInfo osInfo = mock(OsInfo.class);
when(osService.info()).thenReturn(osInfo);
when(osInfo.getAvailableProcessors()).thenReturn(4);
// node info
NodeEnvironment nodeEnv = mock(NodeEnvironment.class);
Path[] dataLocations = new Path[] { new File("/foo").toPath(), new File("/bar").toPath() };
when(nodeEnv.hasNodeFile()).then(invocation -> true);
when(nodeEnv.nodeDataPaths()).thenReturn(dataLocations);
ExtendedNodeInfo extendedNodeInfo = new DummyExtendedNodeInfo(nodeEnv);
// process stats
ProcessStats processStats = mock(ProcessStats.class);
when(processStats.getOpenFileDescriptors()).thenReturn(42L);
when(processStats.getMaxFileDescriptors()).thenReturn(1000L);
CONTEXT.id(BytesRefs.toBytesRef("93c7ff92-52fa-11e6-aad8-3c15c2d3ad18"));
CONTEXT.name(BytesRefs.toBytesRef("crate1"));
CONTEXT.hostname(BytesRefs.toBytesRef("crate1.example.com"));
CONTEXT.version(Version.CURRENT);
CONTEXT.build(Build.CURRENT);
CONTEXT.timestamp(100L);
CONTEXT.restUrl(BytesRefs.toBytesRef("10.0.0.1:4200"));
CONTEXT.port(new HashMap<String, Integer>(2) {
{
put("http", 4200);
put("transport", 4300);
}
});
CONTEXT.jvmStats(jvmStats);
CONTEXT.osInfo(osInfo);
CONTEXT.processStats(processStats);
CONTEXT.osStats(osStats);
CONTEXT.extendedOsStats(extendedNodeInfo.osStats());
CONTEXT.networkStats(extendedNodeInfo.networkStats());
CONTEXT.extendedProcessCpuStats(extendedNodeInfo.processCpuStats());
CONTEXT.extendedFsStats(extendedNodeInfo.fsStats());
}
use of org.elasticsearch.env.NodeEnvironment in project elasticsearch by elastic.
the class ShardPath method selectNewPathForShard.
public static ShardPath selectNewPathForShard(NodeEnvironment env, ShardId shardId, IndexSettings indexSettings, long avgShardSizeInBytes, Map<Path, Integer> dataPathToShardCount) throws IOException {
final Path dataPath;
final Path statePath;
if (indexSettings.hasCustomDataPath()) {
dataPath = env.resolveCustomLocation(indexSettings, shardId);
statePath = env.nodePaths()[0].resolve(shardId);
} else {
BigInteger totFreeSpace = BigInteger.ZERO;
for (NodeEnvironment.NodePath nodePath : env.nodePaths()) {
totFreeSpace = totFreeSpace.add(BigInteger.valueOf(nodePath.fileStore.getUsableSpace()));
}
// TODO: this is a hack!! We should instead keep track of incoming (relocated) shards since we know
// how large they will be once they're done copying, instead of a silly guess for such cases:
// Very rough heuristic of how much disk space we expect the shard will use over its lifetime, the max of current average
// shard size across the cluster and 5% of the total available free space on this node:
BigInteger estShardSizeInBytes = BigInteger.valueOf(avgShardSizeInBytes).max(totFreeSpace.divide(BigInteger.valueOf(20)));
// TODO - do we need something more extensible? Yet, this does the job for now...
final NodeEnvironment.NodePath[] paths = env.nodePaths();
NodeEnvironment.NodePath bestPath = null;
BigInteger maxUsableBytes = BigInteger.valueOf(Long.MIN_VALUE);
for (NodeEnvironment.NodePath nodePath : paths) {
FileStore fileStore = nodePath.fileStore;
BigInteger usableBytes = BigInteger.valueOf(fileStore.getUsableSpace());
assert usableBytes.compareTo(BigInteger.ZERO) >= 0;
// Deduct estimated reserved bytes from usable space:
Integer count = dataPathToShardCount.get(nodePath.path);
if (count != null) {
usableBytes = usableBytes.subtract(estShardSizeInBytes.multiply(BigInteger.valueOf(count)));
}
if (bestPath == null || usableBytes.compareTo(maxUsableBytes) > 0) {
maxUsableBytes = usableBytes;
bestPath = nodePath;
}
}
statePath = bestPath.resolve(shardId);
dataPath = statePath;
}
return new ShardPath(indexSettings.hasCustomDataPath(), dataPath, statePath, shardId);
}
use of org.elasticsearch.env.NodeEnvironment in project elasticsearch by elastic.
the class MetaStateServiceTests method testLoadGlobal.
public void testLoadGlobal() throws Exception {
try (NodeEnvironment env = newNodeEnvironment()) {
MetaStateService metaStateService = new MetaStateService(Settings.EMPTY, env, xContentRegistry());
IndexMetaData index = IndexMetaData.builder("test1").settings(indexSettings).build();
MetaData metaData = MetaData.builder().persistentSettings(Settings.builder().put("test1", "value1").build()).put(index, true).build();
metaStateService.writeGlobalState("test_write", metaData);
metaStateService.writeIndex("test_write", index);
MetaData loadedState = metaStateService.loadFullState();
assertThat(loadedState.persistentSettings(), equalTo(metaData.persistentSettings()));
assertThat(loadedState.hasIndex("test1"), equalTo(true));
assertThat(loadedState.index("test1"), equalTo(index));
}
}
use of org.elasticsearch.env.NodeEnvironment in project elasticsearch by elastic.
the class MetaStateServiceTests method testWriteLoadGlobal.
public void testWriteLoadGlobal() throws Exception {
try (NodeEnvironment env = newNodeEnvironment()) {
MetaStateService metaStateService = new MetaStateService(Settings.EMPTY, env, xContentRegistry());
MetaData metaData = MetaData.builder().persistentSettings(Settings.builder().put("test1", "value1").build()).build();
metaStateService.writeGlobalState("test_write", metaData);
assertThat(metaStateService.loadGlobalState().persistentSettings(), equalTo(metaData.persistentSettings()));
}
}
Aggregations