public static void addAttributeToArgs(Attribute<String> attribute, Context context, List<CharSequence> vargs) { String value = context.getValue(attribute); if (value != null) { vargs.add(String.format("-D%s=$'%s'", attribute.getLongName(), value.replace("\\", "\\\\\\\\").replaceAll("['\"$]", "\\\\$0"))); } } }
public static Map<Attribute<Object>, Object> getAllAttributes(Context context, Class<?> clazz) { Map<Attribute<Object>, Object> result = new HashMap<>(); try { for (Field f: clazz.getDeclaredFields()) { if (Modifier.isStatic(f.getModifiers()) && Attribute.class.isAssignableFrom(f.getType())) { @SuppressWarnings(value = "unchecked") Attribute<Object> attribute = (Attribute<Object>)f.get(null); result.put(attribute, context.getValue(attribute)); } } } catch (Exception ex) { throw Throwables.propagate(ex); } return result; }
@Override public <T> T getValue(Attribute<T> key) { T attr = attributes.get(key); if (attr != null) { return attr; } return parentContext == null ? key.defaultValue : parentContext.getValue(key); }
private <T extends PubSubWebSocketClient> T build(Class<T> clazz) { Preconditions.checkState(context != null, "Context not specified"); String gatewayAddress = context.getValue(LogicalPlan.GATEWAY_CONNECT_ADDRESS); if (gatewayAddress != null) { int timeout = context.getValue(LogicalPlan.PUBSUB_CONNECT_TIMEOUT_MILLIS); boolean gatewayUseSsl = context.getValue(LogicalPlan.GATEWAY_USE_SSL); // The builder can be used to build different types of PubSub clients in future but for now only one is supported SharedPubSubWebSocketClient wsClient = null; try { wsClient = new SharedPubSubWebSocketClient((gatewayUseSsl ? "wss://" : "ws://") + gatewayAddress + "/pubsub", timeout); String gatewayUserName = context.getValue(LogicalPlan.GATEWAY_USER_NAME); String gatewayPassword = context.getValue(LogicalPlan.GATEWAY_PASSWORD); if (gatewayUserName != null && gatewayPassword != null) { wsClient.setLoginUrl((gatewayUseSsl ? "https://" : "http://") + gatewayAddress + GATEWAY_LOGIN_URL_PATH); wsClient.setUserName(gatewayUserName); wsClient.setPassword(gatewayPassword); } return (T)wsClient; } catch (URISyntaxException e) { logger.warn("Unable to initialize websocket for gateway address {}", gatewayAddress, e); } return null; } return null; }
@Override public void setup(Context ctx) { tupleRecordingPartFileSize = ctx.getValue(LogicalPlan.TUPLE_RECORDING_PART_FILE_SIZE); tupleRecordingPartFileTimeMillis = ctx.getValue(LogicalPlan.TUPLE_RECORDING_PART_FILE_TIME_MILLIS); appId = ctx.getValue(LogicalPlan.APPLICATION_ID); appPath = ctx.getValue(LogicalPlan.APPLICATION_PATH); codecs = ctx.getAttributes().get(Context.DAGContext.STRING_CODECS); wsClient = new PubSubWebSocketClientBuilder().setContext(ctx).build(); RequestDelegateImpl impl = new RequestDelegateImpl(); RequestFactory rf = ctx.getValue(ContainerContext.REQUEST_FACTORY); if (rf == null) { logger.warn("No request factory defined, recording is disabled!"); } else { rf.registerDelegate(StramToNodeRequest.RequestType.START_RECORDING, impl); rf.registerDelegate(StramToNodeRequest.RequestType.STOP_RECORDING, impl); rf.registerDelegate(StramToNodeRequest.RequestType.SYNC_RECORDING, impl); } }