List of usage examples for org.apache.commons.lang3.tuple ImmutablePair of
public static <L, R> ImmutablePair<L, R> of(final L left, final R right)
Obtains an immutable pair of from two objects inferring the generic types.
This factory allows the pair to be created using inference to obtain the generic types.
From source file:io.dockstore.client.cli.nested.AbstractEntryClient.java
private void launchWdl(String entry, final List<String> args) { boolean isLocalEntry = false; if (args.contains("--local-entry")) { isLocalEntry = true;/* ww w .j ava 2 s . co m*/ } final String json = reqVal(args, "--json"); Main main = new Main(); File parameterFile = new File(json); final SourceFile wdlFromServer; try { // Grab WDL from server and store to file final File tempDir = Files.createTempDir(); File tmp; if (!isLocalEntry) { wdlFromServer = getDescriptorFromServer(entry, "wdl"); File tempDescriptor = File.createTempFile("temp", ".wdl", tempDir); Files.write(wdlFromServer.getContent(), tempDescriptor, StandardCharsets.UTF_8); downloadDescriptors(entry, "wdl", tempDir); tmp = resolveImportsForDescriptor(tempDir, tempDescriptor); } else { tmp = new File(entry); } // Get list of input files Bridge bridge = new Bridge(); Map<String, String> wdlInputs = bridge.getInputFiles(tmp); // Convert parameter JSON to a map WDLFileProvisioning wdlFileProvisioning = new WDLFileProvisioning(this.getConfigFile()); Gson gson = new Gson(); String jsonString = FileUtils.readFileToString(parameterFile, StandardCharsets.UTF_8); Map<String, Object> inputJson = gson.fromJson(jsonString, HashMap.class); // Download files and change to local location // Make a new map of the inputs with updated locations final String workingDir = Paths.get(".").toAbsolutePath().normalize().toString(); System.out.println("Creating directories for run of Dockstore launcher in current working directory: " + workingDir); Map<String, Object> fileMap = wdlFileProvisioning.pullFiles(inputJson, wdlInputs); // Make new json file String newJsonPath = wdlFileProvisioning.createUpdatedInputsJson(inputJson, fileMap); final List<String> wdlRun = Lists.newArrayList(tmp.getAbsolutePath(), newJsonPath); final scala.collection.immutable.List<String> wdlRunList = scala.collection.JavaConversions .asScalaBuffer(wdlRun).toList(); // run a workflow System.out.println("Calling out to Cromwell to run your workflow"); // save the output stream PrintStream savedOut = System.out; PrintStream savedErr = System.err; // capture system.out and system.err ByteArrayOutputStream stdoutCapture = new ByteArrayOutputStream(); System.setOut(new PrintStream(stdoutCapture, true, StandardCharsets.UTF_8.toString())); ByteArrayOutputStream stderrCapture = new ByteArrayOutputStream(); System.setErr(new PrintStream(stderrCapture, true, StandardCharsets.UTF_8.toString())); final int run = main.run(wdlRunList); System.out.flush(); System.err.flush(); String stdout = stdoutCapture.toString(StandardCharsets.UTF_8); String stderr = stderrCapture.toString(StandardCharsets.UTF_8); System.setOut(savedOut); System.setErr(savedErr); System.out.println("Cromwell exit code: " + run); LauncherCWL.outputIntegrationOutput(workingDir, ImmutablePair.of(stdout, stderr), stdout.replaceAll("\n", "\t"), stderr.replaceAll("\n", "\t"), "Cromwell"); // capture the output and provision it final String wdlOutputTarget = optVal(args, "--wdl-output-target", null); if (wdlOutputTarget != null) { // grab values from output JSON Map<String, String> outputJson = gson.fromJson(stdout, HashMap.class); System.out.println("Provisioning your output files to their final destinations"); final List<String> outputFiles = bridge.getOutputFiles(tmp); for (String outFile : outputFiles) { // find file path from output final File resultFile = new File(outputJson.get(outFile)); FileProvisioning.FileInfo new1 = new FileProvisioning.FileInfo(); new1.setUrl(wdlOutputTarget + "/" + resultFile.getParentFile().getName() + "/" + resultFile.getName()); new1.setLocalPath(resultFile.getAbsolutePath()); System.out.println("Uploading: " + outFile + " from " + resultFile + " to : " + new1.getUrl()); FileProvisioning fileProvisioning = new FileProvisioning(this.getConfigFile()); fileProvisioning.provisionOutputFile(new1, resultFile.getAbsolutePath()); } } else { System.out.println("Output files left in place"); } } catch (ApiException ex) { exceptionMessage(ex, "", API_ERROR); } catch (IOException ex) { exceptionMessage(ex, "", IO_ERROR); } }
From source file:cgeo.geocaching.connector.gc.GCParser.java
/** * Upload an image to a log that has already been posted * * @param logId//from www . j av a 2 s .c o m * the ID of the log to upload the image to. Found on page returned when log is uploaded * @param caption * of the image; max 50 chars * @param description * of the image; max 250 chars * @param imageUri * the URI for the image to be uploaded * @return status code to indicate success or failure */ public static ImmutablePair<StatusCode, String> uploadLogImage(final String logId, final String caption, final String description, final Uri imageUri) { final String uri = new Uri.Builder().scheme("http").authority("www.geocaching.com") .path("/seek/upload.aspx").encodedQuery("LID=" + logId).build().toString(); final String page = GCLogin.getInstance().getRequestLogged(uri, null); if (StringUtils.isBlank(page)) { Log.e("GCParser.uploadLogImage: No data from server"); return new ImmutablePair<StatusCode, String>(StatusCode.UNKNOWN_ERROR, null); } assert page != null; final String[] viewstates = GCLogin.getViewstates(page); final Parameters uploadParams = new Parameters("__EVENTTARGET", "", "__EVENTARGUMENT", "", "ctl00$ContentBody$ImageUploadControl1$uxFileCaption", caption, "ctl00$ContentBody$ImageUploadControl1$uxFileDesc", description, "ctl00$ContentBody$ImageUploadControl1$uxUpload", "Upload"); GCLogin.putViewstates(uploadParams, viewstates); final File image = new File(imageUri.getPath()); final String response = Network.getResponseData(Network.postRequest(uri, uploadParams, "ctl00$ContentBody$ImageUploadControl1$uxFileUpload", "image/jpeg", image)); final MatcherWrapper matcherUrl = new MatcherWrapper(GCConstants.PATTERN_IMAGE_UPLOAD_URL, response); if (matcherUrl.find()) { Log.i("Logimage successfully uploaded."); final String uploadedImageUrl = matcherUrl.group(1); return ImmutablePair.of(StatusCode.NO_ERROR, uploadedImageUrl); } Log.e("GCParser.uploadLogIMage: Failed to upload image because of unknown error"); return ImmutablePair.of(StatusCode.LOGIMAGE_POST_ERROR, null); }
From source file:org.apache.cxf.jaxrs.swagger.DefaultSwagger2Serializers.java
@Override public void writeTo(final Swagger data, final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, Object> headers, final OutputStream out) throws IOException { if (dynamicBasePath) { MessageContext ctx = JAXRSUtils.createContextValue(JAXRSUtils.getCurrentMessage(), null, MessageContext.class); String currentBasePath = StringUtils.substringBeforeLast(ctx.getHttpServletRequest().getRequestURI(), "/"); if (!currentBasePath.equals(beanConfig.getBasePath())) { data.setBasePath(currentBasePath); data.setHost(beanConfig.getHost()); data.setInfo(beanConfig.getInfo()); }// w w w . j a v a2 s. c om if (beanConfig.getSwagger() != null && beanConfig.getSwagger().getSecurityDefinitions() != null && data.getSecurityDefinitions() == null) { data.setSecurityDefinitions(beanConfig.getSwagger().getSecurityDefinitions()); } } if (replaceTags || javadocProvider != null) { Map<String, ClassResourceInfo> operations = new HashMap<>(); Map<Pair<String, String>, OperationResourceInfo> methods = new HashMap<>(); for (ClassResourceInfo cri : cris) { for (OperationResourceInfo ori : cri.getMethodDispatcher().getOperationResourceInfos()) { String normalizedPath = getNormalizedPath(cri.getURITemplate().getValue(), ori.getURITemplate().getValue()); operations.put(normalizedPath, cri); methods.put(ImmutablePair.of(ori.getHttpMethod(), normalizedPath), ori); } } if (replaceTags && data.getTags() != null) { data.getTags().clear(); } for (final Map.Entry<String, Path> entry : data.getPaths().entrySet()) { Tag tag = null; if (replaceTags && operations.containsKey(entry.getKey())) { ClassResourceInfo cri = operations.get(entry.getKey()); tag = new Tag(); tag.setName(cri.getURITemplate().getValue().replaceAll("/", "_")); if (javadocProvider != null) { tag.setDescription(javadocProvider.getClassDoc(cri)); } data.addTag(tag); } for (Map.Entry<HttpMethod, Operation> subentry : entry.getValue().getOperationMap().entrySet()) { if (replaceTags && tag != null) { subentry.getValue().setTags(Collections.singletonList(tag.getName())); } Pair<String, String> key = ImmutablePair.of(subentry.getKey().name(), entry.getKey()); if (methods.containsKey(key) && javadocProvider != null) { OperationResourceInfo ori = methods.get(key); subentry.getValue().setSummary(javadocProvider.getMethodDoc(ori)); for (int i = 0; i < subentry.getValue().getParameters().size(); i++) { subentry.getValue().getParameters().get(i) .setDescription(javadocProvider.getMethodParameterDoc(ori, i)); } addParameters(subentry.getValue().getParameters()); if (subentry.getValue().getResponses() != null && !subentry.getValue().getResponses().isEmpty()) { subentry.getValue().getResponses().entrySet().iterator().next().getValue() .setDescription(javadocProvider.getMethodResponseDoc(ori)); } } } } } if (replaceTags && data.getTags() != null) { Collections.sort(data.getTags(), new Comparator<Tag>() { @Override public int compare(final Tag tag1, final Tag tag2) { return tag1.getName().compareTo(tag2.getName()); } }); } super.writeTo(data, type, genericType, annotations, mediaType, headers, out); }
From source file:org.apache.cxf.jaxrs.swagger.Swagger2Customizer.java
public Swagger customize(Swagger data) { if (dynamicBasePath) { MessageContext ctx = createMessageContext(); String currentBasePath = StringUtils.substringBeforeLast(ctx.getHttpServletRequest().getRequestURI(), "/"); if (!currentBasePath.equals(beanConfig.getBasePath())) { data.setBasePath(currentBasePath); data.setHost(beanConfig.getHost()); data.setInfo(beanConfig.getInfo()); }//from w ww .j a v a 2 s . c o m if (beanConfig.getSwagger() != null && beanConfig.getSwagger().getSecurityDefinitions() != null && data.getSecurityDefinitions() == null) { data.setSecurityDefinitions(beanConfig.getSwagger().getSecurityDefinitions()); } } if (replaceTags || javadocProvider != null) { Map<String, ClassResourceInfo> operations = new HashMap<>(); Map<Pair<String, String>, OperationResourceInfo> methods = new HashMap<>(); for (ClassResourceInfo cri : cris) { for (OperationResourceInfo ori : cri.getMethodDispatcher().getOperationResourceInfos()) { String normalizedPath = getNormalizedPath(cri.getURITemplate().getValue(), ori.getURITemplate().getValue()); operations.put(normalizedPath, cri); methods.put(ImmutablePair.of(ori.getHttpMethod(), normalizedPath), ori); } } if (replaceTags && data.getTags() != null) { data.getTags().clear(); } for (final Map.Entry<String, Path> entry : data.getPaths().entrySet()) { Tag tag = null; if (replaceTags && operations.containsKey(entry.getKey())) { ClassResourceInfo cri = operations.get(entry.getKey()); tag = new Tag(); tag.setName(cri.getURITemplate().getValue().replaceAll("/", "_")); if (javadocProvider != null) { tag.setDescription(javadocProvider.getClassDoc(cri)); } data.addTag(tag); } for (Map.Entry<HttpMethod, Operation> subentry : entry.getValue().getOperationMap().entrySet()) { if (replaceTags && tag != null) { subentry.getValue().setTags(Collections.singletonList(tag.getName())); } Pair<String, String> key = ImmutablePair.of(subentry.getKey().name(), entry.getKey()); if (methods.containsKey(key) && javadocProvider != null) { OperationResourceInfo ori = methods.get(key); subentry.getValue().setSummary(javadocProvider.getMethodDoc(ori)); for (int i = 0; i < subentry.getValue().getParameters().size(); i++) { subentry.getValue().getParameters().get(i) .setDescription(javadocProvider.getMethodParameterDoc(ori, i)); } addParameters(subentry.getValue().getParameters()); if (subentry.getValue().getResponses() != null && !subentry.getValue().getResponses().isEmpty()) { subentry.getValue().getResponses().entrySet().iterator().next().getValue() .setDescription(javadocProvider.getMethodResponseDoc(ori)); } } } } } if (replaceTags && data.getTags() != null) { Collections.sort(data.getTags(), new Comparator<Tag>() { @Override public int compare(final Tag tag1, final Tag tag2) { return tag1.getName().compareTo(tag2.getName()); } }); } applyDefaultVersion(data); return data; }
From source file:org.apache.cxf.jaxrs.swagger.Swagger2Serializers.java
@Override public void writeTo(final Swagger data, final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, Object> headers, final OutputStream out) throws IOException { if (dynamicBasePath) { MessageContext ctx = JAXRSUtils.createContextValue(JAXRSUtils.getCurrentMessage(), null, MessageContext.class); data.setBasePath(StringUtils.substringBeforeLast(ctx.getHttpServletRequest().getRequestURI(), "/")); }// w w w . j av a 2s .co m if (replaceTags || javadocProvider != null) { Map<String, ClassResourceInfo> operations = new HashMap<>(); Map<Pair<String, String>, OperationResourceInfo> methods = new HashMap<>(); for (ClassResourceInfo cri : cris) { for (OperationResourceInfo ori : cri.getMethodDispatcher().getOperationResourceInfos()) { String normalizedPath = getNormalizedPath(cri.getURITemplate().getValue(), ori.getURITemplate().getValue()); operations.put(normalizedPath, cri); methods.put(ImmutablePair.of(ori.getHttpMethod(), normalizedPath), ori); } } if (replaceTags && data.getTags() != null) { data.getTags().clear(); } for (final Map.Entry<String, Path> entry : data.getPaths().entrySet()) { Tag tag = null; if (replaceTags && operations.containsKey(entry.getKey())) { ClassResourceInfo cri = operations.get(entry.getKey()); tag = new Tag(); tag.setName(cri.getURITemplate().getValue()); if (javadocProvider != null) { tag.setDescription(javadocProvider.getClassDoc(cri)); } data.addTag(tag); } for (Map.Entry<HttpMethod, Operation> subentry : entry.getValue().getOperationMap().entrySet()) { if (replaceTags && tag != null) { subentry.getValue().setTags(Collections.singletonList(tag.getName())); } Pair<String, String> key = ImmutablePair.of(subentry.getKey().name(), entry.getKey()); if (methods.containsKey(key) && javadocProvider != null) { OperationResourceInfo ori = methods.get(key); subentry.getValue().setSummary(javadocProvider.getMethodDoc(ori)); for (int i = 0; i < subentry.getValue().getParameters().size(); i++) { subentry.getValue().getParameters().get(i) .setDescription(javadocProvider.getMethodParameterDoc(ori, i)); } if (subentry.getValue().getResponses() != null && !subentry.getValue().getResponses().isEmpty()) { subentry.getValue().getResponses().entrySet().iterator().next().getValue() .setDescription(javadocProvider.getMethodResponseDoc(ori)); } } } } } super.writeTo(data, type, genericType, annotations, mediaType, headers, out); }
From source file:org.apache.gobblin.data.management.conversion.hive.task.HiveConverterUtils.java
/** * Returns a pair of Hive table and its partitions * @param dbName db name//w ww . ja va2 s. c o m * @param tableName table name * @param props properties * @return a pair of Hive table and its partitions * @throws DataConversionException */ public static Pair<Optional<Table>, Optional<List<Partition>>> getDestinationTableMeta(String dbName, String tableName, Properties props) { Optional<Table> table = Optional.<Table>absent(); Optional<List<Partition>> partitions = Optional.<List<Partition>>absent(); try { HiveMetastoreClientPool pool = HiveMetastoreClientPool.get(props, Optional.fromNullable(props.getProperty(HiveDatasetFinder.HIVE_METASTORE_URI_KEY))); try (AutoReturnableObject<IMetaStoreClient> client = pool.getClient()) { table = Optional.of(client.get().getTable(dbName, tableName)); if (table.isPresent()) { org.apache.hadoop.hive.ql.metadata.Table qlTable = new org.apache.hadoop.hive.ql.metadata.Table( table.get()); if (HiveUtils.isPartitioned(qlTable)) { partitions = Optional .of(HiveUtils.getPartitions(client.get(), qlTable, Optional.<String>absent())); } } } } catch (NoSuchObjectException e) { return ImmutablePair.of(table, partitions); } catch (IOException | TException e) { throw new RuntimeException("Could not fetch destination table metadata", e); } return ImmutablePair.of(table, partitions); }
From source file:org.apache.gobblin.service.modules.template.StaticFlowTemplate.java
/** * Generate the input/output dataset descriptors for the {@link FlowTemplate}. * @param userConfig//from w w w . j a v a 2 s . c o m * @return a List of Input/Output DatasetDescriptors that resolve this {@link FlowTemplate}. */ @Override public List<Pair<DatasetDescriptor, DatasetDescriptor>> getResolvingDatasetDescriptors(Config userConfig) throws IOException, SpecNotFoundException, JobTemplate.TemplateException { Config config = this.getResolvedFlowConfig(userConfig) .resolve(ConfigResolveOptions.defaults().setAllowUnresolved(true)); if (!config.hasPath(DatasetDescriptorConfigKeys.FLOW_EDGE_INPUT_DATASET_DESCRIPTOR_PREFIX) || !config.hasPath(DatasetDescriptorConfigKeys.FLOW_EDGE_OUTPUT_DATASET_DESCRIPTOR_PREFIX)) { throw new IOException("Flow template must specify at least one input/output dataset descriptor"); } int i = 0; String inputPrefix = Joiner.on(".") .join(DatasetDescriptorConfigKeys.FLOW_EDGE_INPUT_DATASET_DESCRIPTOR_PREFIX, Integer.toString(i)); List<Pair<DatasetDescriptor, DatasetDescriptor>> result = Lists.newArrayList(); while (config.hasPath(inputPrefix)) { try { Config inputDescriptorConfig = config.getConfig(inputPrefix); DatasetDescriptor inputDescriptor = getDatasetDescriptor(inputDescriptorConfig); String outputPrefix = Joiner.on(".").join( DatasetDescriptorConfigKeys.FLOW_EDGE_OUTPUT_DATASET_DESCRIPTOR_PREFIX, Integer.toString(i)); Config outputDescriptorConfig = config.getConfig(outputPrefix); DatasetDescriptor outputDescriptor = getDatasetDescriptor(outputDescriptorConfig); if (isResolvable(userConfig, inputDescriptor, outputDescriptor)) { result.add(ImmutablePair.of(inputDescriptor, outputDescriptor)); } } catch (ReflectiveOperationException e) { //Cannot instantiate I/O dataset descriptor due to missing config; skip and try the next one. } inputPrefix = Joiner.on(".").join(DatasetDescriptorConfigKeys.FLOW_EDGE_INPUT_DATASET_DESCRIPTOR_PREFIX, Integer.toString(++i)); } return result; }
From source file:org.apache.hadoop.hive.ql.QOutProcessor.java
private Pair<Pattern, String> toPatternPair(String patternStr, String maskComment) { return ImmutablePair.of(Pattern.compile(patternStr), maskComment); }
From source file:org.apache.pulsar.client.impl.RawBatchConverter.java
public static List<ImmutablePair<MessageId, String>> extractIdsAndKeys(RawMessage msg) throws IOException { checkArgument(msg.getMessageIdData().getBatchIndex() == -1); ByteBuf payload = msg.getHeadersAndPayload(); MessageMetadata metadata = Commands.parseMessageMetadata(payload); int batchSize = metadata.getNumMessagesInBatch(); CompressionType compressionType = metadata.getCompression(); CompressionCodec codec = CompressionCodecProvider.getCompressionCodec(compressionType); int uncompressedSize = metadata.getUncompressedSize(); ByteBuf uncompressedPayload = codec.decode(payload, uncompressedSize); metadata.recycle();// ww w . ja va2s. c om List<ImmutablePair<MessageId, String>> idsAndKeys = new ArrayList<>(); for (int i = 0; i < batchSize; i++) { SingleMessageMetadata.Builder singleMessageMetadataBuilder = SingleMessageMetadata.newBuilder(); ByteBuf singleMessagePayload = Commands.deSerializeSingleMessageInBatch(uncompressedPayload, singleMessageMetadataBuilder, 0, batchSize); MessageId id = new BatchMessageIdImpl(msg.getMessageIdData().getLedgerId(), msg.getMessageIdData().getEntryId(), msg.getMessageIdData().getPartition(), i); if (!singleMessageMetadataBuilder.getCompactedOut()) { idsAndKeys.add(ImmutablePair.of(id, singleMessageMetadataBuilder.getPartitionKey())); } singleMessageMetadataBuilder.recycle(); singleMessagePayload.release(); } uncompressedPayload.release(); return idsAndKeys; }
From source file:org.apache.pulsar.functions.worker.SchedulerManager.java
private Pair<List<Function.Instance>, List<Assignment>> getUnassignedFunctionInstances( Map<String, Map<String, Assignment>> currentAssignments, Map<String, Function.Instance> functionInstances) { List<Function.Instance> unassignedFunctionInstances = new LinkedList<>(); List<Assignment> heartBeatAssignments = Lists.newArrayList(); Map<String, Assignment> assignmentMap = new HashMap<>(); for (Map<String, Assignment> entry : currentAssignments.values()) { assignmentMap.putAll(entry);/*from w w w .j a v a 2 s . c o m*/ } for (Map.Entry<String, Function.Instance> instanceEntry : functionInstances.entrySet()) { String fullyQualifiedInstanceId = instanceEntry.getKey(); Function.Instance instance = instanceEntry.getValue(); String heartBeatWorkerId = checkHeartBeatFunction(instance); if (heartBeatWorkerId != null) { heartBeatAssignments .add(Assignment.newBuilder().setInstance(instance).setWorkerId(heartBeatWorkerId).build()); continue; } if (!assignmentMap.containsKey(fullyQualifiedInstanceId)) { unassignedFunctionInstances.add(instance); } } return ImmutablePair.of(unassignedFunctionInstances, heartBeatAssignments); }