Search in sources :

Example 21 with Cluster

use of com.hazelcast.cluster.Cluster in project hazelcast by hazelcast.

the class HazelcastCommandLine method listJobs.

@Command(name = "list-jobs", description = "Lists running jobs on the cluster")
public void listJobs(@Mixin(name = "verbosity") Verbosity verbosity, @Mixin(name = "targets") TargetsMixin targets, @Option(names = { "-a", "--all" }, description = "Lists all jobs including completed and failed ones") boolean listAll) {
    runWithHazelcast(targets, verbosity, false, hz -> {
        JetClientInstanceImpl jetClientInstanceImpl = (JetClientInstanceImpl) hz.getJet();
        List<JobSummary> summaries = jetClientInstanceImpl.getJobSummaryList();
        String format = "%-19s %-18s %-23s %s";
        printf(format, "ID", "STATUS", "SUBMISSION TIME", "NAME");
        summaries.stream().filter(job -> listAll || isActive(job.getStatus())).forEach(job -> {
            String idString = idToString(job.getJobId());
            String name = job.getName().equals(idString) ? "N/A" : job.getName();
            printf(format, idString, job.getStatus(), toLocalDateTime(job.getSubmissionTime()), name);
        });
    });
}
Also used : JobSummary(com.hazelcast.jet.impl.JobSummary) Arrays(java.util.Arrays) BuildInfoProvider.getBuildInfo(com.hazelcast.instance.BuildInfoProvider.getBuildInfo) Parameters(picocli.CommandLine.Parameters) Member(com.hazelcast.cluster.Member) LogManager(java.util.logging.LogManager) ITypeConverter(picocli.CommandLine.ITypeConverter) JetClientInstanceImpl(com.hazelcast.jet.impl.JetClientInstanceImpl) HazelcastVersionProvider(com.hazelcast.client.console.HazelcastCommandLine.HazelcastVersionProvider) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) JobStatus(com.hazelcast.jet.core.JobStatus) CommandLine(picocli.CommandLine) XmlClientConfigBuilder(com.hazelcast.client.config.XmlClientConfigBuilder) MCClusterMetadata(com.hazelcast.client.impl.management.MCClusterMetadata) YamlClientConfigBuilder(com.hazelcast.client.config.YamlClientConfigBuilder) Collections.emptyList(java.util.Collections.emptyList) Mixin(picocli.CommandLine.Mixin) Collection(java.util.Collection) ExecutionException(picocli.CommandLine.ExecutionException) ConsumerEx(com.hazelcast.function.ConsumerEx) ClientClusterService(com.hazelcast.client.impl.spi.ClientClusterService) InvocationTargetException(java.lang.reflect.InvocationTargetException) LockSupport(java.util.concurrent.locks.LockSupport) Option(picocli.CommandLine.Option) List(java.util.List) Util.idToString(com.hazelcast.jet.Util.idToString) JobStateSnapshot(com.hazelcast.jet.JobStateSnapshot) Util.toLocalDateTime(com.hazelcast.jet.impl.util.Util.toLocalDateTime) Util.uncheckCall(com.hazelcast.jet.impl.util.Util.uncheckCall) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) RunAll(picocli.CommandLine.RunAll) JobSummary(com.hazelcast.jet.impl.JobSummary) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) FutureUtil(com.hazelcast.internal.util.FutureUtil) HelpCommand(picocli.CommandLine.HelpCommand) HazelcastClient(com.hazelcast.client.HazelcastClient) LocalDateTime(java.time.LocalDateTime) CompletableFuture(java.util.concurrent.CompletableFuture) MCGetClusterMetadataCodec(com.hazelcast.client.impl.protocol.codec.MCGetClusterMetadataCodec) Function(java.util.function.Function) Level(java.util.logging.Level) JetException(com.hazelcast.jet.JetException) HazelcastBootstrap(com.hazelcast.instance.impl.HazelcastBootstrap) DefaultExceptionHandler(picocli.CommandLine.DefaultExceptionHandler) ClientConfig(com.hazelcast.client.config.ClientConfig) BuildInfo(com.hazelcast.instance.BuildInfo) ParseResult(picocli.CommandLine.ParseResult) Command(picocli.CommandLine.Command) Job(com.hazelcast.jet.Job) JobNotFoundException(com.hazelcast.jet.core.JobNotFoundException) PrintStream(java.io.PrintStream) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Cluster(com.hazelcast.cluster.Cluster) Ansi(picocli.CommandLine.Help.Ansi) IOException(java.io.IOException) Preconditions.checkNotNull(com.hazelcast.internal.util.Preconditions.checkNotNull) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) ClientDelegatingFuture(com.hazelcast.client.impl.ClientDelegatingFuture) ClusterState(com.hazelcast.cluster.ClusterState) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy) IVersionProvider(picocli.CommandLine.IVersionProvider) Comparator(java.util.Comparator) Collections(java.util.Collections) Util(com.hazelcast.jet.Util) SECONDS(java.util.concurrent.TimeUnit.SECONDS) JetClientInstanceImpl(com.hazelcast.jet.impl.JetClientInstanceImpl) Util.idToString(com.hazelcast.jet.Util.idToString) HelpCommand(picocli.CommandLine.HelpCommand) Command(picocli.CommandLine.Command)

