use of org.javatuples.Triplet in project Dempsy by Dempsy.
the class TestWordCount method testWordCountHomogeneousProcessing.
@Test
public void testWordCountHomogeneousProcessing() throws Throwable {
final String[][] ctxs = { // adaptor only node
{ "classpath:/word-count/adaptor-kjv.xml" }, { "classpath:/word-count/mp-word-count.xml", "classpath:/word-count/mp-word-rank.xml" }, { "classpath:/word-count/mp-word-count.xml", "classpath:/word-count/mp-word-rank.xml" }, { "classpath:/word-count/mp-word-count.xml", "classpath:/word-count/mp-word-rank.xml" }, { "classpath:/word-count/mp-word-count.xml", "classpath:/word-count/mp-word-rank.xml" } };
// the adaptor is the first one.
final int NUM_WC = ctxs.length - 1;
try (@SuppressWarnings("resource") final SystemPropertyManager props = new SystemPropertyManager().set("min_nodes", Integer.toString(NUM_WC)).set("routing-group", ":group").set("send_threads", "1").set("receive_threads", "1").set("blocking-queue-size", "500000")) {
WordCounter.aliveWordsToTestPassivate.clear();
// need to make it wait.
WordProducer.latch = new CountDownLatch(1);
runCombos("testWordCountHomogeneousProcessing", (r, c, s, t, ser) -> isElasticRoutingStrategy(r) && isContainerOkay(c), ctxs, n -> {
final ClusterId countCId = new ClusterId(currentAppName, "test-cluster1");
final ClusterId rankCId = new ClusterId(currentAppName, "test-cluster2");
final List<NodeManagerWithContext> nodes = n.nodes;
final NodeManager[] managers = nodes.stream().map(nm -> nm.manager).toArray(NodeManager[]::new);
// wait until I can reach the cluster from the adaptor.
assertTrue(poll(o -> managers[0].getRouter().allReachable("test-cluster1").size() == NUM_WC));
assertTrue(poll(o -> managers[0].getRouter().allReachable("test-cluster2").size() == NUM_WC));
WordProducer.latch.countDown();
final WordProducer adaptor = nodes.get(0).ctx.getBean(WordProducer.class);
waitForAllSent(adaptor);
// get all of the stats collectors.
final List<Triplet<NodeMetricGetters, ClusterMetricGetters, ClusterMetricGetters>> statsByNode = Arrays.asList(managers).subList(1, managers.length).stream().map(nm -> Triplet.with((NodeMetricGetters) nm.getNodeStatsCollector(), (ClusterMetricGetters) nm.getClusterStatsCollector(countCId), (ClusterMetricGetters) nm.getClusterStatsCollector(rankCId))).collect(Collectors.toList());
final NodeMetricGetters adaptorStats = (NodeMetricGetters) managers[0].getNodeStatsCollector();
final int totalSent = adaptor.numDispatched;
// now wait for the sum of all messages received by the ranking to be the number sent
assertTrue(poll(o -> {
// System.out.println("" + adaptor.numDispatched + " ==? ");
final int allDiscardedMessagesCount = allDiscardedMessagesCount(adaptorStats, castToTupleList3(statsByNode));
final int totalRanked = allDiscardedMessagesCount + statsByNode.stream().mapToInt(sc -> (int) sc.getValue2().getDispatchedMessageCount()).sum();
// System.out.println(": " + totalRanked + " == " + totalSent);
return totalRanked == totalSent;
}));
// no nodes (except the adaptor node) should have sent any messages.
// IOW, messages got to the Rank processor never leaving the node the Count was executed.
final List<NodeMetricGetters> nodeStats = Arrays.asList(managers).subList(1, managers.length).stream().map(nm -> nm.getNodeStatsCollector()).map(s -> (NodeMetricGetters) s).collect(Collectors.toList());
// if the routing id isn't a group id then there should be cross talk.
assertEquals(NUM_WC, nodeStats.size());
for (final NodeMetricGetters mg : nodeStats) assertEquals(0, mg.getMessagesNotSentCount());
if (isGroupRoutingStrategy(routerId)) {
for (final NodeMetricGetters mg : nodeStats) assertEquals(0, mg.getMessagesSentCount());
} else {
assertNotNull(nodeStats.stream().filter(mg -> mg.getMessagesSentCount() > 0).findFirst().orElse(null));
}
});
final int remaining = WordCounter.aliveWordsToTestPassivate.size();
WordCounter.aliveWordsToTestPassivate.clear();
assertEquals(0, remaining);
}
}
use of org.javatuples.Triplet in project repository-permissions-updater by jenkins-infra.
the class HostingChecker method checkRequest.
public void checkRequest(int issueID) throws IOException {
boolean hasBuildSystem = false;
HashSet<VerificationMessage> hostingIssues = new HashSet<>();
boolean debug = System.getProperty("debugHosting", "false").equalsIgnoreCase("true");
ArrayList<Triplet<String, Verifier, ConditionChecker>> verifications = new ArrayList<>();
verifications.add(Triplet.with("Jira", new HostingFieldVerifier(), null));
verifications.add(Triplet.with("GitHub", new GitHubVerifier(), null));
verifications.add(Triplet.with("Maven", new MavenVerifier(), new FileExistsConditionChecker("pom.xml")));
verifications.add(Triplet.with("Gradle", new GradleVerifier(), new FileExistsConditionChecker("build.gradle")));
verifications.add(Triplet.with("JenkinsProjectUsers", new JenkinsProjectUserVerifier(), null));
// verifications.add(Triplet.with("Kotlin", new KotlinVerifier(), new FileExistsConditionChecker("build.gradle.kts")));
final HostingRequest hostingRequest = HostingRequestParser.retrieveAndParse(issueID);
for (Triplet<String, Verifier, ConditionChecker> verifier : verifications) {
try {
boolean runIt = verifier.getValue2() == null || verifier.getValue2().checkCondition(hostingRequest);
if (runIt) {
LOGGER.info("Running verification '" + verifier.getValue0() + "'");
verifier.getValue1().verify(hostingRequest, hostingIssues);
}
if (verifier.getValue1() instanceof BuildSystemVerifier) {
hasBuildSystem |= ((BuildSystemVerifier) verifier.getValue1()).hasBuildFile(hostingRequest);
}
} catch (Exception e) {
LOGGER.error("Error running verification '" + verifier.getValue0(), e);
}
}
if (!hasBuildSystem) {
hostingIssues.add(new VerificationMessage(VerificationMessage.Severity.WARNING, "No build system found (pom.xml, build.gradle)"));
}
LOGGER.info("Done checking hosting for " + issueID + ", found " + hostingIssues.size() + " issues");
StringBuilder msg = new StringBuilder("Hello from your friendly Jenkins Hosting Checker\n\n");
LOGGER.info("Checking if there were errors");
if (!hostingIssues.isEmpty()) {
msg.append("It appears you have some issues with your hosting request. Please see the list below and " + "correct all issues marked Required. Your hosting request will not be " + "approved until these issues are corrected. Issues marked with Warning " + "or Info are just recommendations and will not stall the hosting process.\n");
LOGGER.info("Appending issues to msg");
appendIssues(msg, hostingIssues, 1);
msg.append("\nYou can re-trigger a check by editing your hosting request or by commenting `/hosting re-check`");
} else {
msg.append("It looks like you have everything in order for your hosting request. " + "A human volunteer will check over things that I am not able to check for " + "(code review, README content, etc) and process the request as quickly as possible. " + "Thank you for your patience.\n").append("\nHosting team members can host this request with `/hosting host`");
}
LOGGER.info(msg.toString());
if (!debug) {
GitHub github = GitHub.connect();
GHIssue issue = github.getRepository(HOSTING_REPO_SLUG).getIssue(issueID);
issue.comment(msg.toString());
if (hostingIssues.isEmpty()) {
issue.addLabels("hosting-request", "bot-check-complete");
issue.removeLabels("needs-fix");
} else {
issue.removeLabels("bot-check-complete");
issue.addLabels("hosting-request", "needs-fix");
}
} else {
LOGGER.info("Here are the results of the checking:");
LOGGER.info(msg.toString());
}
}
use of org.javatuples.Triplet in project hopsworks by logicalclocks.
the class ElasticFeaturestoreBuilder method setFeatureNameHighlights.
private void setFeatureNameHighlights(SearchHit hitAux, ElasticFeaturestoreDTO result, DatasetAccessController.DatasetAccessCtrl accessCtrl) throws ElasticException, GenericException {
ElasticFeaturestoreHit hit = ElasticFeaturestoreHit.instance(hitAux);
Map<String, HighlightField> highlightFields = hitAux.getHighlightFields();
String featureNameField = FeaturestoreXAttrsConstants.getFeaturestoreElasticKey(FeaturestoreXAttrsConstants.FG_FEATURES, FeaturestoreXAttrsConstants.NAME);
// <highlighted text, name, description>
Function<Triplet<String, String, String>, Boolean> matcher = (state) -> {
// check if highlighted name equals feature name
return removeHighlightTags(state.getValue0()).equals(state.getValue1());
};
BiConsumer<ElasticFeaturestoreItemDTO.Highlights, String> highlighter = ElasticFeaturestoreItemDTO.Highlights::setName;
setFeatureHighlights(highlightFields.get(featureNameField), hit, matcher, highlighter, result, accessCtrl);
}
use of org.javatuples.Triplet in project video-transcoder by brarcher.
the class MainActivity method handleEncodeIntent.
private void handleEncodeIntent(Intent intent) {
final String inputFilePath = intent.getStringExtra("inputVideoFilePath");
final String destinationFilePath = intent.getStringExtra("outputFilePath");
String mediaContainerStr = intent.getStringExtra("mediaContainer");
final MediaContainer container = MediaContainer.fromName(mediaContainerStr);
String videoCodecStr = intent.getStringExtra("videoCodec");
final VideoCodec videoCodec = VideoCodec.fromName(videoCodecStr);
int tmpCideoBitrateK = intent.getIntExtra("videoBitrateK", -1);
final Integer videoBitrateK = tmpCideoBitrateK != -1 ? tmpCideoBitrateK : null;
final String resolution = intent.getStringExtra("resolution");
final String fps = intent.getStringExtra("fps");
String audioCodecStr = intent.getStringExtra("audioCodec");
final AudioCodec audioCodec = AudioCodec.fromName(audioCodecStr);
int tmpAudioSampleRate = intent.getIntExtra("audioSampleRate", -1);
final Integer audioSampleRate = tmpAudioSampleRate != -1 ? tmpAudioSampleRate : null;
final String audioChannel = intent.getStringExtra("audioChannel");
int tmpAudioBitrateK = intent.getIntExtra("audioBitrateK", -1);
final Integer audioBitrateK = tmpAudioBitrateK != -1 ? tmpAudioBitrateK : null;
boolean skipDialog = intent.getBooleanExtra("skipDialog", false);
List<Triplet<Object, Integer, String>> nullChecks = new LinkedList<>();
nullChecks.add(new Triplet<>(inputFilePath, R.string.fieldMissingError, "inputFilePath"));
nullChecks.add(new Triplet<>(destinationFilePath, R.string.fieldMissingError, "outputFilePath"));
nullChecks.add(new Triplet<>(container, R.string.fieldMissingOrInvalidError, "mediaContainer"));
if (container != null && container.supportedVideoCodecs.size() > 0) {
nullChecks.add(new Triplet<>(videoCodec, R.string.fieldMissingOrInvalidError, "videoCodec"));
nullChecks.add(new Triplet<>(videoBitrateK, R.string.fieldMissingError, "videoBitrateK missing"));
nullChecks.add(new Triplet<>(resolution, R.string.fieldMissingError, "resolution"));
nullChecks.add(new Triplet<>(fps, R.string.fieldMissingError, "fps"));
}
if (container != null && container.supportedAudioCodecs.size() > 0) {
nullChecks.add(new Triplet<>(audioCodec, R.string.fieldMissingOrInvalidError, "audioCodec"));
nullChecks.add(new Triplet<>(audioSampleRate, R.string.fieldMissingError, "audioSampleRate"));
nullChecks.add(new Triplet<>(audioChannel, R.string.fieldMissingError, "audioChannel"));
nullChecks.add(new Triplet<>(audioBitrateK, R.string.fieldMissingError, "audioBitrateK"));
}
for (Triplet<Object, Integer, String> check : nullChecks) {
if (check.getValue0() == null) {
String submsg = String.format(getString(check.getValue1()), check.getValue2());
String message = String.format(getString(R.string.cannotEncodeFile), submsg);
Log.i(TAG, message);
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
finish();
return;
}
}
String message = String.format(getString(R.string.encodeStartConfirmation), inputFilePath, destinationFilePath);
DialogInterface.OnClickListener positiveButtonListener = new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, int which) {
FFmpegUtil.getMediaDetails(new File(inputFilePath), new ResultCallbackHandler<MediaInfo>() {
@Override
public void onResult(MediaInfo result) {
if (result != null) {
int durationSec = (int) (result.durationMs / 1000);
startEncode(inputFilePath, 0, durationSec, durationSec, container, videoCodec, videoBitrateK, resolution, fps, audioCodec, audioSampleRate, audioChannel, audioBitrateK, destinationFilePath);
} else {
String message = String.format(getString(R.string.transcodeFailed), getString(R.string.couldNotFindFileSubmsg));
Toast.makeText(MainActivity.this, message, Toast.LENGTH_LONG).show();
finish();
dialog.dismiss();
}
}
});
}
};
AlertDialog dialog = new AlertDialog.Builder(this).setMessage(message).setCancelable(false).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
dialog.dismiss();
}
}).setPositiveButton(R.string.encode, positiveButtonListener).create();
dialog.show();
if (skipDialog) {
positiveButtonListener.onClick(dialog, 0);
dialog.dismiss();
}
}
use of org.javatuples.Triplet in project ldbc_snb_datagen_spark by ldbc.
the class PersonActivityGenerator method generateWall.
/**
* Generates the personal wall for a Person. Note, only this Person creates Posts in the wall.
*
* @param person Person
*/
private GenWall<Triplet<Post, Stream<Like>, Stream<Pair<Comment, Stream<Like>>>>> generateWall(Person person, long blockId) {
// Generate wall
Forum wall = forumGenerator.createWall(randomFarm, startForumId++, person, blockId);
// Could be null as moderator can't be added
if (wall == null)
return new GenWall<>(Stream.empty());
// creates a forum membership for the moderator
// only the moderator can post on their wall
ForumMembership moderator = new ForumMembership(wall.getId(), wall.getCreationDate() + DatagenParams.delta, wall.getDeletionDate(), new PersonSummary(person), Forum.ForumType.WALL, false);
// list of members who can post on the wall - only moderator of wall can post on it
List<ForumMembership> memberships = new ArrayList<>();
memberships.add(moderator);
Stream<Triplet<Post, Stream<Like>, Stream<Pair<Comment, Stream<Like>>>>> uniform = uniformPostGenerator.createPosts(randomFarm, wall, memberships, numPostsPerGroup(randomFarm, wall, DatagenParams.maxNumPostPerMonth, DatagenParams.maxNumFriends), messageIdIterator, blockId);
Stream<Triplet<Post, Stream<Like>, Stream<Pair<Comment, Stream<Like>>>>> flashMob = flashmobPostGenerator.createPosts(randomFarm, wall, memberships, numPostsPerGroup(randomFarm, wall, DatagenParams.maxNumFlashmobPostPerMonth, DatagenParams.maxNumFriends), messageIdIterator, blockId);
return new GenWall<>(Stream.of(new Triplet<>(wall, wall.getMemberships().stream(), Stream.concat(uniform, flashMob))));
}
Aggregations