Tabnine Logo
SamzaContainer.shutdown
Code IndexAdd Tabnine to your IDE (free)

How to use
shutdown
method
in
org.apache.samza.container.SamzaContainer

Best Java code snippets using org.apache.samza.container.SamzaContainer.shutdown (Showing top 13 results out of 315)

origin: apache/samza

/**
 * Stops the {@link SamzaContainer}.
 * @return true if {@link SamzaContainer} had shutdown within task.shutdown.ms. false otherwise.
 */
private boolean stopSamzaContainer() {
 boolean hasContainerShutdown = true;
 if (container != null) {
  try {
   container.shutdown();
   LOGGER.info("Waiting {} ms for the container: {} to shutdown.", taskShutdownMs, container);
   hasContainerShutdown = containerShutdownLatch.await(taskShutdownMs, TimeUnit.MILLISECONDS);
  } catch (InterruptedException e) {
   LOGGER.error("Exception occurred when shutting down the container: {}.", container, e);
   hasContainerShutdown = false;
   if (containerException != null) {
    containerException = e;
   }
  }
  LOGGER.info(String.format("Shutdown status of container: %s for stream processor: %s is: %b.", container, processorId, hasContainerShutdown));
 }
 // We want to propagate TimeoutException when container shutdown times out. It is possible that the timeout exception
 // we propagate to the application runner maybe overwritten by container failure cause in case of interleaved execution.
 // It is acceptable since container exception is much more useful compared to timeout exception.
 // We can infer from the logs about the fact that container shutdown timed out or not for additional inference.
 if (!hasContainerShutdown && containerException == null) {
  containerException = new TimeoutException("Container shutdown timed out after " + taskShutdownMs + " ms.");
 }
 return hasContainerShutdown;
}
origin: org.apache.samza/samza-core_2.10

/**
 * Stops the {@link SamzaContainer}.
 * @return true if {@link SamzaContainer} had shutdown within task.shutdown.ms. false otherwise.
 */
private boolean stopSamzaContainer() {
 boolean hasContainerShutdown = true;
 if (container != null) {
  try {
   container.shutdown();
   LOGGER.info("Waiting {} ms for the container: {} to shutdown.", taskShutdownMs, container);
   hasContainerShutdown = containerShutdownLatch.await(taskShutdownMs, TimeUnit.MILLISECONDS);
  } catch (InterruptedException e) {
   LOGGER.error("Exception occurred when shutting down the container: {}.", container, e);
   hasContainerShutdown = false;
   if (containerException != null) {
    containerException = e;
   }
  }
  LOGGER.info(String.format("Shutdown status of container: %s for stream processor: %s is: %b.", container, processorId, hasContainerShutdown));
 }
 // We want to propagate TimeoutException when container shutdown times out. It is possible that the timeout exception
 // we propagate to the application runner maybe overwritten by container failure cause in case of interleaved execution.
 // It is acceptable since container exception is much more useful compared to timeout exception.
 // We can infer from the logs about the fact that container shutdown timed out or not for additional inference.
 if (!hasContainerShutdown && containerException == null) {
  containerException = new TimeoutException("Container shutdown timed out after " + taskShutdownMs + " ms.");
 }
 return hasContainerShutdown;
}
origin: org.apache.samza/samza-core_2.11

/**
 * Stops the {@link SamzaContainer}.
 * @return true if {@link SamzaContainer} had shutdown within task.shutdown.ms. false otherwise.
 */
private boolean stopSamzaContainer() {
 boolean hasContainerShutdown = true;
 if (container != null) {
  try {
   container.shutdown();
   LOGGER.info("Waiting {} ms for the container: {} to shutdown.", taskShutdownMs, container);
   hasContainerShutdown = containerShutdownLatch.await(taskShutdownMs, TimeUnit.MILLISECONDS);
  } catch (InterruptedException e) {
   LOGGER.error("Exception occurred when shutting down the container: {}.", container, e);
   hasContainerShutdown = false;
   if (containerException != null) {
    containerException = e;
   }
  }
  LOGGER.info(String.format("Shutdown status of container: %s for stream processor: %s is: %b.", container, processorId, hasContainerShutdown));
 }
 // We want to propagate TimeoutException when container shutdown times out. It is possible that the timeout exception
 // we propagate to the application runner maybe overwritten by container failure cause in case of interleaved execution.
 // It is acceptable since container exception is much more useful compared to timeout exception.
 // We can infer from the logs about the fact that container shutdown timed out or not for additional inference.
 if (!hasContainerShutdown && containerException == null) {
  containerException = new TimeoutException("Container shutdown timed out after " + taskShutdownMs + " ms.");
 }
 return hasContainerShutdown;
}
origin: org.apache.samza/samza-core_2.12

