Skip to content
Snippets Groups Projects
Commit 1fa1e2a5 authored by Anuj Gupta's avatar Anuj Gupta
Browse files

Merge branch 'automatic-deploy-sl-ibm' into 'master'

added automatic deployment logic for new serverless app

See merge request !197
parents 858efb03 d31ff1ad
No related branches found
No related tags found
2 merge requests!229Merge branch 'dependency-upgrade' into 'master',!197added automatic deployment logic for new serverless app
Pipeline #113086 passed with warnings
...@@ -3,13 +3,20 @@ ...@@ -3,13 +3,20 @@
package org.opengroup.osdu.partition.provider.ibm.service; package org.opengroup.osdu.partition.provider.ibm.service;
import com.cloudant.client.api.Database; import java.io.IOException;
import com.cloudant.client.api.model.Response; import java.net.MalformedURLException;
import com.cloudant.client.org.lightcouch.DocumentConflictException; import java.util.HashMap;
import com.cloudant.client.org.lightcouch.NoDocumentException; import java.util.List;
import lombok.extern.slf4j.Slf4j; import java.util.Map;
import javax.annotation.PostConstruct;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.opengroup.osdu.core.common.cache.ICache; import org.opengroup.osdu.core.common.cache.ICache;
import org.opengroup.osdu.core.common.http.HttpClient;
import org.opengroup.osdu.core.common.http.HttpRequest;
import org.opengroup.osdu.core.common.http.HttpResponse;
import org.opengroup.osdu.core.common.http.IHttpClient;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.ibm.auth.ServiceCredentials; import org.opengroup.osdu.core.ibm.auth.ServiceCredentials;
...@@ -22,10 +29,13 @@ import org.springframework.beans.factory.annotation.Qualifier; ...@@ -22,10 +29,13 @@ import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct; import com.cloudant.client.api.Database;
import java.io.IOException; import com.cloudant.client.api.model.Response;
import java.net.MalformedURLException; import com.cloudant.client.org.lightcouch.DocumentConflictException;
import java.util.List; import com.cloudant.client.org.lightcouch.NoDocumentException;
import com.google.gson.JsonObject;
import lombok.extern.slf4j.Slf4j;
@Service @Service
@Slf4j @Slf4j
...@@ -44,6 +54,11 @@ public class PartitionServiceImpl implements IPartitionService { ...@@ -44,6 +54,11 @@ public class PartitionServiceImpl implements IPartitionService {
@Autowired @Autowired
@Qualifier("partitionListCache") @Qualifier("partitionListCache")
private ICache<String, List<String>> partitionListCache; private ICache<String, List<String>> partitionListCache;
@Value("${pipline.trigger.url}")
String pipelineURL;
private final IHttpClient httpClient = new HttpClient();
Database db; Database db;
...@@ -84,6 +99,10 @@ public class PartitionServiceImpl implements IPartitionService { ...@@ -84,6 +99,10 @@ public class PartitionServiceImpl implements IPartitionService {
PartitionInfo pi; PartitionInfo pi;
PartitionDoc partitionDoc = new PartitionDoc(partitionId, partitionInfo); PartitionDoc partitionDoc = new PartitionDoc(partitionId, partitionInfo);
try { try {
HttpResponse response = runPipeline(partitionId);
if(response.getResponseCode() != HttpStatus.SC_ACCEPTED || response.getResponseCode() != HttpStatus.SC_CREATED) {
log.error("Response Recieved : "+response.getResponseCode()+"Error occured while triggering pipeline for record-changed-topic-listener [tenant-specific] deployment");
}
db.save(partitionDoc); db.save(partitionDoc);
pi = partitionInfo; pi = partitionInfo;
} catch (DocumentConflictException e) { } catch (DocumentConflictException e) {
...@@ -103,6 +122,29 @@ public class PartitionServiceImpl implements IPartitionService { ...@@ -103,6 +122,29 @@ public class PartitionServiceImpl implements IPartitionService {
return pi; return pi;
} }
private HttpResponse runPipeline(String partitionID) {
JsonObject buildPostJsonData = buildPostJsonData(partitionID);
Map<String, String> httpHeaders = new HashMap<>();
httpHeaders.put("X-GitHub-Event", "push");
httpHeaders.put("Content-Type", "application/json");
//System.out.println("buildPostJsonData.getAsString() "+buildPostJsonData.getAsString());
HttpResponse result = this.httpClient.send(
HttpRequest.post(buildPostJsonData).url(pipelineURL).headers(httpHeaders).build());
//this.getResult(result, Members.class);
log.info("Pipeline trigger Response {}, Response Body : {}", result.getResponseCode(), result.getBody());
return result;
}
private JsonObject buildPostJsonData(String partitionId) {
JsonObject repositoryJson = new JsonObject();
repositoryJson.addProperty("url", "https://unused-url-parameter-but-mandatory");
repositoryJson.addProperty("name", partitionId);
JsonObject postData = new JsonObject();
postData.add("repository", repositoryJson);
return postData;
}
@Override @Override
public PartitionInfo updatePartition(String partitionId, PartitionInfo partitionInfo) { public PartitionInfo updatePartition(String partitionId, PartitionInfo partitionInfo) {
PartitionInfo pi; PartitionInfo pi;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment