@Override public RunId getRunId() { return delegate.getRunId(); }
/** * Get the RunId associated with the Twill controller. * @return the Twill RunId */ public RunId getTwillRunId() { return twillController.getRunId(); }
/** * Get the RunId associated with the Twill controller. * @return the Twill RunId */ public RunId getTwillRunId() { return twillController.getRunId(); }
protected AbstractTwillProgramController(String programName, TwillController twillController) { super(programName, twillController.getRunId()); this.programName = programName; this.twillController = twillController; }
@Override public RunId getRunId() { return delegate.getRunId(); }
@Override public void failed(Service.State from, Throwable failure) { LOG.info("Twill program failed: {} {}", programName, twillController.getRunId()); error(failure); } };
@Override public void running() { LOG.info("Twill program running: {} {}", programName, twillController.getRunId()); started(); }
@Override public void run() { LOG.info("Twill program running: {}, twill runId: {}", getProgramRunId(), twillController.getRunId()); started(); } }, Threads.SAME_THREAD_EXECUTOR);
@Override public void terminated(Service.State from) { LOG.info("Twill program terminated: {} {}", programName, twillController.getRunId()); stop(); }
@Override public void run() { LOG.info("Twill program running: {}, twill runId: {}", getProgramRunId(), twillController.getRunId()); started(); } }, Threads.SAME_THREAD_EXECUTOR);
/** * Terminates all instances of the {@link PeriodicNotificationTwillApp} on the YARN cluster. */ public void stopApp() { LOG.info("Stopping any running instances..."); int counter = 0; // It is possible that we have launched multiple instances of the app. For now, stop them all, one at a time. for(final TwillController c : twillRunner.lookup(PeriodicNotificationTwillApp.APPLICATION_NAME)) { final ResourceReport report = c.getResourceReport(); LOG.info("Attempting to stop {} with YARN ApplicationId: {} and Twill RunId: {}", PeriodicNotificationTwillApp.APPLICATION_NAME, report.getApplicationId(), c.getRunId()); Futures.getUnchecked(c.terminate()); LOG.info("Stopped {} with YARN ApplicationId: {} and Twill RunId: {}", PeriodicNotificationTwillApp.APPLICATION_NAME, report.getApplicationId(), c.getRunId()); counter++; } LOG.info("Stopped {} instance(s) of {}", counter, PeriodicNotificationTwillApp.APPLICATION_NAME); }
@Override public Map<RunId, RuntimeInfo> list(ProgramType type) { Map<RunId, RuntimeInfo> result = new HashMap<>(); Lock lock = runtimeInfosLock.readLock(); lock.lock(); try { result.putAll(runtimeInfos.row(type)); } finally { lock.unlock(); } // Add any missing RuntimeInfo from the remote twill runner if (remoteTwillRunnerService == null) { return Collections.unmodifiableMap(result); } for (TwillRunner.LiveInfo liveInfo : remoteTwillRunnerService.lookupLive()) { ProgramId programId = TwillAppNames.fromTwillAppName(liveInfo.getApplicationName(), false); if (programId == null || !programId.getType().equals(type)) { continue; } for (TwillController controller : liveInfo.getControllers()) { // For remote twill runner, the twill run id and cdap run id are the same RunId runId = controller.getRunId(); if (result.computeIfAbsent(runId, rid -> createRuntimeInfo(programId, runId, controller)) == null) { LOG.warn("Unable to create runtime info for program {} with run id {}", programId, runId); } } } return Collections.unmodifiableMap(result); }
@Override public Map<RunId, RuntimeInfo> list(ProgramType type) { Map<RunId, RuntimeInfo> result = new HashMap<>(); Lock lock = runtimeInfosLock.readLock(); lock.lock(); try { result.putAll(runtimeInfos.row(type)); } finally { lock.unlock(); } // Add any missing RuntimeInfo from the remote twill runner if (remoteTwillRunnerService == null) { return Collections.unmodifiableMap(result); } for (TwillRunner.LiveInfo liveInfo : remoteTwillRunnerService.lookupLive()) { ProgramId programId = TwillAppNames.fromTwillAppName(liveInfo.getApplicationName(), false); if (programId == null || !programId.getType().equals(type)) { continue; } for (TwillController controller : liveInfo.getControllers()) { // For remote twill runner, the twill run id and cdap run id are the same RunId runId = controller.getRunId(); if (result.computeIfAbsent(runId, rid -> createRuntimeInfo(programId, runId, controller)) == null) { LOG.warn("Unable to create runtime info for program {} with run id {}", programId, runId); } } } return Collections.unmodifiableMap(result); }
/** * Creates a {@link RuntimeInfo} representing the given program run. * * @param programId the program id for the program run * @param runId the run id for the program run * @param controller the {@link TwillController} controlling the corresponding twill application * @return a {@link RuntimeInfo} or {@code null} if not able to create the {@link RuntimeInfo} due to unexpected * and unrecoverable error/bug. */ @Nullable protected RuntimeInfo createRuntimeInfo(ProgramId programId, RunId runId, TwillController controller) { try { ProgramController programController = createController(programId, runId, controller); SimpleRuntimeInfo runtimeInfo = programController == null ? null : new SimpleRuntimeInfo(programController, programId, controller.getRunId()); if (runtimeInfo != null) { updateRuntimeInfo(programId.getType(), runId, runtimeInfo); } return runtimeInfo; } catch (Exception e) { return null; } }
/** * Creates a {@link RuntimeInfo} representing the given program run. * * @param programId the program id for the program run * @param runId the run id for the program run * @param controller the {@link TwillController} controlling the corresponding twill application * @return a {@link RuntimeInfo} or {@code null} if not able to create the {@link RuntimeInfo} due to unexpected * and unrecoverable error/bug. */ @Nullable protected RuntimeInfo createRuntimeInfo(ProgramId programId, RunId runId, TwillController controller) { try { ProgramController programController = createController(programId, runId, controller); SimpleRuntimeInfo runtimeInfo = programController == null ? null : new SimpleRuntimeInfo(programController, programId, controller.getRunId()); if (runtimeInfo != null) { updateRuntimeInfo(programId.getType(), runId, runtimeInfo); } return runtimeInfo; } catch (Exception e) { return null; } }
@Override public void reportResources() { for (TwillRunner.LiveInfo info : twillRunner.lookupLive()) { Map<String, String> metricContext = getMetricContext(info); if (metricContext == null) { continue; } // will have multiple controllers if there are multiple runs of the same application for (TwillController controller : info.getControllers()) { ResourceReport report = controller.getResourceReport(); if (report == null) { continue; } int memory = report.getAppMasterResources().getMemoryMB(); int vcores = report.getAppMasterResources().getVirtualCores(); Map<String, String> runContext = ImmutableMap.<String, String>builder() .putAll(metricContext) .put(Constants.Metrics.Tag.RUN_ID, controller.getRunId().getId()).build(); sendMetrics(runContext, 1, memory, vcores); } } reportYarnResources(); }
@Override public void reportResources() { for (TwillRunner.LiveInfo info : twillRunner.lookupLive()) { Map<String, String> metricContext = getMetricContext(info); if (metricContext == null) { continue; } // will have multiple controllers if there are multiple runs of the same application for (TwillController controller : info.getControllers()) { ResourceReport report = controller.getResourceReport(); if (report == null) { continue; } int memory = report.getAppMasterResources().getMemoryMB(); int vcores = report.getAppMasterResources().getVirtualCores(); Map<String, String> runContext = ImmutableMap.<String, String>builder() .putAll(metricContext) .put(Constants.Metrics.Tag.RUN_ID, controller.getRunId().getId()).build(); sendMetrics(runContext, 1, memory, vcores); } } reportYarnResources(); }
@Test public void testStopCluster() throws Exception { assumeNonMaprProfile(); Cluster myCluster = createCluster(); myCluster.setState(ClusterState.RUNNING); YarnController controller = Mockito.mock(YarnController.class); YarnService yarnService = new YarnService(new TestListener(), controller, Mockito.mock(NodeProvider.class)); TwillController twillController = Mockito.mock(TwillController.class); RunId runId = RunIds.generate(); when(controller.startCluster(any(YarnConfiguration.class), eq(myCluster.getClusterConfig().getSubPropertyList()))) .thenReturn(twillController); when(twillController.getRunId()).thenReturn(runId); myCluster.setRunId(new com.dremio.provision.RunId(runId.getId())); yarnService.stopCluster(myCluster); assertEquals(ClusterState.STOPPED, myCluster.getState()); }
private boolean expireAppMasterZKSession(TwillController controller, long timeout, TimeUnit timeoutUnit) { MBeanServer mbeanServer = MBeanRegistry.getInstance().getPlatformMBeanServer(); QueryExp query = Query.isInstanceOf(new StringValueExp(ConnectionMXBean.class.getName())); Stopwatch stopwatch = new Stopwatch(); stopwatch.start(); do { // Find the AM session and expire it Set<ObjectName> connectionBeans = mbeanServer.queryNames(ObjectName.WILDCARD, query); for (ObjectName objectName : connectionBeans) { ConnectionMXBean connectionBean = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, objectName, ConnectionMXBean.class, false); for (String node : connectionBean.getEphemeralNodes()) { if (node.endsWith("/instances/" + controller.getRunId().getId())) { // This is the AM, expire the session. LOG.info("Kill AM session {}", connectionBean.getSessionId()); connectionBean.terminateSession(); return true; } } } Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS); } while (stopwatch.elapsedTime(timeoutUnit) < timeout); return false; }
private ClusterEnriched startClusterAsync(Cluster cluster) throws YarnProvisioningHandlingException { YarnConfiguration yarnConfiguration = new YarnConfiguration(); updateYarnConfiguration(cluster, yarnConfiguration); List<Property> props = cluster.getClusterConfig().getSubPropertyList(); // only to show those props on UI/API defaultsConfigurator.getDistroTypeDefaultsConfigurator( cluster.getClusterConfig().getDistroType(), cluster.getClusterConfig().getIsSecure()).mergeProperties(props); List<Property> cleansedProperties = new ArrayList<>(); for (Property prop : props) { if (!EXCLUDED.contains(prop.getKey())) { cleansedProperties.add(prop); } } // async call - unfortunately I can not add event handlers before start of TwillController // which means we can miss failures TwillController twillController = yarnController.startCluster(yarnConfiguration, cleansedProperties); String runId = twillController.getRunId().getId(); RunId dRunId = new RunId(runId); cluster.setState(ClusterState.STARTING); cluster.setRunId(dRunId); OnRunningRunnable onRunning = new OnRunningRunnable(cluster); twillController.onRunning(onRunning, Threads.SAME_THREAD_EXECUTOR); initOnTerminatingThread(cluster, twillController); return getClusterInfo(cluster); }