Commit 3c78f488 authored by Spiros Koulouzis's avatar Spiros Koulouzis

Implmemted rabbitmq logging for user

parent eb3081f7
...@@ -51,6 +51,7 @@ import nl.uva.sne.drip.api.dao.KeyPairDao; ...@@ -51,6 +51,7 @@ import nl.uva.sne.drip.api.dao.KeyPairDao;
import nl.uva.sne.drip.api.exception.BadRequestException; import nl.uva.sne.drip.api.exception.BadRequestException;
import nl.uva.sne.drip.api.exception.KeyException; import nl.uva.sne.drip.api.exception.KeyException;
import nl.uva.sne.drip.commons.utils.Converter; import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.commons.utils.DRIPLogHandler;
import nl.uva.sne.drip.drip.commons.data.v1.external.ConfigurationRepresentation; import nl.uva.sne.drip.drip.commons.data.v1.external.ConfigurationRepresentation;
import nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair; import nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair;
import nl.uva.sne.drip.drip.commons.data.v1.external.ScaleRequest; import nl.uva.sne.drip.drip.commons.data.v1.external.ScaleRequest;
...@@ -94,6 +95,13 @@ public class DeployService { ...@@ -94,6 +95,13 @@ public class DeployService {
private static final String[] CLOUD_SITE_NAMES = new String[]{"domain", "VMResourceID"}; private static final String[] CLOUD_SITE_NAMES = new String[]{"domain", "VMResourceID"};
private static final String[] PUBLIC_ADRESS_NAMES = new String[]{"public_address", "publicAddress"}; private static final String[] PUBLIC_ADRESS_NAMES = new String[]{"public_address", "publicAddress"};
private final Logger logger;
@Autowired
public DeployService() throws IOException, TimeoutException {
logger = Logger.getLogger(DeployService.class.getName());
logger.addHandler(new DRIPLogHandler(messageBrokerHost));
}
@PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))") @PostAuthorize("(returnObject.owner == authentication.name) or (hasRole('ROLE_ADMIN'))")
public DeployResponse findOne(String id) throws JSONException, IOException, TimeoutException, InterruptedException { public DeployResponse findOne(String id) throws JSONException, IOException, TimeoutException, InterruptedException {
...@@ -145,12 +153,15 @@ public class DeployService { ...@@ -145,12 +153,15 @@ public class DeployService {
// + File.separator + "workspace" + File.separator + "DRIP" // + File.separator + "workspace" + File.separator + "DRIP"
// + File.separator + "docs" + File.separator + "json_samples" // + File.separator + "docs" + File.separator + "json_samples"
// + File.separator + "deployer_ansible_response_benchmark.json"); // + File.separator + "deployer_ansible_response_benchmark.json");
logger.info("Calling deployer");
Message response = (deployer.call(deployerInvokationMessage)); Message response = (deployer.call(deployerInvokationMessage));
logger.info("Got response from deployer");
List<MessageParameter> params = response.getParameters(); List<MessageParameter> params = response.getParameters();
DeployResponse deploy = handleResponse(params, deployInfo); DeployResponse deploy = handleResponse(params, deployInfo);
deploy.setProvisionID(deployInfo.getProvisionID()); deploy.setProvisionID(deployInfo.getProvisionID());
deploy.setConfigurationID(deployInfo.getConfigurationID()); deploy.setConfigurationID(deployInfo.getConfigurationID());
deploy.setManagerType(deployInfo.getManagerType().toLowerCase()); deploy.setManagerType(deployInfo.getManagerType().toLowerCase());
logger.info("Deployment saved");
save(deploy); save(deploy);
return deploy; return deploy;
...@@ -172,7 +183,9 @@ public class DeployService { ...@@ -172,7 +183,9 @@ public class DeployService {
Map<String, Object> info; Map<String, Object> info;
deployerInvokationMessage.setOwner(((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername()); deployerInvokationMessage.setOwner(((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername());
try (DRIPCaller deployer = new DeployerCaller(messageBrokerHost);) { try (DRIPCaller deployer = new DeployerCaller(messageBrokerHost);) {
logger.info("Calling deployer");
Message response = (deployer.call(deployerInvokationMessage)); Message response = (deployer.call(deployerInvokationMessage));
logger.info("Got response from deployer");
List<MessageParameter> params = response.getParameters(); List<MessageParameter> params = response.getParameters();
info = buildSwarmInfo(params); info = buildSwarmInfo(params);
} }
...@@ -326,7 +339,9 @@ public class DeployService { ...@@ -326,7 +339,9 @@ public class DeployService {
Message message = buildDeployerMessage(deployment.getProvisionID(), "scale", confID, scaleReq.getScaleTargetName(), scaleReq.getNumOfInstances()); Message message = buildDeployerMessage(deployment.getProvisionID(), "scale", confID, scaleReq.getScaleTargetName(), scaleReq.getNumOfInstances());
message.setOwner(((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername()); message.setOwner(((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername());
try (DRIPCaller deployer = new DeployerCaller(messageBrokerHost);) { try (DRIPCaller deployer = new DeployerCaller(messageBrokerHost);) {
logger.info("Calling deployer");
Message response = (deployer.call(message)); Message response = (deployer.call(message));
logger.info("Got response from deployer");
List<MessageParameter> params = response.getParameters(); List<MessageParameter> params = response.getParameters();
handleResponse(params, null); handleResponse(params, null);
} }
......
...@@ -59,6 +59,7 @@ import org.springframework.security.access.prepost.PreAuthorize; ...@@ -59,6 +59,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import nl.uva.sne.drip.api.dao.ProvisionResponseDao; import nl.uva.sne.drip.api.dao.ProvisionResponseDao;
import nl.uva.sne.drip.api.rpc.ProvisionerCaller1; import nl.uva.sne.drip.api.rpc.ProvisionerCaller1;
import nl.uva.sne.drip.commons.utils.DRIPLogHandler;
import nl.uva.sne.drip.drip.commons.data.v1.external.Key; import nl.uva.sne.drip.drip.commons.data.v1.external.Key;
import nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair; import nl.uva.sne.drip.drip.commons.data.v1.external.KeyPair;
import nl.uva.sne.drip.drip.commons.data.v1.external.ScaleRequest; import nl.uva.sne.drip.drip.commons.data.v1.external.ScaleRequest;
...@@ -88,6 +89,13 @@ public class ProvisionService { ...@@ -88,6 +89,13 @@ public class ProvisionService {
@Value("${message.broker.host}") @Value("${message.broker.host}")
private String messageBrokerHost; private String messageBrokerHost;
private final Logger logger;
@Autowired
public ProvisionService() throws IOException, TimeoutException {
logger = Logger.getLogger(DeployService.class.getName());
logger.addHandler(new DRIPLogHandler(messageBrokerHost));
}
public ProvisionResponse save(ProvisionResponse ownedObject) { public ProvisionResponse save(ProvisionResponse ownedObject) {
User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
...@@ -442,10 +450,10 @@ public class ProvisionService { ...@@ -442,10 +450,10 @@ public class ProvisionService {
try (DRIPCaller provisioner = new ProvisionerCaller0(messageBrokerHost);) { try (DRIPCaller provisioner = new ProvisionerCaller0(messageBrokerHost);) {
Message provisionerInvokationMessage = buildProvisioner0Message(provisionRequest); Message provisionerInvokationMessage = buildProvisioner0Message(provisionRequest);
provisionerInvokationMessage.setOwner(((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername()); provisionerInvokationMessage.setOwner(((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername());
logger.info("Calling provisioner");
Message response = (provisioner.call(provisionerInvokationMessage)); Message response = (provisioner.call(provisionerInvokationMessage));
logger.info("Got provisioner response");
return parseCreateResourcesResponse(response.getParameters(), provisionRequest, null, true, true); return parseCreateResourcesResponse(response.getParameters(), provisionRequest, null, true, true);
} }
} }
...@@ -454,7 +462,9 @@ public class ProvisionService { ...@@ -454,7 +462,9 @@ public class ProvisionService {
try (DRIPCaller provisioner = new ProvisionerCaller1(messageBrokerHost);) { try (DRIPCaller provisioner = new ProvisionerCaller1(messageBrokerHost);) {
Message provisionerInvokationMessage = buildProvisioner1Message(provisionRequest); Message provisionerInvokationMessage = buildProvisioner1Message(provisionRequest);
provisionerInvokationMessage.setOwner(((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername()); provisionerInvokationMessage.setOwner(((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername());
logger.info("Calling provisioner");
Message response = (provisioner.call(provisionerInvokationMessage)); Message response = (provisioner.call(provisionerInvokationMessage));
logger.info("Got provisioner response");
return parseCreateResourcesResponse(response.getParameters(), provisionRequest, null, true, true); return parseCreateResourcesResponse(response.getParameters(), provisionRequest, null, true, true);
} }
...@@ -464,7 +474,9 @@ public class ProvisionService { ...@@ -464,7 +474,9 @@ public class ProvisionService {
try (DRIPCaller provisioner = new ProvisionerCaller1(messageBrokerHost);) { try (DRIPCaller provisioner = new ProvisionerCaller1(messageBrokerHost);) {
Message deleteInvokationMessage = buildTopoplogyModificationMessage(provisionInfo, "kill_topology", null); Message deleteInvokationMessage = buildTopoplogyModificationMessage(provisionInfo, "kill_topology", null);
deleteInvokationMessage.setOwner(((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername()); deleteInvokationMessage.setOwner(((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername());
logger.info("Calling provisioner");
Message response = (provisioner.call(deleteInvokationMessage)); Message response = (provisioner.call(deleteInvokationMessage));
logger.info("Got provisioner response");
parseDeleteResourcesResponse(response.getParameters(), provisionInfo); parseDeleteResourcesResponse(response.getParameters(), provisionInfo);
} }
} }
...@@ -514,7 +526,9 @@ public class ProvisionService { ...@@ -514,7 +526,9 @@ public class ProvisionService {
Message scaleMessage = buildTopoplogyModificationMessage(provisionInfo, "scale_topology_down", extra); Message scaleMessage = buildTopoplogyModificationMessage(provisionInfo, "scale_topology_down", extra);
scaleMessage.setOwner(((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername()); scaleMessage.setOwner(((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername());
logger.info("Calling provisioner");
Message response = provisioner.call(scaleMessage); Message response = provisioner.call(scaleMessage);
logger.info("Got response from provisioner");
parseCreateResourcesResponse(response.getParameters(), null, provisionInfo, false, false); parseCreateResourcesResponse(response.getParameters(), null, provisionInfo, false, false);
} }
} else if (currentNumOfInstances < scaleRequest.getNumOfInstances() || currentNumOfInstances == 0) { } else if (currentNumOfInstances < scaleRequest.getNumOfInstances() || currentNumOfInstances == 0) {
...@@ -527,7 +541,9 @@ public class ProvisionService { ...@@ -527,7 +541,9 @@ public class ProvisionService {
Message scaleMessage = buildTopoplogyModificationMessage(provisionInfo, "scale_topology_up", extra); Message scaleMessage = buildTopoplogyModificationMessage(provisionInfo, "scale_topology_up", extra);
scaleMessage.setOwner(((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername()); scaleMessage.setOwner(((User) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername());
logger.info("Calling provisioner");
Message response = provisioner.call(scaleMessage); Message response = provisioner.call(scaleMessage);
logger.info("Got response from provisioner");
parseCreateResourcesResponse(response.getParameters(), null, provisionInfo, false, false); parseCreateResourcesResponse(response.getParameters(), null, provisionInfo, false, false);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment