use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project fabric8-maven-plugin by fabric8io.
the class ApplyMojo method createRouteForService.
private Route createRouteForService(String routeDomainPostfix, String namespace, Service service) {
Route route = null;
String id = KubernetesHelper.getName(service);
if (Strings.isNotBlank(id) && hasExactlyOneService(service, id)) {
route = new Route();
String routeId = id;
KubernetesHelper.setName(route, namespace, routeId);
RouteSpec routeSpec = new RouteSpec();
RouteTargetReference objectRef = new RouteTargetReferenceBuilder().withName(id).build();
// objectRef.setNamespace(namespace);
routeSpec.setTo(objectRef);
if (!Strings.isNullOrBlank(routeDomainPostfix)) {
String host = Strings.stripSuffix(Strings.stripSuffix(id, "-service"), ".");
routeSpec.setHost(host + "." + Strings.stripPrefix(routeDomainPostfix, "."));
} else {
routeSpec.setHost("");
}
route.setSpec(routeSpec);
String json;
try {
json = KubernetesHelper.toJson(route);
} catch (JsonProcessingException e) {
json = e.getMessage() + ". object: " + route;
}
log.debug("Created route: " + json);
}
return route;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project fabric8-maven-plugin by fabric8io.
the class ApplyMojo method createIngressForService.
private Ingress createIngressForService(String routeDomainPostfix, String namespace, Service service) {
Ingress ingress = null;
String serviceName = KubernetesHelper.getName(service);
ServiceSpec serviceSpec = service.getSpec();
if (serviceSpec != null && Strings.isNotBlank(serviceName) && shouldCreateExternalURLForService(service, serviceName)) {
String ingressId = serviceName;
String host = "";
if (Strings.isNotBlank(routeDomainPostfix)) {
host = serviceName + "." + namespace + "." + Strings.stripPrefix(routeDomainPostfix, ".");
}
List<HTTPIngressPath> paths = new ArrayList<>();
List<ServicePort> ports = serviceSpec.getPorts();
if (ports != null) {
for (ServicePort port : ports) {
Integer portNumber = port.getPort();
if (portNumber != null) {
HTTPIngressPath path = new HTTPIngressPathBuilder().withNewBackend().withServiceName(serviceName).withServicePort(createIntOrString(portNumber.intValue())).endBackend().build();
paths.add(path);
}
}
}
if (paths.isEmpty()) {
return ingress;
}
ingress = new IngressBuilder().withNewMetadata().withName(ingressId).withNamespace(namespace).endMetadata().withNewSpec().addNewRule().withHost(host).withNewHttp().withPaths(paths).endHttp().endRule().endSpec().build();
String json;
try {
json = KubernetesHelper.toJson(ingress);
} catch (JsonProcessingException e) {
json = e.getMessage() + ". object: " + ingress;
}
log.debug("Created ingress: " + json);
}
return ingress;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project n4js by eclipse.
the class UpdateShippedCode method cleanJsonFile.
private static void cleanJsonFile(File packJson) {
println(" Cleaning: " + packJson);
ObjectMapper mapper = new ObjectMapper();
try {
ObjectNode root = (ObjectNode) mapper.readTree(packJson);
Iterator<Entry<String, JsonNode>> fieldIterator = root.fields();
List<String> removeFields = new LinkedList<>();
while (fieldIterator.hasNext()) {
Entry<String, JsonNode> field = fieldIterator.next();
String name = field.getKey();
if (name != null && name.startsWith("_")) {
removeFields.add(name);
}
}
final StringBuilder sb = new StringBuilder();
sb.append(" removing fields: ");
for (String fieldName : removeFields) {
sb.append(fieldName + " ");
root.remove(fieldName);
}
println(sb.toString());
String cleanJson = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root);
FileWriter f2 = new FileWriter(packJson, false);
f2.write(cleanJson);
// note: by convention, N4JS repository uses \n as line separator (independent of OS)
f2.write('\n');
f2.close();
} catch (JsonProcessingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project actor4j-core by relvaner.
the class ActorCell method saveSnapshot.
@SuppressWarnings("unchecked")
public <S extends ActorPersistenceObject> void saveSnapshot(Consumer<S> onSuccess, Consumer<Exception> onFailure, S state) {
if (system.persistenceMode && state != null) {
state.persistenceId = persistenceId();
List<ActorPersistenceObject> list = new ArrayList<>();
list.add(state);
PersistenceTuple tuple = new PersistenceTuple((Consumer<ActorPersistenceObject>) onSuccess, onFailure, list);
try {
system.messageDispatcher.postPersistence(new ActorMessage<String>(new ObjectMapper().writeValueAsString(state), PersistenceServiceActor.PERSIST_STATE, id, null));
persistenceTuples.offer(tuple);
} catch (JsonProcessingException e) {
e.printStackTrace();
onFailure.accept(e);
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException in project traccar by traccar.
the class WebDataHandler method formatRequest.
public String formatRequest(Position position) {
Device device = Context.getIdentityManager().getById(position.getDeviceId());
String request = url.replace("{name}", device.getName()).replace("{uniqueId}", device.getUniqueId()).replace("{status}", device.getStatus()).replace("{deviceId}", String.valueOf(position.getDeviceId())).replace("{protocol}", String.valueOf(position.getProtocol())).replace("{deviceTime}", String.valueOf(position.getDeviceTime().getTime())).replace("{fixTime}", String.valueOf(position.getFixTime().getTime())).replace("{valid}", String.valueOf(position.getValid())).replace("{latitude}", String.valueOf(position.getLatitude())).replace("{longitude}", String.valueOf(position.getLongitude())).replace("{altitude}", String.valueOf(position.getAltitude())).replace("{speed}", String.valueOf(position.getSpeed())).replace("{course}", String.valueOf(position.getCourse())).replace("{statusCode}", calculateStatus(position));
if (position.getAddress() != null) {
try {
request = request.replace("{address}", URLEncoder.encode(position.getAddress(), StandardCharsets.UTF_8.name()));
} catch (UnsupportedEncodingException error) {
Log.warning(error);
}
}
if (request.contains("{attributes}")) {
try {
String attributes = Context.getObjectMapper().writeValueAsString(position.getAttributes());
request = request.replace("{attributes}", URLEncoder.encode(attributes, StandardCharsets.UTF_8.name()));
} catch (UnsupportedEncodingException | JsonProcessingException error) {
Log.warning(error);
}
}
if (request.contains("{gprmc}")) {
request = request.replace("{gprmc}", formatSentence(position));
}
return request;
}
Aggregations