use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class FlowVerificationTest method testFlowMissingConnection.
/**
* This test that verification of flow connections
*/
@Test
public void testFlowMissingConnection() throws Exception {
ApplicationSpecification appSpec = Specifications.from(new NoConsumerApp());
ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create(new ReflectionSchemaGenerator());
ApplicationSpecification newSpec = adapter.fromJson(adapter.toJson(appSpec));
FlowVerification flowVerifier = new FlowVerification();
for (FlowSpecification flowSpec : appSpec.getFlows().values()) {
VerifyResult result = flowVerifier.verify(new ApplicationId("test", newSpec.getName()), flowSpec);
Assert.assertTrue(result.getStatus() == VerifyResult.Status.FAILED);
}
}
use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class FlowVerificationTest method testFlowWithMoreOutputThanWhatInputCanHandle.
@Test
public void testFlowWithMoreOutputThanWhatInputCanHandle() throws Exception {
ApplicationSpecification appSpec = Specifications.from(new WebCrawlApp());
ApplicationSpecificationAdapter adapter = ApplicationSpecificationAdapter.create(new ReflectionSchemaGenerator());
ApplicationSpecification newSpec = adapter.fromJson(adapter.toJson(appSpec));
FlowVerification flowSpec = new FlowVerification();
for (Map.Entry<String, FlowSpecification> entry : newSpec.getFlows().entrySet()) {
VerifyResult result = flowSpec.verify(new ApplicationId("test", newSpec.getName()), entry.getValue());
// that is not connected to any input to flowlet CountByField.
if (entry.getValue().getName().equals("WordCountFlow")) {
Assert.assertTrue(result.getStatus() == VerifyResult.Status.FAILED);
} else {
Assert.assertTrue(result.getStatus() == VerifyResult.Status.SUCCESS);
}
}
}
use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class AbstractProgramTwillRunnable method initialize.
@Override
public void initialize(TwillContext context) {
name = context.getSpecification().getName();
LOG.info("Initializing runnable: " + name);
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler());
System.setSecurityManager(new RunnableSecurityManager(System.getSecurityManager()));
// Install the JUL to SLF4J Bridge
SLF4JBridgeHandler.install();
runLatch = new CountDownLatch(1);
coreServices = new ArrayList<>();
try {
CommandLine cmdLine = parseArgs(context.getApplicationArguments());
ClassLoader classLoader = getClass().getClassLoader();
// Loads configurations
hConf = new Configuration();
hConf.clear();
hConf.addResource(classLoader.getResource(cmdLine.getOptionValue(RunnableOptions.HADOOP_CONF_FILE)));
UserGroupInformation.setConfiguration(hConf);
cConf = CConfiguration.create();
cConf.clear();
cConf.addResource(classLoader.getResource(cmdLine.getOptionValue(RunnableOptions.CDAP_CONF_FILE)));
programOpts = createProgramOptions(cmdLine, context, context.getSpecification().getConfigs());
// This impersonation info is added in PropertiesResolver#getSystemProperties
// if kerberos is enabled we expect the principal to be provided in the program options as we
// need it to be used later in ExploreClient to make request. If kerberos is disabled this will be null
String principal = programOpts.getArguments().getOption(ProgramOptionConstants.PRINCIPAL);
ProgramId programId = GSON.fromJson(cmdLine.getOptionValue(RunnableOptions.PROGRAM_ID), ProgramId.class);
String instanceId = programOpts.getArguments().getOption(ProgramOptionConstants.INSTANCE_ID);
String runId = programOpts.getArguments().getOption(ProgramOptionConstants.RUN_ID);
Injector injector = Guice.createInjector(createModule(context, programId, runId, instanceId, principal));
coreServices.add(injector.getInstance(ZKClientService.class));
coreServices.add(injector.getInstance(KafkaClientService.class));
coreServices.add(injector.getInstance(BrokerService.class));
coreServices.add(injector.getInstance(MetricsCollectionService.class));
coreServices.add(injector.getInstance(StreamCoordinatorClient.class));
// Initialize log appender
logAppenderInitializer = injector.getInstance(LogAppenderInitializer.class);
logAppenderInitializer.initialize();
// Create the ProgramRunner
programRunner = createProgramRunner(injector);
try {
Location programJarLocation = Locations.toLocation(new File(cmdLine.getOptionValue(RunnableOptions.JAR)));
ApplicationSpecification appSpec = readAppSpec(new File(cmdLine.getOptionValue(RunnableOptions.APP_SPEC_FILE)));
program = Programs.create(cConf, programRunner, new ProgramDescriptor(programId, appSpec), programJarLocation, new File(cmdLine.getOptionValue(RunnableOptions.EXPANDED_JAR)));
} catch (IOException e) {
throw Throwables.propagate(e);
}
coreServices.add(new ProgramRunnableResourceReporter(program.getId(), injector.getInstance(MetricsCollectionService.class), context));
LOG.info("Runnable initialized: {}", name);
} catch (Throwable t) {
LOG.error(t.getMessage(), t);
throw Throwables.propagate(t);
}
}
use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class DistributedServiceProgramRunner method setupLaunchConfig.
@Override
protected void setupLaunchConfig(LaunchConfig launchConfig, Program program, ProgramOptions options, CConfiguration cConf, Configuration hConf, File tempDir) {
ApplicationSpecification appSpec = program.getApplicationSpecification();
ServiceSpecification serviceSpec = appSpec.getServices().get(program.getName());
// Add a runnable for the service handler
launchConfig.addRunnable(serviceSpec.getName(), new ServiceTwillRunnable(serviceSpec.getName()), serviceSpec.getInstances(), options.getUserArguments().asMap(), serviceSpec.getResources());
}
use of co.cask.cdap.api.app.ApplicationSpecification in project cdap by caskdata.
the class DistributedWorkerProgramRunner method setupLaunchConfig.
@Override
protected void setupLaunchConfig(LaunchConfig launchConfig, Program program, ProgramOptions options, CConfiguration cConf, Configuration hConf, File tempDir) throws IOException {
ApplicationSpecification appSpec = program.getApplicationSpecification();
WorkerSpecification workerSpec = appSpec.getWorkers().get(program.getName());
String instances = options.getArguments().getOption(ProgramOptionConstants.INSTANCES, String.valueOf(workerSpec.getInstances()));
launchConfig.addRunnable(workerSpec.getName(), new WorkerTwillRunnable(workerSpec.getName()), Integer.parseInt(instances), options.getUserArguments().asMap(), workerSpec.getResources());
}
Aggregations