com.datatorrent.api.Attribute Java Examples

The following examples show how to use com.datatorrent.api.Attribute. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StramWebServices.java    From attic-apex-core with Apache License 2.0 6 votes vote down vote up
@GET
@Path(PATH_LOGICAL_PLAN_OPERATORS + "/{operatorName}/attributes")
@Produces(MediaType.APPLICATION_JSON)
public JSONObject getOperatorAttributes(@PathParam("operatorName") String operatorName, @QueryParam("attributeName") String attributeName)
{
  init();
  OperatorMeta logicalOperator = dagManager.getLogicalPlan().getOperatorMeta(operatorName);
  if (logicalOperator == null) {
    throw new NotFoundException();
  }
  HashMap<String, String> map = new HashMap<>();
  for (Map.Entry<Attribute<?>, Object> entry : dagManager.getOperatorAttributes(operatorName).entrySet()) {
    if (attributeName == null || entry.getKey().getSimpleName().equals(attributeName)) {
      Map.Entry<Attribute<Object>, Object> entry1 = (Map.Entry<Attribute<Object>, Object>)(Map.Entry)entry;
      map.put(entry1.getKey().getSimpleName(), entry1.getKey().codec.toString(entry1.getValue()));
    }
  }
  return new JSONObject(map);
}
 
