List of usage examples for com.google.common.collect FluentIterable get
@CheckReturnValue public final E get(int position)
From source file:es.bsc.demiurge.openstackjclouds.HostOpenStack.java
@Override public double getAssignedCpus() { //get the host administration API Optional<? extends HostAdministrationApi> hostAdminApi = openStackJclouds.getNovaApi() .getHostAdministrationExtensionForZone(openStackJclouds.getZone()); //get the information about the host resources FluentIterable<? extends HostResourceUsage> hostResourcesInfo = hostAdminApi.get() .listResourceUsage(hostname); //get the assigned CPUs int assignedCpus = hostResourcesInfo.get(1).getCpu(); //update the class attribute updateAssignedCpus(assignedCpus);//from ww w . j av a 2s . c om return assignedCpus; }
From source file:es.bsc.demiurge.openstackjclouds.HostOpenStack.java
@Override public double getAssignedDiskGb() { //get the host administration API Optional<? extends HostAdministrationApi> hostAdminApi = openStackJclouds.getNovaApi() .getHostAdministrationExtensionForZone(openStackJclouds.getZone()); //get the information about the host resources FluentIterable<? extends HostResourceUsage> hostResourcesInfo = hostAdminApi.get() .listResourceUsage(hostname); //get the assigned disk int assignedDiskGb = hostResourcesInfo.get(1).getDiskGb(); //update the class attribute updateAssignedDiskGb(assignedDiskGb); return assignedDiskGb; }
From source file:es.bsc.demiurge.openstackjclouds.HostOpenStack.java
@Override public double getAssignedMemoryMb() { //get the host administration API Optional<? extends HostAdministrationApi> hostAdminApi = openStackJclouds.getNovaApi() .getHostAdministrationExtensionForZone(openStackJclouds.getZone()); //get the information about the host resources FluentIterable<? extends HostResourceUsage> hostResourcesInfo = hostAdminApi.get() .listResourceUsage(hostname); //get the assigned memory int assignedMemoryMb = hostResourcesInfo.get(1).getMemoryMb(); //update the class attribute updateAssignedMemoryMb(assignedMemoryMb); return assignedMemoryMb; }
From source file:es.bsc.demiurge.openstackjclouds.HostOpenStack.java
private void initTotalResources() { //get the host administration API Optional<? extends HostAdministrationApi> hostAdminApi = openStackJclouds.getNovaApi() .getHostAdministrationExtensionForZone(openStackJclouds.getZone()); //get the information about the host resources FluentIterable<? extends HostResourceUsage> hostResourcesInfo = hostAdminApi.get() .listResourceUsage(hostname); //get the information about the total resources of the host HostResourceUsage totalRes = hostResourcesInfo.get(0); //assign total CPU, RAM, and disk totalCpus = totalRes.getCpu();// w w w . jav a 2 s . c o m totalMemoryMb = totalRes.getMemoryMb(); totalDiskGb = totalRes.getDiskGb(); }
From source file:org.sosy_lab.cpachecker.cpa.termination.TerminationARGPath.java
@Override public List<CFAEdge> getFullPath() { if (terminationFullPath != null) { return terminationFullPath; }/* w ww .ja va 2s . c om*/ ImmutableList.Builder<CFAEdge> fullPathBuilder = ImmutableList.builder(); PathIterator it = pathIterator(); Set<CFAEdge> intermediateTermiantionEdges = Sets.newHashSet(); while (it.hasNext()) { ARGState prev = it.getAbstractState(); CFAEdge curOutgoingEdge = it.getOutgoingEdge(); it.advance(); ARGState succ = it.getAbstractState(); TerminationState terminationPrev = extractStateByType(prev, TerminationState.class); TerminationState terminationSucc = extractStateByType(succ, TerminationState.class); // insert transition from loop to stem if (terminationPrev.isPartOfStem() && terminationSucc.isPartOfLoop()) { CFANode curNode = extractLocation(prev); List<CFAEdge> stemToLoopTransition = terminationInformation.createStemToLoopTransition(curNode, curNode); intermediateTermiantionEdges.addAll(stemToLoopTransition); fullPathBuilder.addAll(stemToLoopTransition); } // compute path between cur and next node if (curOutgoingEdge == null) { CFANode curNode = extractLocation(prev); CFANode nextNode = extractLocation(succ); // add negated ranking relation before target state (non-termination label) if (AbstractStates.isTargetState(succ)) { CFAEdge negatedRankingRelationAssumeEdge = terminationInformation .createRankingRelationAssumeEdge(curNode, nextNode, false); intermediateTermiantionEdges.add(negatedRankingRelationAssumeEdge); fullPathBuilder.add(negatedRankingRelationAssumeEdge); nextNode = curNode; } // we assume a linear chain of edges from 'prev' to 'succ' while (curNode != nextNode) { FluentIterable<CFAEdge> leavingEdges = CFAUtils.leavingEdges(curNode) .filter(not(in(intermediateTermiantionEdges))); if (!(leavingEdges.size() == 1 && curNode.getLeavingSummaryEdge() == null)) { return Collections.emptyList(); } CFAEdge intermediateEdge = leavingEdges.get(0); fullPathBuilder.add(intermediateEdge); curNode = intermediateEdge.getSuccessor(); } // we have a normal connection without hole in the edges } else { fullPathBuilder.add(curOutgoingEdge); } } terminationFullPath = fullPathBuilder.build(); terminationInformation.resetCfa(); return terminationFullPath; }
From source file:io.mesosphere.mesos.frameworks.cassandra.scheduler.CassandraCluster.java
@NotNull private String getExecutorIdForOffer(@NotNull final Protos.Offer offer) { final FluentIterable<CassandraNode> filter = from(clusterState.nodes()).filter(cassandraNodeHasExecutor()) .filter(cassandraNodeHostnameEq(offer.getHostname())); if (filter.isEmpty()) { return configuration.frameworkName() + ".node." + execCounter.getAndIncrement() + ".executor"; } else {//from w w w . java 2s .co m return filter.get(0).getCassandraNodeExecutor().getExecutorId(); } }
From source file:org.sosy_lab.cpachecker.util.cwriter.PathToCWithLoopsTranslator.java
/** * Recreates the code of one (or more nested) loops with gotos. * @param pCFAEdge the edge into the loop * @param currentBlock the current block * @param loopsAfter the loops which we are in after the edge * @return the complete c-code for the recreated loop *///w w w . jav a 2 s . c om private Pair<String, CFAEdge> recreateLoop(CFAEdge pCFAEdge, BasicBlock currentBlock, List<Loop> loopsAfter) { // clear all necessary things resetLoopAndIfMaps(); CFAEdge lastEdge = null; // start actual loop recreation StringBuilder wholeLoopString = new StringBuilder(); // we go into a loop thus we have to uproll it right now, and add all // handled edges to the handledEdges list, so they wont occur twice in the // generated c code // this should be already handled by the handledEdges check at the beginning // of the processEdge method assert loopsAfter.get(loopsAfter.size() - 1).getIncomingEdges().contains(pCFAEdge); Loop loop = loopsAfter.get(loopsAfter.size() - 1); // create necessary mappings String labelStayInLoop = createFreshLabelForLoop(pCFAEdge, loop); // uproll loop and write code wholeLoopString.append(labelStayInLoop).append(": ;\n"); Deque<CFAEdge> edgesToHandle = new ArrayDeque<>(); edgesToHandle.offer(pCFAEdge); Deque<Loop> loopStack = new ArrayDeque<>(); loopStack.push(loop); Deque<CFAEdge> ifStack = new ArrayDeque<>(); Deque<CFAEdge> outOfLoopEdgesStack = new ArrayDeque<>(); while ((!edgesToHandle.isEmpty() || !outOfLoopEdgesStack.isEmpty() || !ifStack.isEmpty())) { // all nodes from the current loop handled, so we can go on to the // next one if (edgesToHandle.isEmpty()) { // at first we need to handle ifs if (!ifStack.isEmpty()) { edgesToHandle.offer(ifStack.pop()); wholeLoopString.append("goto ").append(ifOutLabels.get(edgesToHandle.peek())).append(";\n") .append(ifElseLabels.get(edgesToHandle.peek())).append(": ;\n"); } else { edgesToHandle.offer(outOfLoopEdgesStack.pop()); Loop oldLoop = loopStack.pop(); wholeLoopString.append("goto ").append(loopInLabels.get(oldLoop)).append(";\n") .append(loopOutLabels.get(oldLoop)).append(": ;\n"); } } CFANode currentEdgePredecessor = edgesToHandle.peek().getPredecessor(); handleIfOutLabels(wholeLoopString, currentEdgePredecessor); // only continue if we didn't already visit this edge if (handledEdges.contains(edgesToHandle.peek())) { edgesToHandle.pop(); continue; } CFAEdge currentEdge = edgesToHandle.pop(); handledEdges.add(currentEdge); FluentIterable<CFAEdge> leaving = CFAUtils.leavingEdges(currentEdge.getSuccessor()) .filter(not(instanceOf(FunctionCallEdge.class))); // there was a function call, we need to replace it with the correct successor // as we are sure that there is only one, this is safe, we also don't // need to update loops here if (leaving.isEmpty()) { CFAEdge realLeavingEdge = currentEdge.getSuccessor().getLeavingEdge(0); CFAEdge leavingSummaryEdge = currentEdge.getSuccessor().getLeavingSummaryEdge(); wholeLoopString.append(processSimpleWithLoop(realLeavingEdge, currentBlock, "")); handledFunctions.add(((CFunctionEntryNode) realLeavingEdge.getSuccessor()).getFunctionName()); leaving = leaving.append(leavingSummaryEdge); // no function call just and ordinary statement, add it as it is // to the loopString } else if (leaving.size() == 1) { wholeLoopString.append(processSimpleWithLoop(leaving.get(0), currentBlock, "")); } // only one successor, to handle // we need to check the loops so that we know if we need // to update the loopStack, or only the handledEdges if (leaving.size() == 1) { CFAEdge onlyEdge = leaving.get(0); // this is an edge from inside the loop back to the loop if (loopToHead.get(loopStack.peek()) == onlyEdge.getSuccessor() && !loopStack.peek().getIncomingEdges().contains(onlyEdge)) { handledEdges.add(onlyEdge); handleIfOutLabels(wholeLoopString, onlyEdge.getPredecessor()); } else { edgesToHandle.offer(onlyEdge); updateLoopStack(wholeLoopString, loopStack, onlyEdge); } // more sucessors, we have to add some gotos } else { // there can be at most two leaving edges assert leaving.size() == 2 : leaving.toString(); CFAEdge leaving1 = leaving.get(0); CFAEdge leaving2 = leaving.get(1); // outgoing edges have to be handled first, this way // we can create the goto easier ImmutableSet<CFAEdge> outOfCurrentLoop = loopStack.peek().getOutgoingEdges(); boolean isOutOfLoopContained = false; CFAEdge leavingLoopEdge = null; if (outOfCurrentLoop.contains(leaving1)) { handleOutOfLoopEdge(currentBlock, wholeLoopString, edgesToHandle, loopStack, leaving1, leaving2); leavingLoopEdge = leaving1; isOutOfLoopContained = true; } else if (outOfCurrentLoop.contains(leaving2)) { handleOutOfLoopEdge(currentBlock, wholeLoopString, edgesToHandle, loopStack, leaving2, leaving1); leavingLoopEdge = leaving2; isOutOfLoopContained = true; } if (isOutOfLoopContained) { // we are alredy in the outermost loop that should be handled // if we have an edge which is leaving this loop we just need // to create a goto if (loopStack.size() == 1) { lastEdge = leavingLoopEdge; handledEdges.add(leavingLoopEdge); // deeper loopstack, potentially the same code as above // we do only need to handle the successor of the outOfLoopEdge, too } else { outOfLoopEdgesStack.push(leavingLoopEdge); } // end this loop iteration here continue; } // now comes the case where both edges stay in the loop, this means // this is a "simple" if statement // we need to find the merging point of both branches, such that we // know where the gotos and labels have to go if (!handledEdges.contains(leaving1)) { wholeLoopString.append(processSimpleWithLoop(leaving1, currentBlock, createFreshLabelForIf(leaving2, findEndOfBranches(singletonList(loopToHead.get(loopStack.peek())), currentEdgePredecessor, leaving1.getSuccessor(), leaving2.getSuccessor())))); edgesToHandle.push(leaving1); ifStack.push(leaving2); } } } wholeLoopString.append("goto ").append(loopInLabels.get(loop)).append(";\n").append(loopOutLabels.get(loop)) .append(": ;\n"); // assert ifOutLabelEnd.isEmpty() && loopStack.isEmpty(); return Pair.of(wholeLoopString.toString(), lastEdge); }
From source file:com.salesforce.ide.ui.views.runtest.RunTestsView.java
/** * Display org wide and individual class/trigger code coverage * from ApexOrgWideCoverage & ApexCodeCoverageAgg */// ww w . j ava2 s . co m @VisibleForTesting public void displayCodeCoverage() { if (Utils.isEmpty(forceProject) || Utils.isEmpty(runTestComposite)) return; final List<CodeCovResult> ccResults = Lists.newArrayList(); ApexOrgWideCoverage orgWide = getApexOrgWideCoverage(); ApexCodeCoverageAggregateResponse codeCovs = getApexCodeCoverageAgg(); IProject proj = forceProject.getProject(); // Get a list of existing Apex classes & triggers List<IResource> resources = ApexSourceUtils.INSTANCE.findLocalSourcesInProject(proj); resources = ApexSourceUtils.INSTANCE.filterSourcesByClassOrTrigger(resources); // Save overall code coverage Integer orgWidePercent = Utils.isNotEmpty(orgWide) ? orgWide.getPercentCovered() : 0; CodeCovResult ccResult = new CodeCovResult(Messages.View_CodeCoverageOverall, null, orgWidePercent, null, null); ccResults.add(ccResult); for (Record codeCov : codeCovs.records) { // Get name, percent and lines covered final String classOrTriggerName = codeCov.ApexClassOrTrigger.Name; Integer linesCovered = codeCov.NumLinesCovered; Integer total = linesCovered + codeCov.NumLinesUncovered; Integer percent = (int) Math.round(linesCovered * 100.0 / total); // Find the correct resource for the given classOrTriggerName FluentIterable<IResource> curRes = FluentIterable.from(resources).filter(new Predicate<IResource>() { @Override public boolean apply(IResource res) { if (res.getName().contains(classOrTriggerName)) { return true; } return false; } }); // Show code coverage markers on Apex class/trigger if (curRes != null && !curRes.isEmpty()) { try { // Save code coverage info with resource ApexCodeLocation location = findClass(curRes.get(0)); ccResults.add(new CodeCovResult(classOrTriggerName, location, percent, linesCovered, total)); applyCodeCoverageMarker(curRes.get(0), codeCov.Coverage.uncoveredLines); } catch (CoreException | BadLocationException e) { logger.error("Failed to apply code coverage warnings for " + classOrTriggerName, e); } } else { // Save code coverage info without resource ccResults.add(new CodeCovResult(classOrTriggerName, null, percent, linesCovered, total)); logger.error(String.format("Failed to find resource %s for code coverage", classOrTriggerName)); } } Display display = PlatformUI.getWorkbench().getDisplay(); display.syncExec(new Runnable() { @Override public void run() { // Update Apex Test Results view with code coverage runTestComposite.setCodeCoverage(ccResults); } }); }