Search in sources :

Example 36 with Gfsh

use of org.apache.geode.management.internal.cli.shell.Gfsh in project geode by apache.

the class GatewaySenderIdConverter method getGatewaySenderIds.

public Set<String> getGatewaySenderIds() {
    Set<String> gatewaySenderIds = Collections.emptySet();
    Gfsh gfsh = Gfsh.getCurrentInstance();
    if (gfsh != null && gfsh.isConnectedAndReady()) {
        final String[] gatewaySenderIdArray = (String[]) gfsh.getOperationInvoker().invoke(ManagementConstants.OBJECTNAME__DISTRIBUTEDSYSTEM_MXBEAN, "listGatewaySenders", new Object[0], new String[0]);
        if (gatewaySenderIdArray != null && gatewaySenderIdArray.length != 0) {
            gatewaySenderIds = new TreeSet<String>(Arrays.asList(gatewaySenderIdArray));
        }
    }
    return gatewaySenderIds;
}
Also used : Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh)

Example 37 with Gfsh

use of org.apache.geode.management.internal.cli.shell.Gfsh in project geode by apache.

the class MemberIdNameConverter method getMemberIdAndNames.

private Set<String> getMemberIdAndNames() {
    final Set<String> nonLocatorMembers = new TreeSet<String>();
    final Gfsh gfsh = Gfsh.getCurrentInstance();
    if (gfsh != null && gfsh.isConnectedAndReady()) {
        nonLocatorMembers.addAll(Arrays.asList(gfsh.getOperationInvoker().getDistributedSystemMXBean().listMembers()));
        final String[] locatorMembers = gfsh.getOperationInvoker().getDistributedSystemMXBean().listLocatorMembers(true);
        if (locatorMembers != null && locatorMembers.length != 0) {
            nonLocatorMembers.removeAll(Arrays.asList(locatorMembers));
        }
    }
    return nonLocatorMembers;
}
Also used : Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) TreeSet(java.util.TreeSet)

Example 38 with Gfsh

use of org.apache.geode.management.internal.cli.shell.Gfsh in project geode by apache.

the class RegionPathConverter method getAllPossibleValues.

@Override
public boolean getAllPossibleValues(List<Completion> completions, Class<?> targetType, String existingData, String optionContext, MethodTarget target) {
    Set<String> regionPathSet = getAllRegionPaths();
    Gfsh gfsh = Gfsh.getCurrentInstance();
    String currentContextPath = "";
    if (gfsh != null) {
        currentContextPath = gfsh.getEnvProperty(Gfsh.ENV_APP_CONTEXT_PATH);
        if (currentContextPath != null && !org.apache.geode.management.internal.cli.converters.RegionPathConverter.DEFAULT_APP_CONTEXT_PATH.equals(currentContextPath)) {
            regionPathSet.remove(currentContextPath);
            regionPathSet.add(org.apache.geode.management.internal.cli.converters.RegionPathConverter.DEFAULT_APP_CONTEXT_PATH);
        }
    }
    for (String regionPath : regionPathSet) {
        if (existingData != null) {
            if (regionPath.startsWith(existingData)) {
                completions.add(new Completion(regionPath));
            }
        } else {
            completions.add(new Completion(regionPath));
        }
    }
    return !completions.isEmpty();
}
Also used : Completion(org.springframework.shell.core.Completion) Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh)

Example 39 with Gfsh

use of org.apache.geode.management.internal.cli.shell.Gfsh in project geode by apache.

the class LocatorIdNameConverter method getLocatorIdAndNames.

private Set<String> getLocatorIdAndNames() {
    final Set<String> locatorIdsAndNames = new TreeSet<String>();
    final Gfsh gfsh = Gfsh.getCurrentInstance();
    if (gfsh != null && gfsh.isConnectedAndReady()) {
        final String[] locatorIds = gfsh.getOperationInvoker().getDistributedSystemMXBean().listLocatorMembers(true);
        if (locatorIds != null && locatorIds.length != 0) {
            locatorIdsAndNames.addAll(Arrays.asList(locatorIds));
        }
    }
    return locatorIdsAndNames;
}
Also used : Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) TreeSet(java.util.TreeSet)