Example #2
Source File: AsyncFSStorageAgentTest.java    From attic-apex-core with Apache License 2.0 6 votes vote down vote up
@Override
protected void starting(Description description)
{
  super.starting(description);
  basePath = "target/" + description.getClassName() + "/" + description.getMethodName();
  applicationPath = basePath + "/app";
  try {
    FileUtils.forceMkdir(new File(basePath));
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
  storageAgent = new AsyncFSStorageAgent(applicationPath, null);

  Attribute.AttributeMap.DefaultAttributeMap attributes = new Attribute.AttributeMap.DefaultAttributeMap();
  attributes.put(DAG.APPLICATION_PATH, applicationPath);
}
 
Example #3
Source File: AbstractFileOutputOperatorTest.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
@Override
protected void starting(Description description)
{
  super.starting(description);
  TestUtils.deleteTargetTestClassFolder(description);
  try {
    FileUtils.forceMkdir(new File(getDir()));
    Attribute.AttributeMap.DefaultAttributeMap attributeMap = new Attribute.AttributeMap.DefaultAttributeMap();
    attributeMap.put(Context.DAGContext.CHECKPOINT_WINDOW_COUNT, 60);
    attributeMap.put(Context.OperatorContext.SPIN_MILLIS, 500);

    testOperatorContext = mockOperatorContext(0, attributeMap);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
Example #4
Source File: GeodeKeyValueStorageAgentTest.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
@Override
protected void starting(Description description)
{
  super.starting(description);

  applicationPath = "target/" + description.getClassName() + "/" + description.getMethodName();
  if (System.getProperty("dev.locator.connection") != null) {
    LOCATOR_HOST = System.getProperty("dev.locator.connection");
  }
  try {
    FileUtils.forceMkdir(new File("target/" + description.getClassName()));
  } catch (IOException e) {
    throw new RuntimeException(e);
  }

  Configuration config = new Configuration();
  config.set(GeodeKeyValueStorageAgent.GEODE_LOCATOR_STRING, LOCATOR_HOST);

  storageAgent = new GeodeKeyValueStorageAgent(config);
  storageAgent.setApplicationId(REGION_NAME);
  Attribute.AttributeMap.DefaultAttributeMap attributes = new Attribute.AttributeMap.DefaultAttributeMap();
  attributes.put(DAG.APPLICATION_PATH, applicationPath);
}
 
Example #5
Source File: SimpleTransformApplicationTest.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
@Test
public void testApplication() throws Exception
{
  Configuration conf = new Configuration(false);
  conf.addResource(this.getClass().getResourceAsStream("/META-INF/properties.xml"));
  EmbeddedAppLauncher<?> launcher = Launcher.getLauncher(Launcher.LaunchMode.EMBEDDED);
  Attribute.AttributeMap launchAttributes = new Attribute.AttributeMap.DefaultAttributeMap();
  launchAttributes.put(EmbeddedAppLauncher.RUN_ASYNC, true);
  SimpleTransformApplication simpleTransformApplication = new SimpleTransformApplication();
  simpleTransformApplication.outputFn = outputFn;
  Launcher.AppHandle appHandle = launcher.launchApp(simpleTransformApplication, conf, launchAttributes);
  int sleepTimeCounterForLoopExit = 0;
  int sleepTimePerIteration = 500;
  // wait until expected result count or timeout
  while (results.size() < simpleTransformApplication.pojoDataGenerator.getMaxTuples()) {
    sleepTimeCounterForLoopExit += sleepTimePerIteration;
    if (sleepTimeCounterForLoopExit > 30000) {
      break;
    }
    Thread.sleep(sleepTimePerIteration);
  }
  appHandle.shutdown(Launcher.ShutdownMode.KILL);
  assertEquals(results.size(), simpleTransformApplication.pojoDataGenerator.getMaxTuples());
  assertTransformationsGenerated(simpleTransformApplication);
}
 
Example #6
Source File: TypeDiscoverer.java    From attic-apex-core with Apache License 2.0 6 votes vote down vote up
private static JSONObject getAttrDescription(Context context, Collection<Field> attributes) throws JSONException,
    IllegalAccessException
{
  JSONObject response = new JSONObject();
  JSONArray attrArray = new JSONArray();
  response.put("attributes", attrArray);
  for (Field attrField : attributes) {
    JSONObject attrJson = new JSONObject();
    attrJson.put("name", attrField.getName());
    ParameterizedType attrType = (ParameterizedType)attrField.getGenericType();

    Attribute<?> attr = (Attribute<?>)attrField.get(context);
    Type pType = attrType.getActualTypeArguments()[0];

    TypeDiscoverer discoverer = new TypeDiscoverer();
    discoverer.resolveTypeParameters(pType, attrJson);

    if (attr.defaultValue != null) {
      attrJson.put("default", attr.defaultValue);
    }
    attrArray.put(attrJson);
  }
  return response;
}
 
Example #7
Source File: ApplicationTest.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
@Test
public void testApplication() throws Exception
{
  Configuration conf = new Configuration(false);
  conf.addResource(this.getClass().getResourceAsStream("/META-INF/properties.xml"));
  EmbeddedAppLauncher<?> launcher = Launcher.getLauncher(Launcher.LaunchMode.EMBEDDED);
  Attribute.AttributeMap launchAttributes = new Attribute.AttributeMap.DefaultAttributeMap();
  launchAttributes.put(EmbeddedAppLauncher.RUN_ASYNC, true);
  EnricherAppWithJSONFile enricherAppWithJSONFile = new EnricherAppWithJSONFile();
  enricherAppWithJSONFile.outputFn = outputFn;
  Launcher.AppHandle appHandle = launcher.launchApp(enricherAppWithJSONFile, conf, launchAttributes);
  int sleepTimeCounterForLoopExit = 0;
  int sleepTimePerIteration = 500;
  // wait until expected result count or timeout
  while (results.size() < enricherAppWithJSONFile.getDataGenerator().getLimit()) {
    sleepTimeCounterForLoopExit += sleepTimePerIteration;
    if (sleepTimeCounterForLoopExit > 30000) {
      break;
    }
    Thread.sleep(sleepTimePerIteration);
  }
  appHandle.shutdown(ShutdownMode.KILL);
  assertTrue(results.size() >= enricherAppWithJSONFile.getDataGenerator().getLimit());
  assertEnrichedOutput();
}
 
Example #8
Source File: TestModuleExpansion.java    From attic-apex-core with Apache License 2.0 6 votes vote down vote up
@Override
public void populateDAG(DAG dag, Configuration conf)
{
  DummyOperator o1 = dag.addOperator("O1", new DummyOperator());
  o1.setOperatorProp(level1ModuleProp);

  /** set various attribute on the operator for testing */
  Attribute.AttributeMap attr = dag.getMeta(o1).getAttributes();
  attr.put(OperatorContext.MEMORY_MB, memory);
  attr.put(OperatorContext.APPLICATION_WINDOW_COUNT, 2);
  attr.put(OperatorContext.LOCALITY_HOST, "host1");
  attr.put(OperatorContext.PARTITIONER, new TestPartitioner());
  attr.put(OperatorContext.CHECKPOINT_WINDOW_COUNT, 120);
  attr.put(OperatorContext.STATELESS, true);
  attr.put(OperatorContext.SPIN_MILLIS, 20);

  dag.setInputPortAttribute(o1.in, Context.PortContext.BUFFER_MEMORY_MB, portMemory);
  mIn.set(o1.in);
  mOut.set(o1.out1);
}
 
Example #9
Source File: LogicalPlanConfigurationTest.java    From attic-apex-core with Apache License 2.0 6 votes vote down vote up
private void simpleNameInputPortAssertHelperAssert(Attribute<?> attributeObj, Properties props, Object val, boolean set)
{
  SimpleTestApplicationWithName app = new SimpleTestApplicationWithName();

  LogicalPlanConfiguration dagBuilder = new LogicalPlanConfiguration(new Configuration(false));
  dagBuilder.addFromProperties(props, null);

  String appPath = app.getClass().getName().replace(".", "/") + ".class";

  LogicalPlan dag = new LogicalPlan();
  dagBuilder.prepareDAG(dag, app, appPath);

  simpleNameInputPortAssertHelper(attributeObj, dag, "operator1", val, set);
  simpleNameInputPortAssertHelper(attributeObj, dag, "operator2", val, set);
  simpleNameInputPortAssertHelper(attributeObj, dag, "operator3", val, set);
}
 
Example #10
Source File: FSSliceReaderTest.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
@Override
protected void starting(org.junit.runner.Description description)
{
  output = "target/" + description.getClassName() + "/" + description.getMethodName();
  try {
    FileUtils.forceMkdir(new File(output));
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
  dataFile = new File("src/test/resources/reader_test_data.csv");
  blockReader = getBlockReader();

  Attribute.AttributeMap.DefaultAttributeMap readerAttr = new Attribute.AttributeMap.DefaultAttributeMap();
  readerAttr.put(DAG.APPLICATION_ID, Long.toHexString(System.currentTimeMillis()));
  readerAttr.put(Context.OperatorContext.SPIN_MILLIS, 10);
  readerContext = mockOperatorContext(1, readerAttr);

  blockReader.setup(readerContext);

  messageSink = new CollectorTestSink<>();
  blockReader.messages.setSink(messageSink);

  blockMetadataSink = new CollectorTestSink<>();
  blockReader.blocksMetadataOutput.setSink(blockMetadataSink);
}
 
Example #11
Source File: TransformOperatorTest.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
@Override
protected void starting(Description description)
{
  super.starting(description);
  operator = new TransformOperator();

  sink = new CollectorTestSink<>();
  TestUtils.setSink(operator.output, sink);

  operator.setup(null);

  Attribute.AttributeMap inMap = new Attribute.AttributeMap.DefaultAttributeMap();
  inMap.put(Context.PortContext.TUPLE_CLASS, InputClass.class);
  operator.input.setup(new PortContext(inMap, null));

  Attribute.AttributeMap outMap = new Attribute.AttributeMap.DefaultAttributeMap();
  outMap.put(Context.PortContext.TUPLE_CLASS, OutputClass.class);
  operator.output.setup(new PortContext(outMap, null));
}
 
Example #12
Source File: LogicalPlanConfiguration.java    From attic-apex-core with Apache License 2.0 6 votes vote down vote up
/**
 * This method creates all the appropriate child {@link Conf}s of the given parent {@link Conf} and adds the given
 * attribute to the parent {@link Conf} if appropriate as well as all the child {@link Conf}s of the parent if
 * appropriate.
 *
 * @param conf The parent {@link Conf}.
 * @param attributeName The simple name of the attribute to add.
 * @param attrValue The value of the attribute.
 */
protected static void processAllConfsForAttribute(Conf conf, String attributeName, String attrValue)
{
  ConfElement confElement = conf.getConfElement();

  LOG.debug("Current confElement {} and name {}", confElement.getStramElement(), conf.getId());

  if (confElement.getContextAttributes().contains(attributeName)) {
    LOG.debug("Adding attribute");
    @SuppressWarnings("unchecked")
    Attribute<Object> attr = (Attribute<Object>)ContextUtils.CONTEXT_TO_ATTRIBUTE_NAME_TO_ATTRIBUTE.get(confElement.getContextClass()).get(attributeName);
    conf.setAttribute(attr, attrValue);
  }

  for (ConfElement childConfElement: confElement.getChildren()) {

    if (!childConfElement.getAllChildAttributes().contains(attributeName)) {
      continue;
    }

    Conf childConf = addConf(childConfElement.getStramElement(), WILDCARD, conf);
    processAllConfsForAttribute(childConf, attributeName, attrValue);
  }
}
 
Example #13
Source File: AbstractUpsertOutputOperatorCountersTest.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
@Before
public void setupApexContexts() throws Exception
{
  Attribute.AttributeMap.DefaultAttributeMap attributeMapForCounters =
      new Attribute.AttributeMap.DefaultAttributeMap();
  attributeMapForCounters.put(DAG.APPLICATION_ID, APP_ID);
  contextForCountersOperator = mockOperatorContext(OPERATOR_ID_FOR_COUNTER_COLUMNS, attributeMapForCounters);

  Attribute.AttributeMap.DefaultAttributeMap portAttributesForCounters =
      new Attribute.AttributeMap.DefaultAttributeMap();
  portAttributesForCounters.put(Context.PortContext.TUPLE_CLASS, CounterColumnTableEntry.class);
  testPortContextForCounters = new TestPortContext(portAttributesForCounters);

  counterUpdatesOperator = new CounterColumnUpdatesOperator();
  counterUpdatesOperator.setup(contextForCountersOperator);
  counterUpdatesOperator.activate(contextForCountersOperator);
  counterUpdatesOperator.input.setup(testPortContextForCounters);
}
 
Example #14
Source File: FilterTest.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
public void prepareFilterOperator(Class<?> inClass, String condition)
{
  filter.truePort.setSink(trueSink);
  filter.falsePort.setSink(falseSink);
  filter.error.setSink(errorSink);

  filter.setup(null);

  Attribute.AttributeMap in = new Attribute.AttributeMap.DefaultAttributeMap();
  in.put(Context.PortContext.TUPLE_CLASS, inClass);
  filter.input.setup(new PortContext(in, null));

  filter.setCondition(condition);

  filter.activate(null);
}
 
Example #15
Source File: S3ReconcilerTest.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
@Override
protected void starting(Description description)
{
  super.starting(description);
  outputPath = new File(
      "target" + Path.SEPARATOR + description.getClassName() + Path.SEPARATOR + description.getMethodName())
          .getPath();

  Attribute.AttributeMap attributes = new Attribute.AttributeMap.DefaultAttributeMap();
  attributes.put(DAG.DAGContext.APPLICATION_ID, description.getClassName());
  attributes.put(DAG.DAGContext.APPLICATION_PATH, outputPath);
  context = mockOperatorContext(1, attributes);

  underTest = new S3Reconciler();
  underTest.setAccessKey("");
  underTest.setSecretKey("");

  underTest.setup(context);

  MockitoAnnotations.initMocks(this);
  PutObjectResult result = new PutObjectResult();
  result.setETag(outputPath);
  when(s3clientMock.putObject((PutObjectRequest)any())).thenReturn(result);
  underTest.setS3client(s3clientMock);
}
 
Example #16
Source File: OperatorContextTestHelper.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
public static OperatorContext mockOperatorContext(int id, final AttributeMap map)
{
  OperatorContext context = Mockito.mock(OperatorContext.class);
  Mockito.when(context.getId()).thenReturn(id);
  Mockito.when(context.getAttributes()).thenReturn(map);
  Mockito.doThrow(new UnsupportedOperationException("not supported")).when(context).sendMetrics(Mockito.<Collection<String>>any());
  Mockito.doThrow(new UnsupportedOperationException("not supported")).when(context).setCounters(Mockito.any());
  Mockito.when(context.getValue(Mockito.<Attribute>any())).thenAnswer(new Answer<Object>()
  {
    @Override
    public Object answer(InvocationOnMock invocation) throws Throwable
    {
      final Attribute key = (Attribute)invocation.getArguments()[0];
      Object value = map.get(key);
      if (value != null) {
        return value;
      }
      return key.defaultValue;
    }
  });
  Mockito.doNothing().when(context).setCounters(Mockito.any());
  Mockito.when(context.getWindowsFromCheckpoint()).thenReturn(0);
  return context;
}
 
Example #17
Source File: LogicalPlanConfigurationTest.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
private void testAttributeAmbiguousSimpleHelper(Attribute<?> attributeObjOperator, Attribute<?> attributeObjPort,
    String root, String contextClass, Object val, boolean operatorSet,
    boolean portSet)
{
  Properties props = propertiesBuilder(attributeObjOperator.getSimpleName(), root, contextClass, val);

  simpleAttributeOperatorHelperAssert(attributeObjOperator, props, val, operatorSet);

  simpleNamePortAssertHelperAssert(attributeObjPort, props, val, portSet);
}
 
Example #18
Source File: JdbcPojoOperatorTest.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Test
public void testJdbcOutputOperator()
{
  JdbcTransactionalStore transactionalStore = new JdbcTransactionalStore();
  transactionalStore.setDatabaseDriver(DB_DRIVER);
  transactionalStore.setDatabaseUrl(URL);

  com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap attributeMap = new com.datatorrent.api.Attribute.AttributeMap.DefaultAttributeMap();
  attributeMap.put(DAG.APPLICATION_ID, APP_ID);
  OperatorContext context = mockOperatorContext(OPERATOR_ID, attributeMap);

  TestOutputOperator outputOperator = new TestOutputOperator();
  outputOperator.setBatchSize(3);
  outputOperator.setStore(transactionalStore);

  outputOperator.setup(context);

  outputOperator.activate(context);
  List<TestEvent> events = Lists.newArrayList();
  for (int i = 0; i < 10; i++) {
    events.add(new TestEvent(i));
  }

  outputOperator.beginWindow(0);
  for (TestEvent event : events) {
    outputOperator.input.process(event);
  }
  outputOperator.endWindow();

  Assert.assertEquals("rows in db", 10, outputOperator.getNumOfEventsInStore());
  cleanTable();
}
 
Example #19
Source File: LogicalPlanConfigurationTest.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
private void simpleAttributeInputPortHelper(Attribute<?> attributeObj, String root, boolean simpleName, Object val, boolean set)
{
  Properties props = propertiesBuilderInputPort(attributeObj.getSimpleName(), root, simpleName, val);

  simpleNameInputPortAssertHelperAssert(attributeObj, props, val, set);
  simpleNameOutputPortAssertHelperAssert(attributeObj, props, val, !set);
}
 
Example #20
Source File: PojoToAvroTest.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Override
protected void starting(org.junit.runner.Description description)
{
  Attribute.AttributeMap portAttributes = new Attribute.AttributeMap.DefaultAttributeMap();
  portAttributes.put(Context.PortContext.TUPLE_CLASS, SimpleOrder.class);
  portContext = new TestPortContext(portAttributes);
  super.starting(description);
  avroWriter.output.setSink(outputSink);
}
 
Example #21
Source File: LogicalPlanConfigurationTest.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
private void simpleNameOutputPortAssertHelper(Attribute<?> attributeObj, LogicalPlan dag, String operatorName, Object queueCapacity, boolean set)
{
  OperatorMeta operatorMeta = dag.getOperatorMeta(operatorName);

  for (OutputPortMeta outputPortMeta: operatorMeta.getOutputStreams().keySet()) {
    if (set) {
      Assert.assertEquals(queueCapacity, outputPortMeta.getValue(attributeObj));
    } else {
      Assert.assertNotEquals(queueCapacity, outputPortMeta.getValue(attributeObj));
    }
  }
}
 
Example #22
Source File: FileSplitterBaseTest.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Override
protected void starting(org.junit.runner.Description description)
{
  TestUtils.deleteTargetTestClassFolder(description);
  String methodName = description.getMethodName();
  String className = description.getClassName();
  this.dataDirectory = "target/" + className + "/" + methodName;
  try {
    filePaths = FileSplitterInputTest.createData(this.dataDirectory);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }

  fileSplitter = new FileSplitterBase();
  fileSplitter.setBlocksThreshold(100);
  fileSplitter.setFile(this.dataDirectory);

  Attribute.AttributeMap.DefaultAttributeMap attributes = new Attribute.AttributeMap.DefaultAttributeMap();
  attributes.put(Context.OperatorContext.SPIN_MILLIS, 500);

  context = mockOperatorContext(0, attributes);

  fileMetadataSink = new CollectorTestSink<>();
  TestUtils.setSink(fileSplitter.filesMetadataOutput, fileMetadataSink);

  blockMetadataSink = new CollectorTestSink<>();
  TestUtils.setSink(fileSplitter.blocksMetadataOutput, blockMetadataSink);
}
 
Example #23
Source File: PluginTests.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
@Test
public void testDispatch() throws InterruptedException
{
  DebugPlugin debugPlugin = new DebugPlugin();
  StaticPluginLocator<? extends DAGExecutionPlugin> locator = new StaticPluginLocator<>(debugPlugin);
  ApexPluginDispatcher pluginManager = new DefaultApexPluginDispatcher(locator,
      new StramTestSupport.TestAppContext(new Attribute.AttributeMap.DefaultAttributeMap()), null, null);
  pluginManager.init(new Configuration());
  pluginManager.dispatch(new DAGExecutionEvent.StramExecutionEvent(new StramEvent(StramEvent.LogLevel.DEBUG)
  {
    @Override
    public String getType()
    {
      return "TestEvent";
    }
  }));
  pluginManager.dispatch(new DAGExecutionEvent.CommitExecutionEvent(1234));
  pluginManager.dispatch(new DAGExecutionEvent.HeartbeatExecutionEvent(new StreamingContainerUmbilicalProtocol.ContainerHeartbeat()));
  LogicalPlan plan = new LogicalPlan();
  pluginManager.dispatch(new ApexPluginDispatcher.DAGChangeEvent(plan));
  debugPlugin.waitForEventDelivery(10);
  pluginManager.stop();

  Assert.assertEquals(1, debugPlugin.getEventCount());
  Assert.assertEquals(1, debugPlugin.getHeartbeatCount());
  Assert.assertEquals(1, debugPlugin.getCommitCount());
  Assert.assertEquals(plan, debugPlugin.getLogicalPlan());
}
 
Example #24
Source File: LogicalPlanConfiguration.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
private void setAttributes(List<? extends Conf> confs, Attribute.AttributeMap attributeMap)
{
  Set<Attribute<Object>> processedAttributes = Sets.newHashSet();
  //json object codec for complex attributes
  JSONObject2String jsonCodec = new JSONObject2String();
  if (confs.size() > 0) {
    for (Conf conf1 : confs) {
      for (Map.Entry<Attribute<Object>, String> e : conf1.attributes.entrySet()) {
        Attribute<Object> attribute = e.getKey();
        if (attribute.codec == null) {
          String msg = String.format("Attribute does not support property configuration: %s %s", attribute.name, e.getValue());
          throw new UnsupportedOperationException(msg);
        } else {
          if (processedAttributes.add(attribute)) {
            String val = e.getValue();
            if (val.trim().charAt(0) == '{' && !(attribute.codec instanceof JsonStringCodec)) {
              // complex attribute in json
              attributeMap.put(attribute, jsonCodec.fromString(val));
            } else {
              attributeMap.put(attribute, attribute.codec.fromString(val));
            }
          }
        }
      }
    }
  }
}
 
Example #25
Source File: FSStorageAgentTest.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
@Override
protected void starting(Description description)
{
  super.starting(description);
  applicationPath = "target/" + description.getClassName() + "/" + description.getMethodName();
  try {
    FileUtils.forceMkdir(new File("target/" + description.getClassName()));
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
  storageAgent = new FSStorageAgent(applicationPath, null);

  Attribute.AttributeMap.DefaultAttributeMap attributes = new Attribute.AttributeMap.DefaultAttributeMap();
  attributes.put(DAG.APPLICATION_PATH, applicationPath);
}
 
Example #26
Source File: ApexStreamImpl.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public ApexStream<T> setGlobalAttribute(Attribute attribute, Object value)
{
  graph.dagAttributes.add(Pair.of(attribute, value));
  return this;
}
 
Example #27
Source File: JMSObjectInputOperatorTest.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Override
protected void starting(Description description)
{
  testBase = new JMSTestBase();
  try {
    testBase.beforTest();
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
  String methodName = description.getMethodName();
  String className = description.getClassName();
  baseDir = "target/" + className + "/" + methodName;

  Attribute.AttributeMap attributeMap = new Attribute.AttributeMap.DefaultAttributeMap();
  attributeMap.put(Context.OperatorContext.SPIN_MILLIS, 500);
  attributeMap.put(Context.DAGContext.APPLICATION_PATH, baseDir);

  context = mockOperatorContext(1, attributeMap);
  operator = new JMSObjectInputOperator();
  operator.setSubject("TEST.FOO");
  operator.getConnectionFactoryProperties().put(JMSTestBase.AMQ_BROKER_URL, "vm://localhost");

  sink = new CollectorTestSink<Object>();
  operator.output.setSink(sink);
  operator.setup(context);
  operator.activate(context);
}
 
Example #28
Source File: SpillableSetMultimapImplTest.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Test
public void testLoad()
{
  Random random = new Random();
  final int keySize = 1000000;
  final int valueSize = 100000000;
  final int numOfEntry = 100000;

  SpillableStateStore store = testMeta.store;

  SpillableSetMultimapImpl<String, String> multimap = new SpillableSetMultimapImpl<>(testMeta.store, ID1, 0L,
      createStringSerde(), createStringSerde());

  Attribute.AttributeMap.DefaultAttributeMap attributes = new Attribute.AttributeMap.DefaultAttributeMap();
  attributes.put(DAG.APPLICATION_PATH, testMeta.applicationPath);
  OperatorContext context = mockOperatorContext(testMeta.operatorContext.getId(), attributes);
  store.setup(context);
  multimap.setup(context);

  store.beginWindow(1);
  multimap.beginWindow(1);
  for (int i = 0; i < numOfEntry; ++i) {
    multimap.put(String.valueOf(random.nextInt(keySize)), String.valueOf(random.nextInt(valueSize)));
  }
  multimap.endWindow();
  store.endWindow();
}
 
Example #29
Source File: TestModuleExpansion.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
/**
 * Verify attributes populated on DummyOperator from Level1 module
 */
private void validateOperatorAttribute(LogicalPlan dag, String name, int memory)
{
  LogicalPlan.OperatorMeta oMeta = dag.getOperatorMeta(name);
  Attribute.AttributeMap attrs = oMeta.getAttributes();
  Assert.assertEquals((int)attrs.get(OperatorContext.MEMORY_MB), memory);
  Assert.assertEquals("Application window id is 2 ", (int)attrs.get(OperatorContext.APPLICATION_WINDOW_COUNT), 2);
  Assert.assertEquals("Locality host is host1", attrs.get(OperatorContext.LOCALITY_HOST), "host1");
  Assert.assertEquals(attrs.get(OperatorContext.PARTITIONER).getClass(), TestPartitioner.class);
  Assert.assertEquals("Checkpoint window count ", (int)attrs.get(OperatorContext.CHECKPOINT_WINDOW_COUNT), 120);
  Assert.assertEquals("Operator is stateless ", attrs.get(OperatorContext.STATELESS), true);
  Assert.assertEquals("SPIN MILLIS is set to 20 ", (int)attrs.get(OperatorContext.SPIN_MILLIS), 20);

}
 
Example #30
Source File: LogicalPlan.java    From attic-apex-core with Apache License 2.0 5 votes vote down vote up
private void checkAttributeValueSerializable(AttributeMap attributes, String context)
{
  StringBuilder sb = new StringBuilder();
  String delim = "";
  // Check all attributes got operator are serializable
  for (Entry<Attribute<?>, Object> entry : attributes.entrySet()) {
    if (entry.getValue() != null && !(entry.getValue() instanceof Serializable)) {
      sb.append(delim).append(entry.getKey().getSimpleName());
      delim = ", ";
    }
  }
  if (sb.length() > 0) {
    throw new ValidationException("Attribute value(s) for " + sb.toString() + " in " + context + " are not serializable");
  }
}