Example 22 with Cluster

use of com.hazelcast.cluster.Cluster in project hazelcast by hazelcast.

the class SqlConsole method sqlStartingPrompt.

private static String sqlStartingPrompt(HazelcastInstance hz) {
    HazelcastClientInstanceImpl hazelcastClientImpl = getHazelcastClientInstanceImpl(hz);
    ClientClusterService clientClusterService = hazelcastClientImpl.getClientClusterService();
    MCClusterMetadata clusterMetadata = FutureUtil.getValue(getClusterMetadata(hazelcastClientImpl, clientClusterService.getMasterMember()));
    Cluster cluster = hazelcastClientImpl.getCluster();
    Set<Member> members = cluster.getMembers();
    String versionString = "Hazelcast " + clusterMetadata.getMemberVersion();
    return new AttributedStringBuilder().style(AttributedStyle.BOLD.foreground(PRIMARY_COLOR)).append("Connected to ").append(versionString).append(" at ").append(members.iterator().next().getAddress().toString()).append(" (+").append(String.valueOf(members.size() - 1)).append(" more)\n").append("Type 'help' for instructions").toAnsi();
}
Also used : HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) HazelcastCommandLine.getHazelcastClientInstanceImpl(com.hazelcast.client.console.HazelcastCommandLine.getHazelcastClientInstanceImpl) Cluster(com.hazelcast.cluster.Cluster) AttributedStringBuilder(org.jline.utils.AttributedStringBuilder) Member(com.hazelcast.cluster.Member) ClientClusterService(com.hazelcast.client.impl.spi.ClientClusterService) MCClusterMetadata(com.hazelcast.client.impl.management.MCClusterMetadata)

Example 23 with Cluster

use of com.hazelcast.cluster.Cluster in project hazelcast by hazelcast.

the class ClientClusterProxyTest method removeMembershipListener.

@Test
public void removeMembershipListener() throws Exception {
    Cluster cluster = client().getCluster();
    UUID regId = cluster.addMembershipListener(new MembershipAdapter());
    assertTrue(cluster.removeMembershipListener(regId));
}
Also used : MembershipAdapter(com.hazelcast.cluster.MembershipAdapter) Cluster(com.hazelcast.cluster.Cluster) UUID(java.util.UUID) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 24 with Cluster

use of com.hazelcast.cluster.Cluster in project hazelcast by hazelcast.

the class ClientRoundRobinLBTest method testRoundRobinLB_withMembers.

@Test
public void testRoundRobinLB_withMembers() {
    RoundRobinLB roundRobinLB = new RoundRobinLB();
    HazelcastInstance server = factory.newHazelcastInstance();
    Cluster cluster = server.getCluster();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setLoadBalancer(roundRobinLB);
    roundRobinLB.init(cluster, clientConfig);
    Member member = cluster.getLocalMember();
    assertEquals(member, roundRobinLB.next());
    assertEquals(member, roundRobinLB.nextDataMember());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Cluster(com.hazelcast.cluster.Cluster) ClientConfig(com.hazelcast.client.config.ClientConfig) Member(com.hazelcast.cluster.Member) RoundRobinLB(com.hazelcast.client.util.RoundRobinLB) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Cluster (com.hazelcast.cluster.Cluster)24 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 Member (com.hazelcast.cluster.Member)12 Test (org.junit.Test)12 QuickTest (com.hazelcast.test.annotation.QuickTest)11 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)10 ClientConfig (com.hazelcast.client.config.ClientConfig)5 Config (com.hazelcast.config.Config)5 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)4 MCClusterMetadata (com.hazelcast.client.impl.management.MCClusterMetadata)4 ClientClusterService (com.hazelcast.client.impl.spi.ClientClusterService)4 IPartition (com.hazelcast.internal.partition.IPartition)3 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)3 Partition (com.hazelcast.partition.Partition)3 PartitionService (com.hazelcast.partition.PartitionService)3 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)3 ExecutionException (java.util.concurrent.ExecutionException)3 HazelcastCommandLine.getHazelcastClientInstanceImpl (com.hazelcast.client.console.HazelcastCommandLine.getHazelcastClientInstanceImpl)2 RandomLB (com.hazelcast.client.util.RandomLB)2 RoundRobinLB (com.hazelcast.client.util.RoundRobinLB)2