Skip to content

Commit

Permalink
Added SM Client
Browse files Browse the repository at this point in the history
  • Loading branch information
vthglyk committed Jul 25, 2018
1 parent f8a74e5 commit 66b2bab
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ public static AbstractSymbIoTeClientFactory getFactory(Config config)
*/
public abstract PRClient getPRClient(String platformId);

/**
* Get a Subscription Manager (SM) client for querying the SM of a specific platform
*
* @param platformId the platform which we want to communicate with
* @return a SM client
*/
public abstract SMClient getSMClient(String platformId);

/**
* Get an Authentication and Authorization (AAM) client to communicate with an AAM of a specific platform
*
Expand Down
65 changes: 65 additions & 0 deletions src/main/java/eu/h2020/symbiote/client/feign/FeignSMClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package eu.h2020.symbiote.client.feign;

import eu.h2020.symbiote.client.interfaces.SMClient;
import eu.h2020.symbiote.cloud.model.internal.Subscription;
import eu.h2020.symbiote.security.commons.exceptions.custom.SecurityHandlerException;
import eu.h2020.symbiote.security.communication.ApacheCommonsLogger4Feign;
import eu.h2020.symbiote.security.communication.payloads.AAM;
import eu.h2020.symbiote.security.handler.ISecurityHandler;
import feign.Feign;
import feign.Headers;
import feign.Logger;
import feign.RequestLine;
import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.Map;

/**
* symbIoTe Subscription Manager client based on Feign
*
* @author Vasilis Glykantzis
*/
public class FeignSMClient implements SMClient {

private static final Log logger = LogFactory.getLog(FeignSMClient.class);

private SubscriptionManagerI smClient;

/**
*
* @param securityHandler the security handler implementation that is going to be used
* @param homePlatformId the home Platform Id
*/
public FeignSMClient(ISecurityHandler securityHandler,
String homePlatformId) {

try {
Map<String, AAM> availableAAMs = securityHandler.getAvailableAAMs();
String smBaseUrl = availableAAMs.get(homePlatformId).getAamAddress().replace("/paam", "/subscriptionManager");

this.smClient = Feign.builder()
.decoder(new JacksonDecoder())
.encoder(new JacksonEncoder())
.logger(new ApacheCommonsLogger4Feign(logger))
.logLevel(Logger.Level.FULL)
.client(new SymbIoTeSecurityHandlerFeignClient())
.target(SubscriptionManagerI.class, smBaseUrl);
} catch (SecurityHandlerException e) {
logger.error("Could not create FeignSMClient", e);
}
}

@Override
public void subscribe(Subscription subscription) {
this.smClient.subscribe(subscription);
}

private interface SubscriptionManagerI {
@RequestLine("POST /subscribe ")
@Headers({"Accept: application/json", "Content-Type: application/json"})
void subscribe(Subscription subscription);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public void checkServerTrusted(
@Override
public PRClient getPRClient(String platformId) { return new FeignPRClient(securityHandler, platformId); }

@Override
public SMClient getSMClient(String platformId) { return new FeignSMClient(securityHandler, platformId); }

@Override
public IAAMClient getAAMClient(String homePlatformId) {
try {
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/eu/h2020/symbiote/client/interfaces/SMClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package eu.h2020.symbiote.client.interfaces;

import eu.h2020.symbiote.cloud.model.internal.Subscription;

/**
* Interface for querying the platform Subscription Manager component
*
* @author Vasilis Glykantzis
*/
public interface SMClient {

/**
* Queries the Platform Registry component with home token
*
* @param subscription the subscription request send to the Subscription Manager
*/
void subscribe(Subscription subscription);
}

0 comments on commit 66b2bab

Please sign in to comment.