Search in sources :

Example 6 with PRIVATE

use of lombok.AccessLevel.PRIVATE in project SONG by overture-stack.

the class Benchmark method saveForStudy.

@SneakyThrows
private void saveForStudy(String studyId, Registry registry, List<UploadData> uploadDataList) {
    val modList = uploadDataList.stream().filter(x -> !x.getUploadState().equals("VALIDATION_ERROR")).collect(toList());
    val total = modList.size();
    val errored = uploadDataList.size() - total;
    log.warn("Num Errored Files: {}", errored);
    int count = 0;
    val saveMonitor = monitor.getStudyMonitor(studyId).getSaveMonitor();
    for (val uploadData : modList) {
        val submittedAnalysisId = uploadData.getAnalysisId();
        val idExists = doesIdExist(uploadData.getStudyId(), registry, submittedAnalysisId);
        log.info("ANALYSIS_ID {} existence: {}", submittedAnalysisId, idExists);
        val rawResponse = saveMonitor.callIncr(() -> registry.save(uploadData.getStudyId(), uploadData.getUploadId(), benchmarkConfig.isIgnoreIdCollisions()));
        val response = readTree(rawResponse.getOutputs());
        val status = response.path("status").textValue();
        val analysisId = response.path("analysisId").textValue();
        uploadData.setAnalysisId(analysisId);
        log.info("Saving {} file {} /{} : {}", uploadData.getStudyId(), ++count, total, uploadData.getFile().getFileName().toString());
    }
}
Also used : lombok.val(lombok.val) RestClient(org.icgc.dcc.song.client.register.RestClient) SneakyThrows(lombok.SneakyThrows) StudyClient.createStudyClient(org.icgc.dcc.song.client.benchmark.rest.StudyClient.createStudyClient) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Registry(org.icgc.dcc.song.client.register.Registry) UploadData(org.icgc.dcc.song.client.benchmark.model.UploadData) Lists(com.google.common.collect.Lists) JsonUtils.readTree(org.icgc.dcc.song.core.utils.JsonUtils.readTree) Thread.sleep(java.lang.Thread.sleep) Path(java.nio.file.Path) BenchmarkMonitor(org.icgc.dcc.song.client.benchmark.monitor.BenchmarkMonitor) Files(java.nio.file.Files) NonNull(lombok.NonNull) lombok.val(lombok.val) CounterMonitor(org.icgc.dcc.song.client.benchmark.monitor.CounterMonitor) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) BenchmarkMonitor.createBenchmarkMonitor(org.icgc.dcc.song.client.benchmark.monitor.BenchmarkMonitor.createBenchmarkMonitor) JsonUtils(org.icgc.dcc.song.core.utils.JsonUtils) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Paths(java.nio.file.Paths) StudyMonitor(org.icgc.dcc.song.client.benchmark.monitor.StudyMonitor) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Config(org.icgc.dcc.song.client.config.Config) PRIVATE(lombok.AccessLevel.PRIVATE) SneakyThrows(lombok.SneakyThrows)

Example 7 with PRIVATE

use of lombok.AccessLevel.PRIVATE in project component-runtime by Talend.

the class Generator method generatedJira.

