List of usage examples for org.apache.commons.lang3.tuple ImmutableTriple ImmutableTriple
public ImmutableTriple(final L left, final M middle, final R right)
From source file:it.polimi.diceH2020.SPACE4CloudWS.core.CoarseGrainedOptimizer.java
private List<Triple<Integer, Optional<Double>, Boolean>> alterUntilBreakPoint(SolutionPerJob solPerJob, Function<Integer, Integer> updateFunction, Function<Double, Double> fromResult, Predicate<Double> feasibilityCheck, Predicate<Double> stoppingCondition, BiPredicate<Double, Double> incrementCheck, Predicate<Integer> vmCheck) { List<Triple<Integer, Optional<Double>, Boolean>> lst = new ArrayList<>(); Optional<Double> previous = Optional.empty(); boolean shouldKeepGoing = true; while (shouldKeepGoing) { Pair<Optional<Double>, Long> simulatorResult = dataProcessor.simulateClass(solPerJob); Optional<Double> maybeResult = simulatorResult.getLeft(); Optional<Double> interestingMetric = maybeResult.map(fromResult); Integer nVM = solPerJob.getNumberVM(); lst.add(new ImmutableTriple<>(nVM, maybeResult, interestingMetric.filter(feasibilityCheck).isPresent())); boolean terminationCriterion = !checkState(); logger.trace("terminationCriterion is " + terminationCriterion + " after checkState()"); terminationCriterion |= vmCheck.test(nVM); logger.trace("terminationCriterion is " + terminationCriterion + " after vmCheck.test()"); terminationCriterion |= interestingMetric.filter(stoppingCondition).isPresent(); logger.trace("terminationCriterion is " + terminationCriterion + " after filter"); if (previous.isPresent() && interestingMetric.isPresent() && (dataService.getScenario().getTechnology() != Technology.STORM || interestingMetric.get() == 0.0)) { terminationCriterion |= incrementCheck.test(previous.get(), interestingMetric.get()); }/*from w w w . j a va 2 s . com*/ shouldKeepGoing = !terminationCriterion; previous = interestingMetric; if (dataService.getScenario().getTechnology() == Technology.STORM) { logger.trace(interestingMetric.orElse(Double.NaN) + " vs. " + solPerJob.getJob().getU()); } else { logger.trace(interestingMetric.orElse(Double.NaN) + " vs. " + solPerJob.getJob().getD()); } if (shouldKeepGoing) { String message = String.format("class %s -> num VM: %d, simulator result: %f, metric: %f", solPerJob.getId(), nVM, maybeResult.orElse(Double.NaN), interestingMetric.orElse(Double.NaN)); logger.info(message); solPerJob.updateNumberVM(updateFunction.apply(nVM)); } } return lst; }
From source file:com.minlia.cloud.framework.test.common.service.search.AbstractSearchIntegrationTest.java
@Override @Test//from w w w . j a va2 s . c o m public final void givenResourceWithNameAndIdExists_whenResourceIsSearchedByCorrectIdAndCorrectName_thenOperationIsSuccessful() { final T existingResource = persistNewEntity(); // When // final ImmutableTriple<String, ClientOperation, String> nameConstraint = new ImmutableTriple<String, ClientOperation, String>(SearchField.name.toString(), EQ, existingResource.getName()); final ImmutableTriple<String, ClientOperation, String> idConstraint = new ImmutableTriple<String, ClientOperation, String>( SearchField.id.toString(), EQ, existingResource.getId().toString()); // final List<T> searchResults = getApi().searchAll(nameConstraint, idConstraint); // Then // assertThat(searchResults, Matchers.not(Matchers.<T> empty())); }
From source file:com.hurence.logisland.processor.datastore.EnrichRecords.java
/** * process events/* w w w . ja v a2s.c o m*/ * * @param context * @param records * @return */ @Override public Collection<Record> process(final ProcessContext context, final Collection<Record> records) { List<Record> outputRecords = new ArrayList<>(); List<Triple<Record, String, IncludeFields>> recordsToEnrich = new ArrayList<>(); if (records.size() != 0) { String excludesFieldName = context.getPropertyValue(EXCLUDES_FIELD).asString(); // Excludes : String[] excludesArray = null; if ((excludesFieldName != null) && (!excludesFieldName.isEmpty())) { excludesArray = excludesFieldName.split("\\s*,\\s*"); } //List<MultiGetQueryRecord> multiGetQueryRecords = new ArrayList<>(); MultiGetQueryRecordBuilder mgqrBuilder = new MultiGetQueryRecordBuilder(); mgqrBuilder.excludeFields(excludesArray); List<MultiGetResponseRecord> multiGetResponseRecords = null; // HashSet<String> ids = new HashSet<>(); // Use a Set to avoid duplicates for (Record record : records) { String recordKeyName = null; String indexName = null; String typeName = FieldDictionary.RECORD_TYPE; String includesFieldName = null; try { recordKeyName = context.getPropertyValue(RECORD_KEY_FIELD).evaluate(record).asString(); indexName = context.getPropertyValue(COLLECTION_NAME).evaluate(record).asString(); if (context.getPropertyValue(TYPE_NAME).isSet()) typeName = context.getPropertyValue(TYPE_NAME).evaluate(record).asString(); includesFieldName = context.getPropertyValue(INCLUDES_FIELD).evaluate(record).asString(); } catch (Throwable t) { record.setStringField(FieldDictionary.RECORD_ERRORS, "Failure in executing EL. Error: " + t.getMessage()); getLogger().error("Cannot interpret EL : " + record, t); } if (recordKeyName != null) { try { String key = record.getField(recordKeyName).asString(); // Includes : String[] includesArray = null; if ((includesFieldName != null) && (!includesFieldName.isEmpty())) { includesArray = includesFieldName.split("\\s*,\\s*"); } IncludeFields includeFields = new IncludeFields(includesArray); mgqrBuilder.add(indexName, typeName, includeFields.getAttrsToIncludeArray(), key); recordsToEnrich.add( new ImmutableTriple(record, asUniqueKey(indexName, typeName, key), includeFields)); } catch (Throwable t) { record.setStringField(FieldDictionary.RECORD_ERRORS, "Can not request datastore with " + indexName + " " + typeName + " " + recordKeyName); outputRecords.add(record); } } else { //record.setStringField(FieldDictionary.RECORD_ERRORS, "Interpreted EL returned null for recordKeyName"); outputRecords.add(record); //logger.error("Interpreted EL returned null for recordKeyName"); } } try { List<MultiGetQueryRecord> mgqrs = mgqrBuilder.build(); multiGetResponseRecords = datastoreClientService.multiGet(mgqrs); } catch (InvalidMultiGetQueryRecordException e) { getLogger().error("error while multiger", e); } if (multiGetResponseRecords == null || multiGetResponseRecords.isEmpty()) { return records; } // Transform the returned documents from ES in a Map Map<String, MultiGetResponseRecord> responses = multiGetResponseRecords.stream() .collect(Collectors.toMap(EnrichRecords::asUniqueKey, Function.identity())); recordsToEnrich.forEach(recordToEnrich -> { Triple<Record, String, IncludeFields> triple = recordToEnrich; Record outputRecord = triple.getLeft(); // TODO: should probably store the resulting recordKeyName during previous invocation above String key = triple.getMiddle(); IncludeFields includeFields = triple.getRight(); MultiGetResponseRecord responseRecord = responses.get(key); if ((responseRecord != null) && (responseRecord.getRetrievedFields() != null)) { // Retrieve the fields from responseRecord that matches the ones in the recordToEnrich. responseRecord.getRetrievedFields().forEach((k, v) -> { String fieldName = k.toString(); if (includeFields.includes(fieldName)) { // Now check if there is an attribute mapping rule to apply if (includeFields.hasMappingFor(fieldName)) { String mappedAttributeName = includeFields.getAttributeToMap(fieldName); // Replace the attribute name outputRecord.setStringField(mappedAttributeName, v.toString()); } else { outputRecord.setStringField(fieldName, v.toString()); } } }); } outputRecords.add(outputRecord); }); } return outputRecords; }
From source file:alluxio.master.file.PermissionCheckTest.java
@Test public void getPermissionOwner() throws Exception { ArrayList<Triple<String, String, Mode>> permissions = new ArrayList<>(); permissions/*from w ww .j av a 2 s . co m*/ .add(new ImmutableTriple<>(TEST_USER_1.getUser(), TEST_USER_1.getGroup(), new Mode((short) 0754))); LockedInodePath lockedInodePath = getLockedInodePath(permissions); try (Closeable r = new AuthenticatedUserRule(TEST_USER_1.getUser()).toResource()) { PermissionChecker checker = new PermissionChecker(mInodeTree); Mode.Bits actual = checker.getPermission(lockedInodePath); Assert.assertEquals(Mode.Bits.ALL, actual); } }
From source file:alluxio.master.file.PermissionCheckTest.java
@Test public void getPermissionGroup() throws Exception { ArrayList<Triple<String, String, Mode>> permissions = new ArrayList<>(); permissions/*from ww w .ja va 2 s . c o m*/ .add(new ImmutableTriple<>(TEST_USER_1.getUser(), TEST_USER_1.getGroup(), new Mode((short) 0754))); LockedInodePath lockedInodePath = getLockedInodePath(permissions); try (Closeable r = new AuthenticatedUserRule(TEST_USER_3.getUser()).toResource()) { PermissionChecker checker = new PermissionChecker(mInodeTree); Mode.Bits actual = checker.getPermission(lockedInodePath); Assert.assertEquals(Mode.Bits.READ_EXECUTE, actual); } }
From source file:com.minlia.cloud.framework.test.common.service.search.AbstractSearchIntegrationTest.java
@Override @Test/*from w ww.jav a 2s . c o m*/ public final void givenResourceWithNameAndIdExists_whenResourceIsSearchedByCorrectIdAndIncorrectName_thenResourceIsNotFound() { final T existingResource = persistNewEntity(); // When final ImmutableTriple<String, ClientOperation, String> nameConstraint = new ImmutableTriple<String, ClientOperation, String>( SearchField.name.toString(), EQ, randomAlphabetic(8)); final ImmutableTriple<String, ClientOperation, String> idConstraint = new ImmutableTriple<String, ClientOperation, String>( SearchField.id.toString(), EQ, existingResource.getId().toString()); final List<T> searchResults = getApi().searchAll(nameConstraint, idConstraint); // Then assertThat(searchResults, not(hasItem(existingResource))); }
From source file:alluxio.master.file.PermissionCheckTest.java
@Test public void getPermissionOther() throws Exception { ArrayList<Triple<String, String, Mode>> permissions = new ArrayList<>(); permissions//from w w w. j av a 2s. c o m .add(new ImmutableTriple<>(TEST_USER_1.getUser(), TEST_USER_1.getGroup(), new Mode((short) 0754))); LockedInodePath lockedInodePath = getLockedInodePath(permissions); try (Closeable r = new AuthenticatedUserRule(TEST_USER_2.getUser()).toResource()) { PermissionChecker checker = new PermissionChecker(mInodeTree); Mode.Bits actual = checker.getPermission(lockedInodePath); Assert.assertEquals(Mode.Bits.READ, actual); } }
From source file:com.minlia.cloud.framework.test.common.service.search.AbstractSearchIntegrationTest.java
@Override @Test/*from www. ja va2 s.c o m*/ public final void givenResourceExists_whenResourceIsSearchedByNegatedId_thenOperationIsSuccessful() { // Given final T existingResource = persistNewEntity(); // When final Triple<String, ClientOperation, String> negatedIdConstraint = new ImmutableTriple<String, ClientOperation, String>( SearchField.id.toString(), NEG_EQ, existingResource.getId().toString()); final List<T> searchResults = getApi().searchAll(negatedIdConstraint); // Then assertThat(searchResults, notNullValue()); }
From source file:com.telefonica.iot.cygnus.interceptors.NGSINameMappingsInterceptor.java
/** * Applies the mappings to the input NotifyContextRequest object. * //from w w w . j a v a2 s. co m * @param originalService * @param originalServicePath * @param originalCE * @return The input NotifyContextRequest object with maps applied */ public ImmutableTriple<String, String, ContextElement> doMap(String originalService, String originalServicePath, ContextElement originalCE) { if (nameMappings == null) { return new ImmutableTriple(originalService, originalServicePath, originalCE); } // if // Triple to be returned String newService = originalService; String newServicePath = originalServicePath; ContextElement newCE = originalCE.deepCopy(); // Map the service ServiceMapping serviceMapping = null; for (ServiceMapping sm : nameMappings.getServiceMappings()) { serviceMapping = sm; if (!serviceMapping.getOriginalServicePattern().matcher(originalService).matches()) { serviceMapping = null; continue; } // if LOGGER.debug("[nmi] FIWARE service found: " + originalService); if (serviceMapping.getNewService() != null) { newService = originalService.replaceAll(serviceMapping.getOriginalServicePattern().toString(), serviceMapping.getNewService()); LOGGER.debug("[nmi] FIWARE new service obtained: " + newService); } // if break; } // for if (serviceMapping == null) { LOGGER.debug("[nmi] FIWARE service not found: " + originalService); return new ImmutableTriple(newService, newServicePath, newCE); } // if // Map the service path ServicePathMapping servicePathMapping = null; for (ServicePathMapping spm : serviceMapping.getServicePathMappings()) { LOGGER.debug("[nmi] checking with servicePathMappings: " + spm.toString()); if (!spm.getOriginalServicePathPattern().matcher(originalServicePath).matches()) { continue; } // if LOGGER.debug("[nmi] FIWARE service path found: " + originalServicePath); for (EntityMapping em : spm.getEntityMappings()) { LOGGER.debug("[nmi] checking em: " + em.toString()); // check type if (em.getOriginalEntityType() != null) { if (!em.getOriginalEntityTypePattern().matcher(newCE.getType()).matches()) { continue; } else { if (spm.getNewServicePath() != null) { newServicePath = originalServicePath.replaceAll( spm.getOriginalServicePathPattern().toString(), spm.getNewServicePath()); } LOGGER.debug("[nmi] FIWARE new service path obtained: " + newServicePath); servicePathMapping = spm; break; } } else { if (spm.getNewServicePath() != null) { newServicePath = originalServicePath.replaceAll( spm.getOriginalServicePathPattern().toString(), spm.getNewServicePath()); } LOGGER.debug("[nmi] FIWARE new service path obtained: " + newServicePath); servicePathMapping = spm; break; } } if (servicePathMapping != null) { break; } } // for if (servicePathMapping == null) { LOGGER.debug("[nmi] FIWARE service path not found: " + originalServicePath); return new ImmutableTriple(newService, newServicePath, newCE); } // if String originalEntityId = newCE.getId(); String originalEntityType = newCE.getType(); String newEntityId = originalEntityId; String newEntityType = originalEntityType; EntityMapping entityMapping = null; for (EntityMapping em : servicePathMapping.getEntityMappings()) { entityMapping = em; LOGGER.debug("[nmi] checking with entityMapping: " + entityMapping.toString()); // check if match by Type if (entityMapping.getOriginalEntityType() != null) { if (!entityMapping.getOriginalEntityTypePattern().matcher(originalEntityType).matches()) { LOGGER.debug("[nmi] not matches type"); continue; } else { LOGGER.debug("[nmi] " + entityMapping.getOriginalEntityType() + " matches " + newCE.getType()); } } // check if match by Id if (entityMapping.getOriginalEntityId() != null) { if (!entityMapping.getOriginalEntityIdPattern().matcher(originalEntityId).matches()) { LOGGER.debug("[nmi] not matches entityId"); continue; } else { LOGGER.debug("[nmi] " + entityMapping.getOriginalEntityId() + " matches " + newCE.getId()); } } if (!entityMapping.getOriginalEntityIdPattern().matcher(originalEntityId).matches() || !entityMapping.getOriginalEntityTypePattern().matcher(originalEntityType).matches()) { LOGGER.debug("[nmi] not matches both type and entityId"); entityMapping = null; continue; } // if LOGGER.debug("[nmi] Entity found: " + originalEntityId + ", " + originalEntityType); if (entityMapping.getNewEntityId() != null) { LOGGER.debug("[nmi] IdPattern : " + entityMapping.getOriginalEntityIdPattern().toString()); newEntityId = originalEntityId.replaceAll(entityMapping.getOriginalEntityIdPattern().toString(), entityMapping.getNewEntityId()); LOGGER.debug("[nmi] newEntityId : " + newEntityId); } // if if (entityMapping.getNewEntityType() != null) { newEntityType = entityMapping.getNewEntityType(); } // if break; } // for if (entityMapping == null) { LOGGER.debug("[nmi] Entity not found: " + originalEntityId + ", " + originalEntityType); return new ImmutableTriple(newService, newServicePath, newCE); } // if newCE.setId(newEntityId); newCE.setType(newEntityType); for (ContextAttribute newCA : newCE.getAttributes()) { LOGGER.debug("[nmi] checking with CA: " + newCA.toString()); String originalAttributeName = newCA.getName(); String originalAttributeType = newCA.getType(); String newAttributeName = originalAttributeName; String newAttributeType = originalAttributeType; AttributeMapping attributeMapping = null; for (AttributeMapping am : entityMapping.getAttributeMappings()) { attributeMapping = am; LOGGER.debug("[nmi] checking with attributeMapping: " + attributeMapping.toString()); // Check attribute type if (attributeMapping.getOriginalAttributeType() != null) { if (!attributeMapping.getOriginalAttributeTypePattern().matcher(originalAttributeType) .matches()) { LOGGER.debug("[nmi] not matches attribute type"); continue; } else { LOGGER.debug("[nmi] " + attributeMapping.getOriginalAttributeType() + " matches "); } } // Check attribute name if (attributeMapping.getOriginalAttributeName() != null) { if (!attributeMapping.getOriginalAttributeNamePattern().matcher(originalAttributeName) .matches()) { LOGGER.debug("[nmi] not matches attribute name"); continue; } else { LOGGER.debug("[nmi] " + attributeMapping.getOriginalAttributeName() + " matches "); } } if (!attributeMapping.getOriginalAttributeNamePattern().matcher(originalAttributeName).matches() || !attributeMapping.getOriginalAttributeTypePattern().matcher(originalAttributeType) .matches()) { LOGGER.debug("[nmi] not matches both attribute type and name"); attributeMapping = null; continue; } // if LOGGER.debug("[nmi] Attribute found: " + originalAttributeName + ", " + originalAttributeType); if (attributeMapping.getNewAttributeName() != null) { newAttributeName = attributeMapping.getNewAttributeName(); } // if if (attributeMapping.getNewAttributeType() != null) { newAttributeType = attributeMapping.getNewAttributeType(); } // if break; } // for if (attributeMapping == null) { LOGGER.debug("[nmi] Attribute not found: " + originalAttributeName + ", " + originalAttributeType); continue; } // if newCA.setName(newAttributeName); newCA.setType(newAttributeType); LOGGER.debug("[nmi] newCA: " + newCA.toString()); } // for LOGGER.debug("[nmi] newCE: " + newCE.toString()); return new ImmutableTriple(newService, newServicePath, newCE); }
From source file:com.minlia.cloud.framework.test.common.service.search.AbstractSearchIntegrationTest.java
@Override @Test// w w w. j av a 2 s . c o m public final void givenResourceAndOtherResourcesExists_whenResourceIsSearchedByNegatedId_thenResourcesAreFound() { final T existingResource1 = persistNewEntity(); final T existingResource2 = persistNewEntity(); // When final ImmutableTriple<String, ClientOperation, String> idConstraint = new ImmutableTriple<String, ClientOperation, String>( SearchField.id.toString(), NEG_EQ, existingResource1.getId().toString()); final List<T> searchResults = getApi().searchAll(idConstraint); // Then assertThat(searchResults, not(hasItem(existingResource1))); assertThat(searchResults, hasItem(existingResource2)); }