Skip to content

Commit

Permalink
Merge pull request #389 from aol/oathMigration
Browse files Browse the repository at this point in the history
Oath migration
  • Loading branch information
johnmcclean authored Nov 2, 2017
2 parents affed8e + 187a417 commit 2ec0695
Show file tree
Hide file tree
Showing 1,512 changed files with 20,942 additions and 21,419 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.aol.micro.server.application.registry;
package com.oath.micro.server.application.registry;

import java.util.Iterator;
import java.util.List;
Expand All @@ -9,7 +9,7 @@
import lombok.experimental.FieldDefaults;


import com.aol.micro.server.rest.jackson.JacksonUtil;
import com.oath.micro.server.rest.jackson.JacksonUtil;

@FieldDefaults(makeFinal=true, level=AccessLevel.PRIVATE)
public class Application implements Iterable<RegisterEntry>{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.aol.micro.server.application.registry;
package com.oath.micro.server.application.registry;

import java.net.InetAddress;
import java.net.UnknownHostException;
Expand All @@ -16,8 +16,8 @@
import org.springframework.stereotype.Component;


import com.aol.micro.server.servers.ApplicationRegister;
import com.aol.micro.server.servers.model.ServerData;
import com.oath.micro.server.servers.ApplicationRegister;
import com.oath.micro.server.servers.model.ServerData;

import lombok.Getter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.aol.micro.server.application.registry;
package com.oath.micro.server.application.registry;

import java.io.File;
import java.util.Date;
Expand All @@ -11,7 +11,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.aol.micro.server.rest.jackson.JacksonUtil;
import com.oath.micro.server.rest.jackson.JacksonUtil;

@Component
public class Cleaner {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.aol.micro.server.application.registry;
package com.oath.micro.server.application.registry;

import java.io.File;
import java.util.ArrayList;
Expand All @@ -15,7 +15,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.aol.micro.server.rest.jackson.JacksonUtil;
import com.oath.micro.server.rest.jackson.JacksonUtil;

@Component
public class Finder {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.oath.micro.server.application.registry;

public enum Health {

OK, ERROR
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.oath.micro.server.application.registry;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.oath.micro.server.rest.client.nio.AsyncRestClient;
import com.oath.micro.server.rest.jackson.JacksonUtil;

@Component
public class Job {

private final Logger logger = LoggerFactory.getLogger(getClass());
private final AsyncRestClient rest = new AsyncRestClient(
100, 2000);
private final String apiUrl;
private final ApplicationRegisterImpl app;
private final String uuid = UUID.randomUUID()
.toString();
private final String resourcePath;
private final RegistryHealthChecker checker;
private final RegistryStatsChecker statsChecker;

@Autowired
public Job(@Value("${service.registry.url:#{null}}") String apiUrl, ApplicationRegisterImpl app,
@Value("${resource.path:/service-registry/register}") String resourcePath, RegistryHealthChecker checker,
RegistryStatsChecker statsChecker) {

this.apiUrl = apiUrl;
this.app = app;
this.resourcePath = resourcePath;
this.checker = checker;
this.statsChecker = statsChecker;

}

@PostConstruct
@Scheduled(fixedDelayString = "${service.registry.delay:1000}")
public synchronized void schedule() {
try {
if (app.getApplication() != null && apiUrl != null)
app.getApplication()
.forEach(moduleEntry -> sendPing(moduleEntry));
} catch (Exception e) {
logger.error("Failed to register services due to exception {}", e.getMessage(), e);
}
}

private void sendPing(RegisterEntry moduleEntry) {
final RegisterEntry entry = moduleEntry.withTime(new Date())
.withUuid(uuid)
.withHealth(checker.isOk() ? Health.OK : Health.ERROR)
.withStats(nonEmptyOrNull(statsChecker.stats()));
try {

logger.debug("Posting {} to " + apiUrl + resourcePath, JacksonUtil.serializeToJson(entry));
rest.post(apiUrl + resourcePath, JacksonUtil.serializeToJson(entry))
.join();
} catch (Exception e) {
logger.warn("Failed posting {} to {}" + resourcePath, JacksonUtil.serializeToJson(entry), apiUrl);

}
}

private List<Map<String, Map<String, String>>> nonEmptyOrNull(List<Map<String, Map<String, String>>> stats) {
if (stats == null || stats.isEmpty())
return null;
return stats;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.aol.micro.server.application.registry;
package com.oath.micro.server.application.registry;

import java.io.InputStream;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package com.aol.micro.server.application.registry;
package com.oath.micro.server.application.registry;

import java.io.File;
import java.io.IOException;

import lombok.val;

import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.aol.micro.server.ip.tracker.*;
import com.aol.micro.server.rest.jackson.JacksonUtil;
import com.oath.micro.server.ip.tracker.*;
import com.oath.micro.server.rest.jackson.JacksonUtil;


@Component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.aol.micro.server.application.registry;
package com.oath.micro.server.application.registry;

import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.aol.micro.server.application.registry;
package com.oath.micro.server.application.registry;

import java.text.SimpleDateFormat;
import java.util.*;

import javax.ws.rs.QueryParam;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.aol.micro.server.application.registry;
package com.oath.micro.server.application.registry;

import java.util.List;

Expand All @@ -8,7 +8,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.aol.micro.server.HealthStatusChecker;
import com.oath.micro.server.HealthStatusChecker;

@Component
public class RegistryHealthChecker {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.aol.micro.server.application.registry;
package com.oath.micro.server.application.registry;

import java.util.List;
import java.util.Map;
Expand All @@ -10,7 +10,7 @@
import org.springframework.stereotype.Component;


import com.aol.micro.server.StatsSupplier;
import com.oath.micro.server.StatsSupplier;

@Component
public class RegistryStatsChecker {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package com.aol.micro.server.application.registry;
package com.oath.micro.server.application.registry;

import java.util.Arrays;
import java.util.Optional;

import javax.ws.rs.*;
import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;

import cyclops.reactive.ReactiveSeq;
Expand All @@ -17,11 +14,9 @@
import org.springframework.beans.factory.annotation.Autowired;


import com.aol.micro.server.WorkerThreads;
import com.aol.micro.server.auto.discovery.Rest;
import com.aol.micro.server.utility.HashMapBuilder;

import static javax.ws.rs.core.Response.Status.*;
import com.oath.micro.server.WorkerThreads;
import com.oath.micro.server.auto.discovery.Rest;
import com.oath.micro.server.utility.HashMapBuilder;


@Rest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.aol.micro.server.application.registry;
package com.oath.micro.server.application.registry;

import cyclops.reactive.ReactiveSeq;

Expand Down
Loading

0 comments on commit 2ec0695

Please sign in to comment.