@Override public void process(Exchange exchange) throws Exception { final INDArray arr = (INDArray) exchange.getIn().getBody(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bos); Nd4j.write(arr, dos); byte[] bytes = bos.toByteArray(); String base64 = Base64.encodeBase64String(bytes); exchange.getIn().setBody(base64, String.class); String id = UUID.randomUUID().toString(); exchange.getIn().setHeader(KafkaConstants.KEY, id); exchange.getIn().setHeader(KafkaConstants.PARTITION_KEY, id); } }).to(kafkaUri);
public static Object assertMessageHeader(Message message, String name, Object expected) { Object value = message.getHeader(name); assertEquals("Header: " + name + " on Message: " + message, expected, value); return value; }
Session session = Session.getInstance(props, null); Message msg = new MimeMessage(session); msg.setFrom(new InternetAddress("mail@tovare.com"));; msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("tov.are.jacobsen@iss.no", false)); msg.setSubject("Heisann "+System.currentTimeMillis()); msg.setText("Med vennlig hilsennTov Are Jacobsen"); msg.setHeader("X-Mailer", "Tov Are's program"); msg.setSentDate(new Date()); SMTPTransport t = (SMTPTransport)session.getTransport("smtps"); t.connect("smtp.gmail.com", "admin@tovare.com", "<insert password here>"); t.sendMessage(msg, msg.getAllRecipients()); System.out.println("Response: " + t.getLastServerResponse()); t.close();
private void restoreDroplet(Exchange exchange) throws Exception { if (ObjectHelper.isEmpty(exchange.getIn().getHeader(DigitalOceanHeaders.IMAGE_ID))) { throw new IllegalArgumentException(DigitalOceanHeaders.IMAGE_ID + " must be specified"); } Action action = getEndpoint().getDigitalOceanClient().restoreDroplet(dropletId, exchange.getIn().getHeader(DigitalOceanHeaders.IMAGE_ID, Integer.class)); LOG.trace("DropletAction Restore [{}] ", action); exchange.getOut().setBody(action); }
protected void doGetHPA(Exchange exchange, String operation) throws Exception { HorizontalPodAutoscaler hpa = null; String podName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_HPA_NAME, String.class); String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); if (ObjectHelper.isEmpty(podName)) { LOG.error("Get a specific hpa require specify an hpa name"); throw new IllegalArgumentException("Get a specific hpa require specify an hpa name"); } if (ObjectHelper.isEmpty(namespaceName)) { LOG.error("Get a specific hpa require specify a namespace name"); throw new IllegalArgumentException("Get a specific hpa require specify a namespace name"); } hpa = getEndpoint().getKubernetesClient().autoscaling().horizontalPodAutoscalers().inNamespace(namespaceName).withName(podName).get(); MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); exchange.getOut().setBody(hpa); }
protected void doDeleteConfigMap(Exchange exchange, String operation) throws Exception { String configMapName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_CONFIGMAP_NAME, String.class); String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); if (ObjectHelper.isEmpty(configMapName)) { LOG.error("Delete a specific config map require specify a config map name"); throw new IllegalArgumentException("Delete a specific config map require specify a config map name"); } if (ObjectHelper.isEmpty(namespaceName)) { LOG.error("Delete a specific config map require specify a namespace name"); throw new IllegalArgumentException("Delete a specific config map require specify a namespace name"); } boolean cfMapDeleted = getEndpoint().getKubernetesClient().configMaps().inNamespace(namespaceName).withName(configMapName).delete(); MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); exchange.getOut().setBody(cfMapDeleted); } }
protected void doGetNamespace(Exchange exchange, String operation) { String namespaceName = exchange.getIn().getHeader( KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); if (ObjectHelper.isEmpty(namespaceName)) { LOG.error("Get a specific namespace require specify a namespace name"); throw new IllegalArgumentException( "Get a specific namespace require specify a namespace name"); } Namespace namespace = getEndpoint().getKubernetesClient().namespaces() .withName(namespaceName).get(); MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); exchange.getOut().setBody(namespace); }
protected void doDeleteDeployment(Exchange exchange, String operation) { String deploymentName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_DEPLOYMENT_NAME, String.class); String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); if (ObjectHelper.isEmpty(deploymentName)) { LOG.error("Delete a specific deployment require specify a deployment name"); throw new IllegalArgumentException("Delete a specific deployment require specify a deployment name"); } if (ObjectHelper.isEmpty(namespaceName)) { LOG.error("Delete a specific deployment require specify a namespace name"); throw new IllegalArgumentException("Delete a specific deployment require specify a namespace name"); } Boolean deployment = getEndpoint().getKubernetesClient().apps().deployments().inNamespace(namespaceName).withName(deploymentName).delete(); MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); exchange.getOut().setBody(deployment); }
protected void doGetJob(Exchange exchange, String operation) throws Exception { Job job = null; String jobName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_JOB_NAME, String.class); String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); if (ObjectHelper.isEmpty(jobName)) { LOG.error("Get a specific job require specify a job name"); throw new IllegalArgumentException("Get a specific job require specify a job name"); } if (ObjectHelper.isEmpty(namespaceName)) { LOG.error("Get a specific job require specify a namespace name"); throw new IllegalArgumentException("Get a specific job require specify a namespace name"); } job = getEndpoint().getKubernetesClient().batch().jobs().inNamespace(namespaceName).withName(jobName).get(); MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); exchange.getOut().setBody(job); }
private void handleHttpFailure(Exchange exchange) { HttpOperationFailedException e = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, HttpOperationFailedException.class); exchange.getOut().setHeaders(exchange.getIn().getHeaders()); exchange.getOut().setBody(String.format(RESPONSE_STRING_FORMAT, String.format("%d %s", e.getStatusCode(), e.getResponseBody()) )); } }
protected void doListConfigMapsByLabels(Exchange exchange, String operation) throws Exception { ConfigMapList configMapsList = null; Map<String, String> labels = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_CONFIGMAPS_LABELS, Map.class); FilterWatchListMultiDeletable<ConfigMap, ConfigMapList, Boolean, Watch, Watcher<ConfigMap>> configMaps = getEndpoint().getKubernetesClient().configMaps().inAnyNamespace(); for (Map.Entry<String, String> entry : labels.entrySet()) { configMaps.withLabel(entry.getKey(), entry.getValue()); } configMapsList = configMaps.list(); MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); exchange.getOut().setBody(configMapsList.getItems()); }
protected static boolean hasParameter(String nextParam, Exchange exchange, Object body) { Map<?, ?> bodyMap = safeMap(exchange.getContext().getTypeConverter().tryConvertTo(Map.class, body)); Map<?, ?> headersMap = safeMap(exchange.getIn().getHeaders()); if ((nextParam.startsWith("$simple{") || nextParam.startsWith("${")) && nextParam.endsWith("}")) { return true; } else if (bodyMap.containsKey(nextParam)) { return true; } else if (headersMap.containsKey(nextParam)) { return true; } return false; }
private Object getMultiInsertBody(Exchange exchange) { Object insert; // we try List first, because it should be the common case insert = exchange.getIn().getBody(List.class); if (insert != null) { // if the body of type List was obtained, ensure that all items are of type DBObject and cast the List to List<DBObject> insert = attemptConvertToList((List<?>) insert, exchange); } else { insert = exchange.getContext().getTypeConverter().tryConvertTo(BasicDBList.class, exchange, exchange.getIn().getBody()); } if (insert == null) { throw new CamelMongoDbException("MongoDB operation = insert, Body is not conversible to type DBObject nor List<DBObject>"); } return insert; }
protected void doGetBuild(Exchange exchange, String operation) throws Exception { Build build = null; String buildName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_BUILD_NAME, String.class); String namespaceName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); if (ObjectHelper.isEmpty(buildName)) { LOG.error("Get a specific Build require specify a Build name"); throw new IllegalArgumentException("Get a specific Build require specify a Build name"); } if (ObjectHelper.isEmpty(namespaceName)) { LOG.error("Get a specific Build require specify a namespace name"); throw new IllegalArgumentException("Get a specific Build require specify a namespace name"); } build = getEndpoint().getKubernetesClient().adapt(OpenShiftClient.class).builds().inNamespace(namespaceName).withName(buildName).get(); MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); exchange.getOut().setBody(build); } }
protected void doGetNode(Exchange exchange, String operation) throws Exception { Node node = null; String pvName = exchange.getIn().getHeader(KubernetesConstants.KUBERNETES_NODE_NAME, String.class); if (ObjectHelper.isEmpty(pvName)) { LOG.error("Get a specific Node require specify a Node name"); throw new IllegalArgumentException("Get a specific Node require specify a Node name"); } node = getEndpoint().getKubernetesClient().nodes().withName(pvName).get(); MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); exchange.getOut().setBody(node); } }
protected void doGetPersistentVolume(Exchange exchange, String operation) throws Exception { PersistentVolume pv = null; String pvName = exchange.getIn().getHeader( KubernetesConstants.KUBERNETES_PERSISTENT_VOLUME_NAME, String.class); if (ObjectHelper.isEmpty(pvName)) { LOG.error("Get a specific Persistent Volume require specify a Persistent Volume name"); throw new IllegalArgumentException( "Get a specific Persistent Volume require specify a Persistent Volume name"); } pv = getEndpoint().getKubernetesClient().persistentVolumes().withName(pvName).get(); MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); exchange.getOut().setBody(pv); } }
private void compare(long expected, Exchange exchange) { long update = exchange.getIn().getBody(Long.class); if (ObjectHelper.isEmpty(expected)) { throw new IllegalArgumentException("Expected value must be specified"); } exchange.getOut().setBody(this.atomicnumber.compareAndSet(expected, update)); }
protected void doList(Exchange exchange, String operation) throws Exception { ServiceList servicesList = null; String namespaceName = exchange.getIn().getHeader( KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class); if (!ObjectHelper.isEmpty(namespaceName)) { servicesList = getEndpoint().getKubernetesClient().services() .inNamespace(namespaceName).list(); } else { servicesList = getEndpoint().getKubernetesClient().services().inAnyNamespace() .list(); } MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); exchange.getOut().setBody(servicesList.getItems()); }