private static void generatedJira(final File generatedDir, final String username, final String password, final String version) {
    if (username == null || username.trim().isEmpty() || "skip".equals(username)) {
        log.error("No JIRA credentials, will skip changelog generation");
        return;
    }
    final String project = "TCOMP";
    final String jiraBase = "https://jira.talendforge.org";
    final File file = new File(generatedDir, "generated_changelog.adoc");
    final Client client = ClientBuilder.newClient().register(new JsonbJaxrsProvider<>());
    final String auth = "Basic " + Base64.getEncoder().encodeToString((username + ':' + password).getBytes(StandardCharsets.UTF_8));
    try {
        final WebTarget restApi = client.target(jiraBase + "/rest/api/2").property("http.connection.timeout", 60000L);
        final List<JiraVersion> versions = restApi.path("project/{project}/versions").resolveTemplate("project", project).request(APPLICATION_JSON_TYPE).header("Authorization", auth).get(new GenericType<List<JiraVersion>>() {
        });
        final String currentVersion = version.replace("-SNAPSHOT", "");
        final List<JiraVersion> loggedVersions = versions.stream().filter(v -> (v.isReleased() || jiraVersionMatches(currentVersion, v.getName()))).collect(toList());
        if (loggedVersions.isEmpty()) {
            try (final PrintStream stream = new PrintStream(new WriteIfDifferentStream(file))) {
                stream.println("No version found.");
            }
            return;
        }
        final String jql = "project=" + project + " AND labels=\"changelog\"" + loggedVersions.stream().map(v -> "fixVersion=" + v.getName()).collect(joining(" OR ", " AND (", ")"));
        final Function<Long, JiraIssues> searchFrom = startAt -> restApi.path("search").queryParam("jql", jql).queryParam("startAt", startAt).request(APPLICATION_JSON_TYPE).header("Authorization", auth).get(JiraIssues.class);
        final Function<JiraIssues, Stream<JiraIssues>> paginate = new Function<JiraIssues, Stream<JiraIssues>>() {

            @Override
            public Stream<JiraIssues> apply(final JiraIssues issues) {
                final long nextStartAt = issues.getStartAt() + issues.getMaxResults();
                final Stream<JiraIssues> fetched = Stream.of(issues);
                return issues.getTotal() > nextStartAt ? Stream.concat(fetched, apply(searchFrom.apply(nextStartAt))) : fetched;
            }
        };
        final Set<String> includeStatus = Stream.of("closed", "resolved", "development done", "qa done", "done").collect(toSet());
        final Map<String, TreeMap<String, List<JiraIssue>>> issues = Stream.of(searchFrom.apply(0L)).flatMap(paginate).flatMap(i -> ofNullable(i.getIssues()).map(Collection::stream).orElseGet(Stream::empty)).filter(issue -> includeStatus.contains(issue.getFields().getStatus().getName().toLowerCase(ENGLISH))).flatMap(i -> i.getFields().getFixVersions().stream().map(v -> Pair.of(v, i))).collect(groupingBy(pair -> pair.getKey().getName(), () -> new TreeMap<>(versionComparator()), groupingBy(pair -> pair.getValue().getFields().getIssuetype().getName(), TreeMap::new, collectingAndThen(mapping(Pair::getValue, toList()), l -> {
            l.sort(comparing(JiraIssue::getKey));
            return l;
        }))));
        final String changelog = issues.entrySet().stream().map(versionnedIssues -> new StringBuilder("\n\n== Version ").append(versionnedIssues.getKey()).append(versionnedIssues.getValue().entrySet().stream().collect((Supplier<StringBuilder>) StringBuilder::new, (builder, issuesByType) -> builder.append("\n\n=== ").append(issuesByType.getKey()).append("\n\n").append(issuesByType.getValue().stream().collect((Supplier<StringBuilder>) StringBuilder::new, // useful
        (a, i) -> a.append("- link:").append(jiraBase).append("/browse/").append(i.getKey()).append("[").append(i.getKey()).append("^]").append(": ").append(i.getFields().getSummary()).append("\n"), StringBuilder::append)), StringBuilder::append))).collect(StringBuilder::new, StringBuilder::append, StringBuilder::append).toString();
        try (final PrintStream stream = new PrintStream(new WriteIfDifferentStream(file))) {
            stream.println(changelog);
        }
    } finally {
        client.close();
    }
}
Also used : Condition(org.talend.sdk.component.api.configuration.condition.meta.Condition) RequiredArgsConstructor(lombok.RequiredArgsConstructor) AnnotationFinder(org.apache.xbean.finder.AnnotationFinder) ConfigurationTypeParameterEnricher(org.talend.sdk.component.runtime.manager.reflect.parameterenricher.ConfigurationTypeParameterEnricher) Type(org.talend.sdk.component.api.service.schema.Type) Collectors.toMap(java.util.stream.Collectors.toMap) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) Defaults(org.talend.sdk.component.runtime.reflect.Defaults) ENGLISH(java.util.Locale.ENGLISH) UiParameterEnricher(org.talend.sdk.component.runtime.manager.reflect.parameterenricher.UiParameterEnricher) Collectors.toSet(java.util.stream.Collectors.toSet) Validations(org.talend.sdk.component.api.configuration.constraint.meta.Validations) JsonbBuilder(javax.json.bind.JsonbBuilder) ActiveIf(org.talend.sdk.component.api.configuration.condition.ActiveIf) Collection(java.util.Collection) Ui(org.talend.sdk.component.api.configuration.ui.meta.Ui) Mapper(org.apache.johnzon.mapper.Mapper) Set(java.util.Set) FilterOutputStream(java.io.FilterOutputStream) PropertyOrderStrategy(javax.json.bind.config.PropertyOrderStrategy) Collectors.joining(java.util.stream.Collectors.joining) StandardCharsets(java.nio.charset.StandardCharsets) InvocationTargetException(java.lang.reflect.InvocationTargetException) GenericType(javax.ws.rs.core.GenericType) Base64(java.util.Base64) List(java.util.List) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) Documentation(org.talend.sdk.component.api.meta.Documentation) Modifier(java.lang.reflect.Modifier) Annotation(java.lang.annotation.Annotation) Configuration(org.apache.deltaspike.core.api.config.Configuration) PRIVATE(lombok.AccessLevel.PRIVATE) MapperBuilder(org.apache.johnzon.mapper.MapperBuilder) Proxy(java.lang.reflect.Proxy) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) Client(javax.ws.rs.client.Client) Collectors.collectingAndThen(java.util.stream.Collectors.collectingAndThen) Function(java.util.function.Function) Supplier(java.util.function.Supplier) JsonbConfig(javax.json.bind.JsonbConfig) AutoLayout(org.talend.sdk.component.api.configuration.ui.layout.AutoLayout) Schema(org.talend.sdk.component.api.service.schema.Schema) ValidationParameterEnricher(org.talend.sdk.component.runtime.manager.reflect.parameterenricher.ValidationParameterEnricher) ConfigProperty(org.apache.deltaspike.core.api.config.ConfigProperty) FileArchive(org.apache.xbean.finder.archive.FileArchive) ArrayList(java.util.ArrayList) ClientBuilder(javax.ws.rs.client.ClientBuilder) ComponentServerConfiguration(org.talend.sdk.component.server.configuration.ComponentServerConfiguration) Collectors.mapping(java.util.stream.Collectors.mapping) Validation(org.talend.sdk.component.api.configuration.constraint.meta.Validation) ConfigurationType(org.talend.sdk.component.api.configuration.type.meta.ConfigurationType) GridLayout(org.talend.sdk.component.api.configuration.ui.layout.GridLayout) Comparator.comparing(java.util.Comparator.comparing) JsonbJaxrsProvider(org.apache.johnzon.jaxrs.jsonb.jaxrs.JsonbJaxrsProvider) ValidationResult(org.talend.sdk.component.api.service.asyncvalidation.ValidationResult) ConditionParameterEnricher(org.talend.sdk.component.runtime.manager.reflect.parameterenricher.ConditionParameterEnricher) OutputStream(java.io.OutputStream) PrintStream(java.io.PrintStream) BaseEnvironmentProvider(org.talend.sdk.component.junit.environment.BaseEnvironmentProvider) ParameterExtensionEnricher(org.talend.sdk.component.spi.parameter.ParameterExtensionEnricher) MalformedURLException(java.net.MalformedURLException) Files(java.nio.file.Files) JarArchive(org.apache.xbean.finder.archive.JarArchive) Values(org.talend.sdk.component.api.service.completion.Values) Optional.ofNullable(java.util.Optional.ofNullable) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) Collectors.toList(java.util.stream.Collectors.toList) TreeMap(java.util.TreeMap) HealthCheckStatus(org.talend.sdk.component.api.service.healthcheck.HealthCheckStatus) JarLocation.jarLocation(org.apache.ziplock.JarLocation.jarLocation) Data(lombok.Data) APPLICATION_JSON_TYPE(javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE) Jsonb(javax.json.bind.Jsonb) WebTarget(javax.ws.rs.client.WebTarget) Comparator(java.util.Comparator) ActionType(org.talend.sdk.component.api.service.ActionType) NoArgsConstructor(lombok.NoArgsConstructor) Function(java.util.function.Function) List(java.util.List) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) FilterOutputStream(java.io.FilterOutputStream) Stream(java.util.stream.Stream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) PrintStream(java.io.PrintStream) FileOutputStream(java.io.FileOutputStream) Client(javax.ws.rs.client.Client) Pair(org.apache.commons.lang3.tuple.Pair) PrintStream(java.io.PrintStream) TreeMap(java.util.TreeMap) WebTarget(javax.ws.rs.client.WebTarget) File(java.io.File)

Aggregations

List (java.util.List)7 PRIVATE (lombok.AccessLevel.PRIVATE)7 File (java.io.File)6 MalformedURLException (java.net.MalformedURLException)6 Files (java.nio.file.Files)6 ArrayList (java.util.ArrayList)6 Collectors.toList (java.util.stream.Collectors.toList)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 FileOutputStream (java.io.FileOutputStream)5 FilterOutputStream (java.io.FilterOutputStream)5 IOException (java.io.IOException)5 OutputStream (java.io.OutputStream)5 PrintStream (java.io.PrintStream)5 Annotation (java.lang.annotation.Annotation)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 Modifier (java.lang.reflect.Modifier)5 Proxy (java.lang.reflect.Proxy)5 StandardCharsets (java.nio.charset.StandardCharsets)5 Base64 (java.util.Base64)5 Collection (java.util.Collection)5