Example 40 with Gfsh

use of org.apache.geode.management.internal.cli.shell.Gfsh in project geode by apache.

the class DiskStoreCommandsDUnitTest method testAlterDiskStore.

/**
   * 1) Create a disk-store in a member, get the disk-dirs. 2) Close the member. 3) Execute the
   * command. 4) Restart the member. 5) Check if the disk-store is altered.
   *
   * @throws IOException
   * @throws ClassNotFoundException
   */
@Test
public void testAlterDiskStore() throws ClassNotFoundException, IOException {
    final String regionName = "region1";
    final String diskStoreName = "disk-store1";
    final String diskDirName = "diskStoreDir";
    final File diskStoreDir = new File(diskDirName);
    diskStoreDir.deleteOnExit();
    if (!diskStoreDir.exists()) {
        diskStoreDir.mkdir();
    }
    final String diskDirPath = diskStoreDir.getCanonicalPath();
    final VM vm1 = Host.getHost(0).getVM(1);
    vm1.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            getSystem();
            Region region = createParRegWithPersistence(regionName, diskStoreName, diskDirPath);
            region.put("a", "QWE");
            return region.put("b", "ASD");
        }
    });
    // Close the cache and all the connections , so the disk-store can be altered
    disconnectAllFromDS();
    // Now do the command execution
    setUpJmxManagerOnVm0ThenConnect(null);
    Gfsh gfshInstance = Gfsh.getCurrentInstance();
    if (gfshInstance == null) {
        fail("In testAlterDiskStore command gfshInstance is null");
    }
    gfshInstance.setDebug(true);
    CommandStringBuilder csb = new CommandStringBuilder(CliStrings.ALTER_DISK_STORE);
    csb.addOption(CliStrings.ALTER_DISK_STORE__DISKSTORENAME, diskStoreName);
    csb.addOption(CliStrings.ALTER_DISK_STORE__REGIONNAME, regionName);
    csb.addOption(CliStrings.ALTER_DISK_STORE__DISKDIRS, diskDirPath);
    csb.addOption(CliStrings.ALTER_DISK_STORE__CONCURRENCY__LEVEL, "5");
    csb.addOption(CliStrings.ALTER_DISK_STORE__INITIAL__CAPACITY, "6");
    csb.addOption(CliStrings.ALTER_DISK_STORE__LRU__EVICTION__ACTION, "local-destroy");
    csb.addOption(CliStrings.ALTER_DISK_STORE__COMPRESSOR, "org.apache.geode.compression.SnappyCompressor");
    csb.addOption(CliStrings.ALTER_DISK_STORE__STATISTICS__ENABLED, "true");
    String commandString = csb.getCommandString();
    commandString.trim();
    CommandResult cmdResult = executeCommand(commandString);
    String resultString = commandResultToString(cmdResult);
    getLogWriter().info("#SB command output : \n" + resultString);
    assertEquals(true, Result.Status.OK.equals(cmdResult.getStatus()));
    assertEquals(true, resultString.contains("concurrencyLevel=5"));
    assertEquals(true, resultString.contains("lruAction=local-destroy"));
    assertEquals(true, resultString.contains("compressor=org.apache.geode.compression.SnappyCompressor"));
    assertEquals(true, resultString.contains("initialCapacity=6"));
    csb = new CommandStringBuilder(CliStrings.ALTER_DISK_STORE);
    csb.addOption(CliStrings.ALTER_DISK_STORE__DISKSTORENAME, diskStoreName);
    csb.addOption(CliStrings.ALTER_DISK_STORE__REGIONNAME, regionName);
    csb.addOption(CliStrings.ALTER_DISK_STORE__DISKDIRS, diskDirPath);
    csb.addOption(CliStrings.ALTER_DISK_STORE__COMPRESSOR, "none");
    cmdResult = executeCommand(csb.getCommandString().trim());
    resultString = commandResultToString(cmdResult);
    assertEquals(true, Result.Status.OK.equals(cmdResult.getStatus()));
    assertTrue(stringContainsLine(resultString, "-compressor=none"));
    // Alter DiskStore with remove option
    csb = new CommandStringBuilder(CliStrings.ALTER_DISK_STORE);
    csb.addOption(CliStrings.ALTER_DISK_STORE__DISKSTORENAME, diskStoreName);
    csb.addOption(CliStrings.ALTER_DISK_STORE__REGIONNAME, regionName);
    csb.addOption(CliStrings.ALTER_DISK_STORE__DISKDIRS, diskDirPath);
    csb.addOption(CliStrings.ALTER_DISK_STORE__REMOVE, "true");
    commandString = csb.getCommandString();
    commandString.trim();
    cmdResult = executeCommand(commandString);
    resultString = commandResultToString(cmdResult);
    getLogWriter().info("command output : \n" + resultString);
    assertEquals(true, Result.Status.OK.equals(cmdResult.getStatus()));
    Object postDestroyValue = vm1.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            getSystem();
            Region region = createParRegWithPersistence(regionName, diskStoreName, diskDirPath);
            return region.get("a");
        }
    });
    assertNull(postDestroyValue);
    csb = new CommandStringBuilder(CliStrings.ALTER_DISK_STORE);
    csb.addOption(CliStrings.ALTER_DISK_STORE__DISKSTORENAME, diskStoreName);
    csb.addOption(CliStrings.ALTER_DISK_STORE__REGIONNAME, regionName);
    csb.addOption(CliStrings.ALTER_DISK_STORE__DISKDIRS, diskDirPath);
    csb.addOption(CliStrings.ALTER_DISK_STORE__CONCURRENCY__LEVEL, "5");
    csb.addOption(CliStrings.ALTER_DISK_STORE__REMOVE, "true");
    commandString = csb.getCommandString();
    commandString.trim();
    cmdResult = executeCommand(commandString);
    resultString = commandResultToString(cmdResult);
    getLogWriter().info("Alter DiskStore with wrong remove option  : \n" + resultString);
    assertEquals(true, Result.Status.ERROR.equals(cmdResult.getStatus()));
    filesToBeDeleted.add(diskDirName);
}
Also used : Gfsh(org.apache.geode.management.internal.cli.shell.Gfsh) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) File(java.io.File) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Aggregations

