flow.getAccountId(), flow.getApplicationId(), flow.getId(), flowletId, oldValue, newValue);
txnl.executeUnchecked(new TransactionExecutor.Function<AppMds, Void>() {
@Override
public Void apply(AppMds mds) throws Exception {
ApplicationSpecification appSpec = getAppSpecOrFail(mds, flow);
FlowSpecification flowSpec = getFlowSpecOrFail(flow, appSpec);
boolean adjusted = false;
List<FlowletConnection> conns = Lists.newArrayList();
for (FlowletConnection con : flowSpec.getConnections()) {
if (FlowletConnection.Type.STREAM == con.getSourceType() &&
flowletId.equals(con.getTargetName()) &&
oldValue.equals(con.getSourceName())) {
conns.add(new FlowletConnection(con.getSourceType(), newValue, con.getTargetName()));
adjusted = true;
} else {
conns.add(con);
}
}
if (!adjusted) {
throw new IllegalArgumentException(
String.format("Cannot change stream connection to %s, the connection to be changed is not found," +
" account: %s, application: %s, flow: %s, flowlet: %s, source stream: %s",
newValue, flow.getAccountId(), flow.getApplicationId(), flow.getId(), flowletId, oldValue));
}
FlowletDefinition flowletDef = getFlowletDefinitionOrFail(flowSpec, flowletId, flow);
FlowletDefinition newFlowletDef = new FlowletDefinition(flowletDef, oldValue, newValue);
ApplicationSpecification newAppSpec = replaceInAppSpec(appSpec, flow, flowSpec, newFlowletDef, conns);
replaceAppSpecInProgramJar(flow, newAppSpec, ProgramType.FLOW);
Id.Application app = flow.getApplication();
mds.apps.updateAppSpec(app.getAccountId(), app.getId(), newAppSpec);