@Test public void testChangeState() throws Exception { YarnClient client = mock(YarnClient.class); YarnClusterConfiguration conf = mock(YarnClusterConfiguration.class); ClusterInfo clusterInfo = new ClusterInfo("foo", conf, client); UUID app = UUID.randomUUID(); ApplicationId yarnAppId = mock(ApplicationId.class); try (InstanceManager manager = new InstanceManager( Collections.singletonMap("foo", clusterInfo), mock(InstanceStateUpdateListener.class), mock(ScheduledExecutorService.class), AthenaXExtraConfigOptions.INSTANCE_MANAGER_RESCAN_INTERVAL.defaultValue())) { InstanceInfo instance = new InstanceInfo("foo", yarnAppId, mock(InstanceMetadata.class), mock(InstanceStatus.class)); manager.instances().put(app, instance); manager.changeState(app, new InstanceState().state(InstanceState.StateEnum.KILLED)); verify(client).killApplication(eq(yarnAppId)); } }
public void changeState(UUID uuid, InstanceState desiredState) throws IOException, YarnException { if (desiredState == null || desiredState.getState() != InstanceState.StateEnum.KILLED) { throw new UnsupportedOperationException(); } InstanceInfo info = instances().get(uuid); if (info == null) { return; } ClusterInfo cluster = clusters.get(info.clusterName()); Preconditions.checkNotNull(cluster); cluster.client().killApplication(info.appId()); }
InstanceManager implements AutoCloseable { public void changeState(UUID uuid, InstanceState desiredState) throws IOException, YarnException { if (desiredState == null || desiredState.getState() != InstanceState.StateEnum.KILLED) { throw new UnsupportedOperationException(); } InstanceInfo info = instances().get(uuid); if (info == null) { return; } ClusterInfo cluster = clusters.get(info.clusterName()); Preconditions.checkNotNull(cluster); cluster.client().killApplication(info.appId()); } }
InstanceManager implements AutoCloseable { public void changeState(UUID uuid, InstanceState desiredState) throws IOException, YarnException { if (desiredState == null || desiredState.getState() != InstanceState.StateEnum.KILLED) { throw new UnsupportedOperationException(); } InstanceInfo info = instances().get(uuid); if (info == null) { return; } ClusterInfo cluster = clusters.get(info.clusterName()); Preconditions.checkNotNull(cluster); cluster.client().killApplication(info.appId()); } @VisibleForTesting  InstanceManager(
      Map<String, ClusterInfo> clusters,
      InstanceStateUpdateListener listener,
      ScheduledExecutorService executor,
      long rescanInterval); }
InstanceManager implements AutoCloseable { public void changeState(UUID uuid, InstanceState desiredState) throws IOException, YarnException { if (desiredState == null || desiredState.getState() != InstanceState.StateEnum.KILLED) { throw new UnsupportedOperationException(); } InstanceInfo info = instances().get(uuid); if (info == null) { return; } ClusterInfo cluster = clusters.get(info.clusterName()); Preconditions.checkNotNull(cluster); cluster.client().killApplication(info.appId()); } @VisibleForTesting  InstanceManager(
      Map<String, ClusterInfo> clusters,
      InstanceStateUpdateListener listener,
      ScheduledExecutorService executor,
      long rescanInterval); @VisibleForTesting static InstanceManager create(
      AthenaXConfiguration conf,
      InstanceStateUpdateListener listener,
      ScheduledExecutorService executor); InstanceStatus getInstanceStatus(UUID uuid); InstanceState getInstanceState(UUID uuid); void changeState(UUID uuid, InstanceState desiredState); ConcurrentHashMap<UUID, InstanceInfo> instances(); void start(); @Override void close(); void killYarnApplication(String clusterName, ApplicationId appId); Map.Entry<UUID, ApplicationId> instantiate(
      JobDefinitionDesiredstate state,
      UUID jobUUID,
      JobCompilationResult job); }
InstanceManager implements AutoCloseable { public void changeState(UUID uuid, InstanceState desiredState) throws IOException, YarnException { if (desiredState == null || desiredState.getState() != InstanceState.StateEnum.KILLED) { throw new UnsupportedOperationException(); } InstanceInfo info = instances().get(uuid); if (info == null) { return; } ClusterInfo cluster = clusters.get(info.clusterName()); Preconditions.checkNotNull(cluster); cluster.client().killApplication(info.appId()); } @VisibleForTesting  InstanceManager(
      Map<String, ClusterInfo> clusters,
      InstanceStateUpdateListener listener,
      ScheduledExecutorService executor,
      long rescanInterval); @VisibleForTesting static InstanceManager create(
      AthenaXConfiguration conf,
      InstanceStateUpdateListener listener,
      ScheduledExecutorService executor); InstanceStatus getInstanceStatus(UUID uuid); InstanceState getInstanceState(UUID uuid); void changeState(UUID uuid, InstanceState desiredState); ConcurrentHashMap<UUID, InstanceInfo> instances(); void start(); @Override void close(); void killYarnApplication(String clusterName, ApplicationId appId); Map.Entry<UUID, ApplicationId> instantiate(
      JobDefinitionDesiredstate state,
      UUID jobUUID,
      JobCompilationResult job);  }