Search in sources :

Example 1 with Triplet

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);
    }
}
Also used : Arrays(java.util.Arrays) GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) LoggerFactory(org.slf4j.LoggerFactory) ConcurrentSet(io.netty.util.internal.ConcurrentSet) Triplet(org.javatuples.Triplet) Map(java.util.Map) ThreadingModel(net.dempsy.threading.ThreadingModel) MessageKey(net.dempsy.lifecycle.annotation.MessageKey) MessageHandler(net.dempsy.lifecycle.annotation.MessageHandler) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Activation(net.dempsy.lifecycle.annotation.Activation) KeyExtractor(net.dempsy.lifecycle.annotation.utils.KeyExtractor) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Pair(org.javatuples.Pair) Serializable(java.io.Serializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) Output(net.dempsy.lifecycle.annotation.Output) CountDownLatch(java.util.concurrent.CountDownLatch) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) Adaptor(net.dempsy.messages.Adaptor) ConditionPoll.assertTrue(net.dempsy.utils.test.ConditionPoll.assertTrue) Optional(java.util.Optional) MessageProcessor(net.dempsy.lifecycle.annotation.MessageProcessor) Mp(net.dempsy.lifecycle.annotation.Mp) MessageType(net.dempsy.lifecycle.annotation.MessageType) Dispatcher(net.dempsy.messages.Dispatcher) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Tuple(org.javatuples.Tuple) ClusterId(net.dempsy.config.ClusterId) Before(org.junit.Before) Logger(org.slf4j.Logger) Assert.assertNotNull(org.junit.Assert.assertNotNull) NodeMetricGetters(net.dempsy.container.NodeMetricGetters) StringWriter(java.io.StringWriter) ClusterMetricGetters(net.dempsy.container.ClusterMetricGetters) SystemPropertyManager(net.dempsy.util.SystemPropertyManager) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Passivation(net.dempsy.lifecycle.annotation.Passivation) ConditionPoll.poll(net.dempsy.utils.test.ConditionPoll.poll) MessageProcessorLifecycle(net.dempsy.messages.MessageProcessorLifecycle) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) InputStream(java.io.InputStream) ClusterId(net.dempsy.config.ClusterId) Triplet(org.javatuples.Triplet) NodeMetricGetters(net.dempsy.container.NodeMetricGetters) CountDownLatch(java.util.concurrent.CountDownLatch) SystemPropertyManager(net.dempsy.util.SystemPropertyManager) Test(org.junit.Test)

Example 2 with Triplet

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());
    }
}
Also used : Triplet(org.javatuples.Triplet) GitHub(org.kohsuke.github.GitHub) ArrayList(java.util.ArrayList) GHIssue(org.kohsuke.github.GHIssue) IOException(java.io.IOException) GHFileNotFoundException(org.kohsuke.github.GHFileNotFoundException) HashSet(java.util.HashSet)

Example 3 with Triplet

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);
}
Also used : HopsworksJAXBContext(io.hops.hopsworks.common.util.HopsworksJAXBContext) ProjectFacade(io.hops.hopsworks.common.dao.project.ProjectFacade) FeaturestoreXAttrsConstants(io.hops.hopsworks.common.featurestore.xattr.dto.FeaturestoreXAttrsConstants) Function(java.util.function.Function) Project(io.hops.hopsworks.persistence.entity.project.Project) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Inject(javax.inject.Inject) TransactionAttributeType(javax.ejb.TransactionAttributeType) Triplet(org.javatuples.Triplet) Text(org.elasticsearch.common.text.Text) TransactionAttribute(javax.ejb.TransactionAttribute) Map(java.util.Map) ElasticException(io.hops.hopsworks.exceptions.ElasticException) SearchResponse(org.elasticsearch.action.search.SearchResponse) HighlightField(org.elasticsearch.search.fetch.subphase.highlight.HighlightField) BiConsumer(java.util.function.BiConsumer) EJB(javax.ejb.EJB) SearchHit(org.elasticsearch.search.SearchHit) Stateless(javax.ejb.Stateless) Set(java.util.Set) ElasticController(io.hops.hopsworks.common.elastic.ElasticController) RESTCodes(io.hops.hopsworks.restutils.RESTCodes) ServiceException(io.hops.hopsworks.exceptions.ServiceException) ElasticFeaturestoreHit(io.hops.hopsworks.common.elastic.ElasticFeaturestoreHit) GenericException(io.hops.hopsworks.exceptions.GenericException) FeaturestoreDocType(io.hops.hopsworks.common.elastic.FeaturestoreDocType) Users(io.hops.hopsworks.persistence.entity.user.Users) ElasticFeaturestoreHit(io.hops.hopsworks.common.elastic.ElasticFeaturestoreHit) Triplet(org.javatuples.Triplet) HighlightField(org.elasticsearch.search.fetch.subphase.highlight.HighlightField)

Example 4 with Triplet

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();
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) Triplet(org.javatuples.Triplet) VideoCodec(protect.videotranscoder.media.VideoCodec) LinkedList(java.util.LinkedList) MediaInfo(protect.videotranscoder.media.MediaInfo) MediaContainer(protect.videotranscoder.media.MediaContainer) File(java.io.File) AudioCodec(protect.videotranscoder.media.AudioCodec)

Example 5 with Triplet

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))));
}
Also used : Like(ldbc.snb.datagen.entities.dynamic.relations.Like) ForumMembership(ldbc.snb.datagen.entities.dynamic.relations.ForumMembership) Triplet(org.javatuples.Triplet) ArrayList(java.util.ArrayList) PersonSummary(ldbc.snb.datagen.entities.dynamic.person.PersonSummary) Forum(ldbc.snb.datagen.entities.dynamic.Forum) Pair(org.javatuples.Pair)

Aggregations

Triplet (org.javatuples.Triplet)7 ArrayList (java.util.ArrayList)5 Map (java.util.Map)3 Set (java.util.Set)3 Function (java.util.function.Function)3 ProjectFacade (io.hops.hopsworks.common.dao.project.ProjectFacade)2 ElasticController (io.hops.hopsworks.common.elastic.ElasticController)2 ElasticFeaturestoreHit (io.hops.hopsworks.common.elastic.ElasticFeaturestoreHit)2 FeaturestoreDocType (io.hops.hopsworks.common.elastic.FeaturestoreDocType)2 FeaturestoreXAttrsConstants (io.hops.hopsworks.common.featurestore.xattr.dto.FeaturestoreXAttrsConstants)2 HopsworksJAXBContext (io.hops.hopsworks.common.util.HopsworksJAXBContext)2 ElasticException (io.hops.hopsworks.exceptions.ElasticException)2 GenericException (io.hops.hopsworks.exceptions.GenericException)2 ServiceException (io.hops.hopsworks.exceptions.ServiceException)2 Project (io.hops.hopsworks.persistence.entity.project.Project)2 Users (io.hops.hopsworks.persistence.entity.user.Users)2 RESTCodes (io.hops.hopsworks.restutils.RESTCodes)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 BiConsumer (java.util.function.BiConsumer)2