/**
 * Stops the {@link SamzaContainer}.
 * @return true if {@link SamzaContainer} had shutdown within task.shutdown.ms. false otherwise.
 */
private boolean stopSamzaContainer() {
 boolean hasContainerShutdown = true;
 if (container != null) {
  try {
   container.shutdown();
   LOGGER.info("Waiting {} ms for the container: {} to shutdown.", taskShutdownMs, container);
   hasContainerShutdown = containerShutdownLatch.await(taskShutdownMs, TimeUnit.MILLISECONDS);
  } catch (InterruptedException e) {
   LOGGER.error("Exception occurred when shutting down the container: {}.", container, e);
   hasContainerShutdown = false;
   if (containerException != null) {
    containerException = e;
   }
  }
  LOGGER.info(String.format("Shutdown status of container: %s for stream processor: %s is: %b.", container, processorId, hasContainerShutdown));
 }
 // We want to propagate TimeoutException when container shutdown times out. It is possible that the timeout exception
 // we propagate to the application runner maybe overwritten by container failure cause in case of interleaved execution.
 // It is acceptable since container exception is much more useful compared to timeout exception.
 // We can infer from the logs about the fact that container shutdown timed out or not for additional inference.
 if (!hasContainerShutdown && containerException == null) {
  containerException = new TimeoutException("Container shutdown timed out after " + taskShutdownMs + " ms.");
 }
 return hasContainerShutdown;
}
origin: org.apache.samza/samza-core

/**
 * Stops the {@link SamzaContainer}.
 * @return true if {@link SamzaContainer} had shutdown within task.shutdown.ms. false otherwise.
 */
