Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
CorrelationIds, Collaborators, Pings
Browse files Browse the repository at this point in the history
  • Loading branch information
marcingrzejszczak committed May 15, 2015
1 parent e26967a commit 2323b7f
Show file tree
Hide file tree
Showing 17 changed files with 220 additions and 246 deletions.
@@ -1,25 +1,15 @@
package com.ofg.infrastructure.discovery;

import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.ofg.infrastructure.discovery.util.CollectionUtils;
import com.ofg.infrastructure.discovery.util.LoadBalancerType;
import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static com.ofg.infrastructure.discovery.ServiceConfigurationProperties.PATH;

public class ServiceConfigurationResolver {

private final String basePath;
Expand Down Expand Up @@ -61,9 +51,9 @@ private String extractBasePath(JSONObject parsedJson) {

private void validateConfiguration(JSONObject metaData) {
serviceConfigurationValidator.checkThatServiceMetadataContainsValidElements(metaData);
jsonToMicroserviceConfigurationConverter.convertFlatDependenciesToMapFormat(metaData);
JsonToMicroserviceConfigurationConverter.convertFlatDependenciesToMapFormat(metaData);
serviceConfigurationValidator.validateDependencyEntries(metaData);
jsonToMicroserviceConfigurationConverter.setDefaultsForMissingOptionalElements(metaData);
JsonToMicroserviceConfigurationConverter.setDefaultsForMissingOptionalElements(metaData);
}

private static JSONObject getDependenciesAsJsonObject(JSONObject serviceMetadata) {
Expand Down

This file was deleted.

@@ -0,0 +1,21 @@
package com.ofg.infrastructure.correlationid;

/**
* Component that stores correlation id using {@link ThreadLocal}
*/
public class CorrelationIdHolder {
public static final String CORRELATION_ID_HEADER = "correlationId";
private static final ThreadLocal<String> id = new ThreadLocal<String>();

public static void set(String correlationId) {
id.set(correlationId);
}

public static String get() {
return id.get();
}

public static void remove() {
id.remove();
}
}

This file was deleted.

@@ -0,0 +1,10 @@
package com.ofg.infrastructure.correlationid;

import java.util.UUID;

public class UuidGenerator {
public String create() {
return UUID.randomUUID().toString();
}

}

This file was deleted.

@@ -0,0 +1,10 @@
package com.ofg.infrastructure.healthcheck;

public enum CollaboratorStatus {
UP, DOWN;

public static CollaboratorStatus of(boolean isUp) {
return isUp ? UP : DOWN;
}

}

This file was deleted.

@@ -0,0 +1,26 @@
package com.ofg.infrastructure.healthcheck;

import com.ofg.infrastructure.discovery.ServiceResolver;
import com.ofg.infrastructure.web.resttemplate.fluent.ServiceRestClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* Registers {@link PingController} (the microservice health check controller) and {@link CollaboratorsConnectivityController} (provider of a state of microservice connection with dependent services).
*
* @see PingController
* @see CollaboratorsConnectivityController
*/
@Configuration
public class CollaboratorsConfiguration {
@Bean
public CollaboratorsStatusResolver collaboratorsStatusResolver(ServiceResolver serviceResolver, PingClient pingClient) {
return new CollaboratorsStatusResolver(serviceResolver, pingClient);
}

@Bean
public PingClient pingClient(ServiceRestClient serviceRestClient) {
return new PingClient(serviceRestClient);
}

}

This file was deleted.

@@ -0,0 +1,37 @@
package com.ofg.infrastructure.healthcheck;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
* {@link RestController} providing connection state with services the microservice depends upon.
*/
@RestController
@RequestMapping(value = "/collaborators", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
class CollaboratorsConnectivityController {
public CollaboratorsConnectivityController(CollaboratorsStatusResolver collaboratorsStatusResolver) {
this.collaboratorsStatusResolver = collaboratorsStatusResolver;
}

/**
* Returns information about connection status of microservice with other microservices.
* For properly connected service <b>UP</b> state is provided and <b>DOWN</b> otherwise.
*
* @return connection status
*/
@RequestMapping
public Map getCollaboratorsConnectivityInfo() {
return collaboratorsStatusResolver.statusOfMyCollaborators();
}

@RequestMapping("/all")
public Map getAllCollaboratorsConnectivityInfo() {
return collaboratorsStatusResolver.statusOfAllDependencies();
}

private final CollaboratorsStatusResolver collaboratorsStatusResolver;
}

This file was deleted.

@@ -0,0 +1,33 @@
package com.ofg.infrastructure.healthcheck;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.io.Resource;

/**
* Registers {@link PingController} (the microservice health check controller) and {@link CollaboratorsConnectivityController} (provider of a state of microservice connection with dependent services).
*
* @see PingController
* @see CollaboratorsConnectivityController
*/
@Configuration
@Import(CollaboratorsConfiguration.class)
public class HealthCheckConfiguration {
@Bean
public PingController pingController() {
return new PingController();
}

@Bean
public CollaboratorsConnectivityController collaboratorsConnectivityController(CollaboratorsStatusResolver collaboratorsStatusResolver) {
return new CollaboratorsConnectivityController(collaboratorsStatusResolver);
}

@Bean
public MicroserviceConfigurationController microserviceConfigurationController(@Value("${microservice.config.file:classpath:microservice.json}") Resource microserviceConfig) {
return new MicroserviceConfigurationController(microserviceConfig);
}

}

0 comments on commit 2323b7f

Please sign in to comment.