Tries to connect an existing branch to a template

@param branchId Branch to connect
198035
@RequestMapping(value = "branches/{branchId}/template/connect", method = RequestMethod.POST)
    public Branch connectTemplateInstance(@PathVariable ID branchId, @RequestBody BranchTemplateInstanceConnectRequest request) {
        return branchTemplateService.connectTemplateInstance(branchId, request);
    }
468268
def get_branch_by_id(self, branch_id):
        
        for branch in self.branches:
            if branch.branch_id == branch_id:
                return branch
        raise AssertionError("couldn't find branch '%s'" % branch_id)
232430
public Object prepare(Xid xid, List<? extends TransactionBranchInfo> branches) throws LogException {
        int branchCount = branches.size();
        byte[][] data = new byte[3 + 2 * branchCount][];
        data[0] = intToBytes(xid.getFormatId());
        data[1] = xid.getGlobalTransactionId();
        data[2] = xid.getBranchQualifier();
        int i = 3;
        for (TransactionBranchInfo transactionBranchInfo : branches) {
            data[i++] = transactionBranchInfo.getBranchXid().getBranchQualifier();
            data[i++] = transactionBranchInfo.getResourceName().getBytes();
        }
        try {
            return logger.putCommit(data);
        } catch (LogClosedException | LogRecordSizeException | InterruptedException | LogFileOverflowException e) {
            throw new IllegalStateException(e);
        } catch (IOException e) {
            throw new LogException(e);
        }
    }
1047288
public function build($projectId, $branch = '')
    {
        /* @var \PHPCI\Model\Project $project */
        $project = $this->projectStore->getById($projectId);

        if (empty($project)) {
            throw new NotFoundException(Lang::get('project_x_not_found', $projectId));
        }
      
        if ($branch === '' && filter_input(INPUT_GET, 'branch') !== null) {
            $branch = filter_input(INPUT_GET, 'branch');
        }

        if (empty($branch)) {
            $branch = $project->getBranch();
        }

        $email = $_SESSION['phpci_user']->getEmail();
        $build = $this->buildService->createBuild($project, null, urldecode($branch), $email);

        if ($this->buildService->queueError) {
            $_SESSION['global_error'] = Lang::get('add_to_queue_failed');
        }

        $response = new b8\Http\Response\RedirectResponse();
        $response->setHeader('Location', PHPCI_URL.'build/view/' . $build->getId());
        return $response;
    }
55218
@RequestMapping(value = "branches/{branchId}/template/instance", method = RequestMethod.DELETE)
    public Branch disconnectTemplateInstance(@PathVariable ID branchId) {
        return branchTemplateService.disconnectTemplateInstance(branchId);
    }
318342
public void setLaunchTemplateIds(java.util.Collection<String> launchTemplateIds) {
        if (launchTemplateIds == null) {
            this.launchTemplateIds = null;
            return;
        }

        this.launchTemplateIds = new com.amazonaws.internal.SdkInternalList<String>(launchTemplateIds);
    }
1210242
void putBranchNode(int lineNumber, int branchNumber, Node block) {
    Preconditions.checkArgument(
        lineNumber > 0, "Expected non-zero positive integer as line number: %s", lineNumber);
    Preconditions.checkArgument(
        branchNumber > 0, "Expected non-zero positive integer as branch number: %s", branchNumber);

    branchNodes.put(BranchIndexPair.of(lineNumber - 1, branchNumber - 1), block);
  }
846646
@RequestMapping(value = "branches/{branchId}/filters", method = RequestMethod.GET)
    public Resources<BuildFilterResource<?>> buildFilters(@PathVariable ID branchId) {
        return Resources.of(
                buildFilterService.getBuildFilters(branchId),
                uri(on(getClass()).buildFilters(branchId))
        );
    }
1065423
private void createEdge(Node fromNode, ControlFlowGraph.Branch branch,
      Node toNode) {
    cfg.createNode(fromNode);
    cfg.createNode(toNode);
    cfg.connectIfNotFound(fromNode, branch, toNode);
  }