private boolean stopSamzaContainer() {
 boolean hasContainerShutdown = true;
 if (container != null) {
  try {
   container.shutdown();
   LOGGER.info("Waiting {} ms for the container: {} to shutdown.", taskShutdownMs, container);
   hasContainerShutdown = containerShutdownLatch.await(taskShutdownMs, TimeUnit.MILLISECONDS);
  } catch (InterruptedException e) {
   LOGGER.error("Exception occurred when shutting down the container: {}.", container, e);
   hasContainerShutdown = false;
   if (containerException != null) {
    containerException = e;
   }
  }
  LOGGER.info(String.format("Shutdown status of container: %s for stream processor: %s is: %b.", container, processorId, hasContainerShutdown));
 }
 // We want to propagate TimeoutException when container shutdown times out. It is possible that the timeout exception
 // we propagate to the application runner maybe overwritten by container failure cause in case of interleaved execution.
 // It is acceptable since container exception is much more useful compared to timeout exception.
 // We can infer from the logs about the fact that container shutdown timed out or not for additional inference.
 if (!hasContainerShutdown && containerException == null) {
  containerException = new TimeoutException("Container shutdown timed out after " + taskShutdownMs + " ms.");
 }
 return hasContainerShutdown;
}
origin: apache/samza

 /**
  * Creates a new container heartbeat monitor if possible.
  * @param container the container to monitor
  * @return a new {@link ContainerHeartbeatMonitor} instance, or null if could not create one
  */
 private static ContainerHeartbeatMonitor createContainerHeartbeatMonitor(SamzaContainer container) {
  String coordinatorUrl = System.getenv(ShellCommandConfig.ENV_COORDINATOR_URL());
  String executionEnvContainerId = System.getenv(ShellCommandConfig.ENV_EXECUTION_ENV_CONTAINER_ID());
  if (executionEnvContainerId != null) {
   log.info("Got execution environment container id: {}", executionEnvContainerId);
   return new ContainerHeartbeatMonitor(() -> {
     try {
      container.shutdown();
      containerRunnerException = new SamzaException("Container shutdown due to expired heartbeat");
     } catch (Exception e) {
      log.error("Heartbeat monitor failed to shutdown the container gracefully. Exiting process.", e);
      System.exit(1);
     }
    }, new ContainerHeartbeatClient(coordinatorUrl, executionEnvContainerId));
  } else {
   log.warn("Execution environment container id not set. Container heartbeat monitor will not be created");
   return null;
  }
 }
}
origin: org.apache.samza/samza-core

 /**
  * Creates a new container heartbeat monitor if possible.
  * @param container the container to monitor
  * @return a new {@link ContainerHeartbeatMonitor} instance, or null if could not create one
  */
 private static ContainerHeartbeatMonitor createContainerHeartbeatMonitor(SamzaContainer container) {
  String coordinatorUrl = System.getenv(ShellCommandConfig.ENV_COORDINATOR_URL());
  String executionEnvContainerId = System.getenv(ShellCommandConfig.ENV_EXECUTION_ENV_CONTAINER_ID());
  if (executionEnvContainerId != null) {
   log.info("Got execution environment container id: {}", executionEnvContainerId);
   return new ContainerHeartbeatMonitor(() -> {
     try {
      container.shutdown();
      containerRunnerException = new SamzaException("Container shutdown due to expired heartbeat");
     } catch (Exception e) {
      log.error("Heartbeat monitor failed to shutdown the container gracefully. Exiting process.", e);
      System.exit(1);
     }
    }, new ContainerHeartbeatClient(coordinatorUrl, executionEnvContainerId));
  } else {
   log.warn("Execution environment container id not set. Container heartbeat monitor will not be created");
   return null;
  }
 }
}
origin: org.apache.samza/samza-core_2.11

 /**
  * Creates a new container heartbeat monitor if possible.
  * @param container the container to monitor
  * @return a new {@link ContainerHeartbeatMonitor} instance, or null if could not create one
  */
 private static ContainerHeartbeatMonitor createContainerHeartbeatMonitor(SamzaContainer container) {
  String coordinatorUrl = System.getenv(ShellCommandConfig.ENV_COORDINATOR_URL());
  String executionEnvContainerId = System.getenv(ShellCommandConfig.ENV_EXECUTION_ENV_CONTAINER_ID());
  if (executionEnvContainerId != null) {
   log.info("Got execution environment container id: {}", executionEnvContainerId);
   return new ContainerHeartbeatMonitor(() -> {
     try {
      container.shutdown();
      containerRunnerException = new SamzaException("Container shutdown due to expired heartbeat");
     } catch (Exception e) {
      log.error("Heartbeat monitor failed to shutdown the container gracefully. Exiting process.", e);
      System.exit(1);
     }
    }, new ContainerHeartbeatClient(coordinatorUrl, executionEnvContainerId));
  } else {
   log.warn("Execution environment container id not set. Container heartbeat monitor will not be created");
   return null;
  }
 }
}
origin: org.apache.samza/samza-core_2.10

 /**
  * Creates a new container heartbeat monitor if possible.
  * @param container the container to monitor
  * @return a new {@link ContainerHeartbeatMonitor} instance, or null if could not create one
  */
 private static ContainerHeartbeatMonitor createContainerHeartbeatMonitor(SamzaContainer container) {
  String coordinatorUrl = System.getenv(ShellCommandConfig.ENV_COORDINATOR_URL());
  String executionEnvContainerId = System.getenv(ShellCommandConfig.ENV_EXECUTION_ENV_CONTAINER_ID());
  if (executionEnvContainerId != null) {
   log.info("Got execution environment container id: {}", executionEnvContainerId);
   return new ContainerHeartbeatMonitor(() -> {
     try {
      container.shutdown();
      containerRunnerException = new SamzaException("Container shutdown due to expired heartbeat");
     } catch (Exception e) {
      log.error("Heartbeat monitor failed to shutdown the container gracefully. Exiting process.", e);
      System.exit(1);
     }
    }, new ContainerHeartbeatClient(coordinatorUrl, executionEnvContainerId));
  } else {
   log.warn("Execution environment container id not set. Container heartbeat monitor will not be created");
   return null;
  }
 }
}
origin: org.apache.samza/samza-core_2.12

 /**
  * Creates a new container heartbeat monitor if possible.
  * @param container the container to monitor
  * @return a new {@link ContainerHeartbeatMonitor} instance, or null if could not create one
  */
 private static ContainerHeartbeatMonitor createContainerHeartbeatMonitor(SamzaContainer container) {
  String coordinatorUrl = System.getenv(ShellCommandConfig.ENV_COORDINATOR_URL());
  String executionEnvContainerId = System.getenv(ShellCommandConfig.ENV_EXECUTION_ENV_CONTAINER_ID());
  if (executionEnvContainerId != null) {
   log.info("Got execution environment container id: {}", executionEnvContainerId);
   return new ContainerHeartbeatMonitor(() -> {
     try {
      container.shutdown();
      containerRunnerException = new SamzaException("Container shutdown due to expired heartbeat");
     } catch (Exception e) {
      log.error("Heartbeat monitor failed to shutdown the container gracefully. Exiting process.", e);
      System.exit(1);
     }
    }, new ContainerHeartbeatClient(coordinatorUrl, executionEnvContainerId));
  } else {
   log.warn("Execution environment container id not set. Container heartbeat monitor will not be created");
   return null;
  }
 }
}
origin: apache/samza

