List of usage examples for com.google.common.base Stopwatch createUnstarted
@CheckReturnValue public static Stopwatch createUnstarted()
From source file:com.thinkbiganalytics.feedmgr.nifi.CreateFeedBuilder.java
private void connectFeedToReusableTemplate(ProcessGroupDTO feedProcessGroup, ProcessGroupDTO categoryProcessGroup) throws NifiComponentNotFoundException { Stopwatch stopwatch = Stopwatch.createStarted(); String categoryProcessGroupId = categoryProcessGroup.getId(); String categoryParentGroupId = categoryProcessGroup.getParentGroupId(); String categoryProcessGroupName = categoryProcessGroup.getName(); String feedProcessGroupId = feedProcessGroup.getId(); String feedProcessGroupName = feedProcessGroup.getName(); ProcessGroupDTO reusableTemplateCategory = niFiObjectCache.getReusableTemplateCategoryProcessGroup(); if (reusableTemplateCategory == null) { throw new NifiClientRuntimeException( "Unable to find the Reusable Template Group. Please ensure NiFi has the 'reusable_templates' processgroup and appropriate reusable flow for this feed." + " You may need to import the base reusable template for this feed."); }// w ww. ja v a 2s .c o m String reusableTemplateCategoryGroupId = reusableTemplateCategory.getId(); stopwatch.stop(); log.debug("Time to get reusableTemplateCategory: {} ", stopwatch.elapsed(TimeUnit.MILLISECONDS)); stopwatch.reset(); Stopwatch totalStopWatch = Stopwatch.createUnstarted(); for (InputOutputPort port : inputOutputPorts) { totalStopWatch.start(); stopwatch.start(); PortDTO reusableTemplatePort = niFiObjectCache.getReusableTemplateInputPort(port.getInputPortName()); stopwatch.stop(); log.debug("Time to get reusableTemplate inputPort {} : {} ", port.getInputPortName(), stopwatch.elapsed(TimeUnit.MILLISECONDS)); stopwatch.reset(); if (reusableTemplatePort != null) { String categoryOutputPortName = categoryProcessGroupName + " to " + port.getInputPortName(); stopwatch.start(); PortDTO categoryOutputPort = niFiObjectCache.getCategoryOutputPort(categoryProcessGroupId, categoryOutputPortName); stopwatch.stop(); log.debug("Time to get categoryOutputPort {} : {} ", categoryOutputPortName, stopwatch.elapsed(TimeUnit.MILLISECONDS)); stopwatch.reset(); if (categoryOutputPort == null) { stopwatch.start(); //create it PortDTO portDTO = new PortDTO(); portDTO.setParentGroupId(categoryProcessGroupId); portDTO.setName(categoryOutputPortName); categoryOutputPort = restClient.getNiFiRestClient().processGroups() .createOutputPort(categoryProcessGroupId, portDTO); niFiObjectCache.addCategoryOutputPort(categoryProcessGroupId, categoryOutputPort); stopwatch.stop(); log.debug("Time to create categoryOutputPort {} : {} ", categoryOutputPortName, stopwatch.elapsed(TimeUnit.MILLISECONDS)); stopwatch.reset(); } stopwatch.start(); Set<PortDTO> feedOutputPorts = feedProcessGroup.getContents().getOutputPorts(); String feedOutputPortName = port.getOutputPortName(); if (feedOutputPorts == null || feedOutputPorts.isEmpty()) { feedOutputPorts = restClient.getNiFiRestClient().processGroups() .getOutputPorts(feedProcessGroup.getId()); } PortDTO feedOutputPort = NifiConnectionUtil.findPortMatchingName(feedOutputPorts, feedOutputPortName); stopwatch.stop(); log.debug("Time to create feedOutputPort {} : {} ", feedOutputPortName, stopwatch.elapsed(TimeUnit.MILLISECONDS)); stopwatch.reset(); if (feedOutputPort != null) { stopwatch.start(); //make the connection on the category from feed to category ConnectionDTO feedOutputToCategoryOutputConnection = niFiObjectCache.getConnection( categoryProcessGroupId, feedOutputPort.getId(), categoryOutputPort.getId()); stopwatch.stop(); log.debug("Time to get feedOutputToCategoryOutputConnection: {} ", stopwatch.elapsed(TimeUnit.MILLISECONDS)); stopwatch.reset(); if (feedOutputToCategoryOutputConnection == null) { stopwatch.start(); //CONNECT FEED OUTPUT PORT TO THE Category output port ConnectableDTO source = new ConnectableDTO(); source.setGroupId(feedProcessGroupId); source.setId(feedOutputPort.getId()); source.setName(feedProcessGroupName); source.setType(NifiConstants.NIFI_PORT_TYPE.OUTPUT_PORT.name()); ConnectableDTO dest = new ConnectableDTO(); dest.setGroupId(categoryProcessGroupId); dest.setName(categoryOutputPort.getName()); dest.setId(categoryOutputPort.getId()); dest.setType(NifiConstants.NIFI_PORT_TYPE.OUTPUT_PORT.name()); feedOutputToCategoryOutputConnection = restClient.createConnection(categoryProcessGroupId, source, dest); niFiObjectCache.addConnection(categoryProcessGroupId, feedOutputToCategoryOutputConnection); nifiFlowCache.addConnectionToCache(feedOutputToCategoryOutputConnection); stopwatch.stop(); log.debug("Time to create feedOutputToCategoryOutputConnection: {} ", stopwatch.elapsed(TimeUnit.MILLISECONDS)); stopwatch.reset(); } stopwatch.start(); //connection made on parent (root) to reusable template ConnectionDTO categoryToReusableTemplateConnection = niFiObjectCache.getConnection( categoryProcessGroup.getParentGroupId(), categoryOutputPort.getId(), reusableTemplatePort.getId()); stopwatch.stop(); log.debug("Time to get categoryToReusableTemplateConnection: {} ", stopwatch.elapsed(TimeUnit.MILLISECONDS)); stopwatch.reset(); //Now connect the category ProcessGroup to the global template if (categoryToReusableTemplateConnection == null) { stopwatch.start(); ConnectableDTO categorySource = new ConnectableDTO(); categorySource.setGroupId(categoryProcessGroupId); categorySource.setId(categoryOutputPort.getId()); categorySource.setName(categoryOutputPortName); categorySource.setType(NifiConstants.NIFI_PORT_TYPE.OUTPUT_PORT.name()); ConnectableDTO categoryToGlobalTemplate = new ConnectableDTO(); categoryToGlobalTemplate.setGroupId(reusableTemplateCategoryGroupId); categoryToGlobalTemplate.setId(reusableTemplatePort.getId()); categoryToGlobalTemplate.setName(reusableTemplatePort.getName()); categoryToGlobalTemplate.setType(NifiConstants.NIFI_PORT_TYPE.INPUT_PORT.name()); categoryToReusableTemplateConnection = restClient.createConnection(categoryParentGroupId, categorySource, categoryToGlobalTemplate); niFiObjectCache.addConnection(categoryParentGroupId, categoryToReusableTemplateConnection); nifiFlowCache.addConnectionToCache(categoryToReusableTemplateConnection); stopwatch.stop(); log.debug("Time to create categoryToReusableTemplateConnection: {} ", stopwatch.elapsed(TimeUnit.MILLISECONDS)); stopwatch.reset(); } } } totalStopWatch.stop(); log.debug("Time to connect feed to {} port. ElapsedTime: {} ", port.getInputPortName(), totalStopWatch.elapsed(TimeUnit.MILLISECONDS)); totalStopWatch.reset(); } }
From source file:ezbake.groups.service.CachingEzGroupsService.java
private Stopwatch getStopwatch() { Stopwatch watch = Stopwatch.createUnstarted(); if (logTimer) { watch.start(); } return watch; }