Gfsh (org.apache.geode.management.internal.cli.shell.Gfsh)40 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)14 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)13 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)13 Test (org.junit.Test)13 IOException (java.io.IOException)11 CliMetaData (org.apache.geode.management.cli.CliMetaData)7 CliCommand (org.springframework.shell.core.annotation.CliCommand)7 TreeSet (java.util.TreeSet)6 ConnectToLocatorResult (org.apache.geode.management.internal.cli.domain.ConnectToLocatorResult)6 File (java.io.File)5 MalformedURLException (java.net.MalformedURLException)5 Result (org.apache.geode.management.cli.Result)5 AuthenticationFailedException (org.apache.geode.security.AuthenticationFailedException)5 ConverterHint (org.apache.geode.management.cli.ConverterHint)3 JmxOperationInvoker (org.apache.geode.management.internal.cli.shell.JmxOperationInvoker)3 ConnectionEndpoint (org.apache.geode.management.internal.cli.util.ConnectionEndpoint)3 HttpOperationInvoker (org.apache.geode.management.internal.web.shell.HttpOperationInvoker)3 RestHttpOperationInvoker (org.apache.geode.management.internal.web.shell.RestHttpOperationInvoker)3 ExitShellRequest (org.springframework.shell.core.ExitShellRequest)3