@Test
public void testCoordinatorFailureShouldStopTheStreamProcessor() {
 JobCoordinator mockJobCoordinator = Mockito.mock(JobCoordinator.class);
 ProcessorLifecycleListener lifecycleListener = Mockito.mock(ProcessorLifecycleListener.class);
 SamzaContainer mockSamzaContainer = Mockito.mock(SamzaContainer.class);
 MapConfig config = new MapConfig(ImmutableMap.of("task.shutdown.ms", "0"));
 StreamProcessor streamProcessor = new StreamProcessor("TestProcessorId", config, new HashMap<>(), null, lifecycleListener, mockJobCoordinator);
 Exception failureException = new Exception("dummy exception");
 streamProcessor.container = mockSamzaContainer;
 streamProcessor.state = State.RUNNING;
 streamProcessor.jobCoordinatorListener.onCoordinatorFailure(failureException);
 Mockito.doNothing().when(mockSamzaContainer).shutdown();
 Mockito.when(mockSamzaContainer.hasStopped()).thenReturn(false);
 assertEquals(State.STOPPED, streamProcessor.state);
 Mockito.verify(lifecycleListener).afterFailure(failureException);
 Mockito.verify(mockSamzaContainer).shutdown();
}
origin: apache/samza

@Test
public void testStopShouldBeIdempotent() {
 JobCoordinator mockJobCoordinator = Mockito.mock(JobCoordinator.class);
 ProcessorLifecycleListener lifecycleListener = Mockito.mock(ProcessorLifecycleListener.class);
 SamzaContainer mockSamzaContainer = Mockito.mock(SamzaContainer.class);
 MapConfig config = new MapConfig(ImmutableMap.of("task.shutdown.ms", "0"));
 StreamProcessor streamProcessor = PowerMockito.spy(new StreamProcessor("TestProcessorId", config, new HashMap<>(), null, lifecycleListener, mockJobCoordinator));
 Mockito.doNothing().when(mockJobCoordinator).stop();
 Mockito.doNothing().when(mockSamzaContainer).shutdown();
 Mockito.when(mockSamzaContainer.hasStopped()).thenReturn(false);
 Mockito.when(mockSamzaContainer.getStatus())
     .thenReturn(SamzaContainerStatus.STARTED)
     .thenReturn(SamzaContainerStatus.STOPPED);
 streamProcessor.state = State.RUNNING;
 streamProcessor.stop();
 assertEquals(State.STOPPING, streamProcessor.state);
}
origin: apache/samza

Mockito.doNothing().when(mockSamzaContainer).shutdown();
Mockito.when(mockSamzaContainer.hasStopped()).thenReturn(false);
Mockito.when(mockSamzaContainer.getStatus())
Mockito.verify(mockSamzaContainer, Mockito.times(1)).shutdown();
Mockito.verify(mockJobCoordinator, Mockito.times(1)).stop();
org.apache.samza.containerSamzaContainershutdown

Popular methods of SamzaContainer

  • readJobModel
  • run
  • setContainerListener
  • DEFAULT_READ_JOBMODEL_DELAY_MS
  • apply
  • getStatus
  • hasStopped

Popular in Java

  • Updating database using SQL prepared statement
  • compareTo (BigDecimal)
  • putExtra (Intent)
  • requestLocationUpdates (LocationManager)
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • BigDecimal (java.math)
    An immutable arbitrary-precision signed decimal.A value is represented by an arbitrary-precision "un
  • ConcurrentHashMap (java.util.concurrent)
    A plug-in replacement for JDK1.5 java.util.concurrent.ConcurrentHashMap. This version is based on or
  • JarFile (java.util.jar)
    JarFile is used to read jar entries and their associated data from jar files.
  • Get (org.apache.hadoop.hbase.client)
    Used to perform Get operations on a single row. To get everything for a row, instantiate a Get objec
  • DateTimeFormat (org.joda.time.format)
    Factory that creates instances of DateTimeFormatter from patterns and styles. Datetime formatting i
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now