216522
public void start()	{
		if(logger.isDebugEnabled()) {
			logger.debug("start");
		}
		
		if(started) {
			throw new IllegalStateException("Proxy branch alredy started!");
		}
		if(canceled) {
			throw new IllegalStateException("Proxy branch was cancelled, you must create a new branch!");
		}
		if(timedOut) {
			throw new IllegalStateException("Proxy brnach has timed out!");
		}
		if(proxy.getAckReceived()) {
			throw new IllegalStateException("An ACK request has been received on this proxy. Can not start new branches.");
		}
		
		// Initialize these here for efficiency.
		if(logger.isDebugEnabled()) {
			logger.debug("start - calling updateTimer");
		}
		updateTimer(false, originalRequest.getSipApplicationSession(false));		
		
		SipURI recordRoute = null;
		
		// If the proxy is not adding record-route header, set it to null and it
		// will be ignored in the Proxying
		if(proxy.getRecordRoute() || this.getRecordRoute()) {
			if(recordRouteURI == null && recordRouteURIString == null) {
				recordRouteURIString = DEFAULT_RECORD_ROUTE_URI;
			}
			if(recordRouteURIString != null) {
				try {
					recordRouteURI = ((SipURI)proxy.getSipFactoryImpl().createURI(recordRouteURIString));
				} catch (ServletParseException e) {
					logger.error("A problem occured while setting the target URI while proxying a request " + recordRouteURIString, e);
				}
			}
			recordRoute = recordRouteURI;
		}
		addTransaction(originalRequest);

		URI destination = null;
                //app may have modified the branch request, so give it priority
                //fixes https://github.com/RestComm/sip-servlets/issues/131
                if (outgoingRequest.getRequestURI().equals(this.getProxy().getOriginalRequest().getRequestURI()))
                {
                    if(targetURI != null) {
                            try {
                                    destination = proxy.getSipFactoryImpl().createURI(targetURI);
                            } catch (ServletParseException e) {
                                    logger.error("A problem occured while setting the target URI while proxying a request " + targetURI, e);
                            }
                    }                    
                } else {
                    //the app has mofified the requestURI after branch creation..
                     destination = outgoingRequest.getRequestURI();
                }
		Request cloned = ProxyUtils.createProxiedRequest(
				outgoingRequest,
				this,
				destination,
				this.outboundInterface,
				recordRoute, 
				this.pathURI);
		//tells the application dispatcher to stop routing the original request
		//since it has been proxied
		originalRequest.setRoutingState(RoutingState.PROXIED);
		
		if(logger.isDebugEnabled()) {
			logger.debug("Proxy Branch 1xx Timeout set to " + proxyBranch1xxTimeout);
		}
		if(proxyBranch1xxTimeout > 0) {
			proxy1xxTimeoutTask = new ProxyBranchTimerTask(this, ResponseType.INFORMATIONAL, originalRequest.getSipApplicationSession(false));				
			proxy.getProxyTimerService().schedule(proxy1xxTimeoutTask, proxyBranch1xxTimeout * 1000L);
			proxyBranch1xxTimerStarted = true;
		}
		
		started = true;
		forwardRequest(cloned, false);		
	}
218551
public void addBranch(Long startPosition, String flowUuid, Map<String, Serializable> context) {
        Map<String, Long> runningPlansIds = getFromMap(RUNNING_PLANS_MAP);
        Long runningPlanId = runningPlansIds.get(flowUuid);
        addBranch(startPosition, runningPlanId, context, new ExecutionRuntimeServices(this));
    }
284857
@RequestMapping(value = "entity/promotionLevel/{project}/{branch}/{promotionLevel:.*}", method = RequestMethod.GET)
    public PromotionLevel promotionLevel(@PathVariable String project, @PathVariable String branch, @PathVariable String promotionLevel) {
        return structureService.findPromotionLevelByName(project, branch, promotionLevel)
                .orElseThrow(() -> new PromotionLevelNotFoundException(project, branch, promotionLevel));
    }
1198997
public function getByBranch($branchId, array $additionalFields = array())
    {
        return $this->getSingle(
            'region/get',
            'Region',
            array('branch_id' => (int)$branchId, 'fields' => self::getArray($additionalFields))
        );
    }
932347
private void publishMultiTaskData(WorkUnitState state, int branchId, Set<Path> writerOutputPathsMoved)
      throws IOException {
    publishData(state, branchId, false, writerOutputPathsMoved);
    addLineageInfo(state, branchId);
  }
553918
private void publishSingleTaskData(WorkUnitState state, int branchId)
      throws IOException {
    publishData(state, branchId, true, new HashSet<Path>());
    addLineageInfo(state, branchId);
  }
1138875
public void setBranchId(String brunchId) {
        Validate.isTrue(StringUtils.isEmpty(getBranchId()), "not allowed to overwrite branch id");
        contextMap.put(BRANCH_ID, brunchId);
    }
1013709
public DataWriterBuilder<S, D> forBranch(int branch) {
    this.branch = branch;
    log.debug("For branch: {}", this.branch);
    return this;
  }