use of com.datatorrent.api.Attribute in project apex-core by apache.
the class StramWebServices method getPortAttributes.
@GET
@Path(PATH_LOGICAL_PLAN_OPERATORS + "/{operatorName}/ports/{portName}/attributes")
@Produces(MediaType.APPLICATION_JSON)
public JSONObject getPortAttributes(@PathParam("operatorName") String operatorName, @PathParam("portName") String portName, @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.getPortAttributes(operatorName, portName).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);
}
use of com.datatorrent.api.Attribute in project apex-core by apache.
the class LogicalPlanConfigurationTest method testInvalidAttribute.
@Test
public void testInvalidAttribute() throws Exception {
Assert.assertNotSame(0, com.datatorrent.api.Context.DAGContext.serialVersionUID);
Attribute<String> attribute = new Attribute<>("", null);
Field nameField = Attribute.class.getDeclaredField("name");
nameField.setAccessible(true);
nameField.set(attribute, "NOT_CONFIGURABLE");
nameField.setAccessible(false);
ContextUtils.addAttribute(com.datatorrent.api.Context.DAGContext.class, attribute);
AttributeParseUtils.initialize();
ConfElement.initialize();
// attribute that cannot be configured
Properties props = new Properties();
props.put(StreamingApplication.APEX_PREFIX + "attr.NOT_CONFIGURABLE", "value");
LogicalPlanConfiguration dagBuilder = new LogicalPlanConfiguration(new Configuration(false));
dagBuilder.addFromProperties(props, null);
try {
dagBuilder.prepareDAG(new LogicalPlan(), null, "");
Assert.fail("Exception expected");
} catch (Exception e) {
Assert.assertThat("Attribute not configurable", e.getMessage(), RegexMatcher.matches("Attribute does not support property configuration: NOT_CONFIGURABLE.*"));
}
ContextUtils.removeAttribute(com.datatorrent.api.Context.DAGContext.class, attribute);
AttributeParseUtils.initialize();
ConfElement.initialize();
// invalid attribute name
props = new Properties();
String invalidAttribute = StreamingApplication.APEX_PREFIX + "attr.INVALID_NAME";
props.put(invalidAttribute, "value");
try {
new LogicalPlanConfiguration(new Configuration(false)).addFromProperties(props, null);
Assert.fail("Exception expected");
} catch (Exception e) {
LOG.debug("Exception message: {}", e);
Assert.assertThat("Invalid attribute name", e.getMessage(), RegexMatcher.matches("Invalid attribute reference: " + invalidAttribute));
}
}
use of com.datatorrent.api.Attribute in project apex-core by apache.
the class LogicalPlan method checkAttributeValueSerializable.
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");
}
}
use of com.datatorrent.api.Attribute in project apex-core by apache.
the class TypeDiscoverer method getAttrDescription.
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;
}
use of com.datatorrent.api.Attribute in project apex-core by apache.
the class YarnAppLauncherImpl method launchApp.
@Override
public YarnAppHandleImpl launchApp(final StreamingApplication app, Configuration conf, Attribute.AttributeMap launchParameters) throws LauncherException {
if (launchParameters != null) {
for (Map.Entry<Attribute<?>, Object> entry : launchParameters.entrySet()) {
String property = propMapping.get(entry.getKey());
if (property != null) {
setConfiguration(conf, property, entry.getValue());
}
}
}
try {
String name = app.getClass().getName();
StramAppLauncher appLauncher = new StramAppLauncher(name, conf);
appLauncher.loadDependencies();
StreamingAppFactory appFactory = new StreamingAppFactory(name, app.getClass()) {
@Override
public LogicalPlan createApp(LogicalPlanConfiguration planConfig) {
return super.createApp(app, planConfig);
}
};
ApplicationId appId = appLauncher.launchApp(appFactory);
appLauncher.resetContextClassLoader();
return new YarnAppHandleImpl(appId, conf);
} catch (Exception ex) {
throw new LauncherException(ex);
}
}
Aggregations