Commit 61b519d1 authored by Aleh Shubko [EPAM]'s avatar Aleh Shubko [EPAM]
Browse files

release mongodb pipeline

parent c9657407
Pipeline #119936 passed with stages
in 37 minutes and 34 seconds
......@@ -6,6 +6,11 @@ variables:
AWS_DEPLOY_TARGET: EKS
AWS_EKS_DEPLOYMENT_NAME: os-legal
MONGODB_AWS_SERVICE: legal
MONGODB_AWS_BUILD_SUBDIR: provider/legal-aws/build-aws
MONGODB_AWS_TEST_SUBDIR: testing/legal-test-aws
MONGODB_AWS_EKS_DEPLOYMENT_NAME: os-legal
GCP_BUILD_SUBDIR: provider/legal-gcp
GCP_INT_TEST_SUBDIR: testing/legal-test-gcp
GCP_APPLICATION_NAME: os-legal
......@@ -39,6 +44,12 @@ include:
- project: "osdu/platform/ci-cd-pipelines"
file: "cloud-providers/aws-maven.yml"
- project: "osdu/platform/ci-cd-pipelines"
file: "cloud-providers/aws-mongodb-global.yml"
- project: "osdu/platform/ci-cd-pipelines"
file: "cloud-providers/aws-mongodb-maven.yml"
- project: "osdu/platform/ci-cd-pipelines"
file: "cloud-providers/ibm.yml"
......
......@@ -39,7 +39,7 @@
<dependency>
<groupId>org.opengroup.osdu.core.aws</groupId>
<artifactId>os-core-lib-aws</artifactId>
<version>0.15.0</version>
<version>0.16.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
......
......@@ -44,7 +44,7 @@ spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.security.Sec
repository.implementation=${LEGAL_SERVICE_REPOSITORY_IMPLEMENTATION:dynamodb}
#MongoDB config
osdu.mongodb.database=osdu_legal_${ENVIRONMENT}
osdu.mongodb.database=${ENVIRONMENT}_osdu_legal
osdu.mongodb.authDatabase=${MONGODB_AUTH_DATABASE:admin}
osdu.mongodb.endpoint=${MONGODB_ENDPOINT:}
osdu.mongodb.port=${MONGODB_PORT:27017}
......
......@@ -14,6 +14,7 @@
package org.opengroup.osdu.legal.acceptanceTests;
import org.apache.commons.lang3.StringUtils;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.legal.util.AwsLegalTagUtils;
......@@ -26,8 +27,11 @@ public class TestValidateLegalTagsApiAcceptance extends ValidateLegalTagsApiAcce
AwsLegalTagUtils legalTagUtils = new AwsLegalTagUtils();
// Insert expired legal tag directly for should_return200_withLegalTagNamesAndInvalidExpirationDateReason_when_GivenExistingInvalidLegalTagNames
legalTagUtils.insertExpiredLegalTag();
if (StringUtils.isBlank(System.getenv("MONGO_DB_TEST"))) {
legalTagUtils.insertExpiredLegalTag();
}else {
legalTagUtils.insertExpiredLegalTagMongoDb();
}
this.legalTagUtils = legalTagUtils;
super.setup();
......
......@@ -14,18 +14,18 @@
package org.opengroup.osdu.legal.util;
import java.io.IOException;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import com.amazonaws.services.s3.AmazonS3;
import org.opengroup.osdu.core.aws.cognito.AWSCognitoClient;
import org.opengroup.osdu.core.aws.dynamodb.DynamoDBQueryHelper;
import org.opengroup.osdu.core.aws.dynamodb.DynamoDBQueryHelperV2;
import org.opengroup.osdu.core.aws.mongodb.helper.BasicMongoDBHelper;
import org.opengroup.osdu.core.aws.s3.S3Config;
import org.opengroup.osdu.core.common.model.legal.Properties;
import org.springframework.beans.factory.annotation.Value;
import org.opengroup.osdu.core.common.model.legal.LegalTag;
import org.opengroup.osdu.legal.util.mongo.MongoDbSimpleTestFactory;
import java.io.IOException;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
public class AwsLegalTagUtils extends LegalTagUtils {
private static final String FILE_NAME = "Legal_COO.json";
......@@ -39,6 +39,10 @@ public class AwsLegalTagUtils extends LegalTagUtils {
private final static String TABLE_PREFIX = "TABLE_PREFIX";
private final static String DYNAMO_DB_REGION = "DYNAMO_DB_REGION";
private final static String DYNAMO_DB_ENDPOINT = "DYNAMO_DB_ENDPOINT";
private static final String COLLECTION_PREFIX = "Legal-";
private static final String MONGO_DB_CONNECTION_URL = "MONGO_DB_URL";
private static final String MONGO_DB_DATABASE_NAME = "MONGO_DB_DATABASE_NAME";
private String BearerToken = "";
......@@ -53,7 +57,7 @@ public class AwsLegalTagUtils extends LegalTagUtils {
try {
s3Client.putObject(BUCKET_NAME_AWS, String.format("%s/%s", dataPartitionId, FILE_NAME), readTestFile("TenantConfigTestingPurpose.json"));
} catch(IOException e){
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
......@@ -79,21 +83,7 @@ public class AwsLegalTagUtils extends LegalTagUtils {
doc.setDescription("Expired integration test tag");
doc.setName(integrationTagTestName);
doc.setId(Integer.toString(integrationTagTestName.hashCode()));
org.opengroup.osdu.core.common.model.legal.Properties properties = new org.opengroup.osdu.core.common.model.legal.Properties();
List countryOfOrigin = new ArrayList();
Date date = new Date(1234567898765L);
countryOfOrigin.add("US");
properties.setCountryOfOrigin(countryOfOrigin);
properties.setContractId("A1234");
properties.setExpirationDate(date);
properties.setOriginator("MyCompany");
properties.setDataType("Transferred Data");
properties.setSecurityClassification("Public");
properties.setPersonalData("No Personal Data");
properties.setExportClassification("EAR99");
doc.setProperties(properties);
doc.setProperties(getLegalTagProperties());
doc.setDataPartitionId(getMyDataPartition());
String dynamoDbRegion = System.getenv(DYNAMO_DB_REGION);
......@@ -103,10 +93,44 @@ public class AwsLegalTagUtils extends LegalTagUtils {
DynamoDBQueryHelperV2 queryHelper = new DynamoDBQueryHelperV2(dynamoDbEndpoint, dynamoDbRegion, table);
// delete legal tag if it exists
if(queryHelper.keyExistsInTable(LegalDoc.class, doc)){
if (queryHelper.keyExistsInTable(LegalDoc.class, doc)) {
queryHelper.deleteByPrimaryKey(LegalDoc.class, doc.getId(), doc.getDataPartitionId());
}
queryHelper.save(doc);
}
public void insertExpiredLegalTagMongoDb() {
// directly create expired legal tag document
String integrationTagTestName = String.format("%s-dps-integration-test-1566474656479", getMyDataPartition()); // name has to match what's hardcoded in the test
String mongoDbConnectionUrl = System.getenv(MONGO_DB_CONNECTION_URL);
String mongoDbDatabaseName = System.getenv(MONGO_DB_DATABASE_NAME);
MongoDbSimpleTestFactory mongoDBSimpleFactory = new MongoDbSimpleTestFactory();
BasicMongoDBHelper basicMongoDBHelper = mongoDBSimpleFactory.getHelper(mongoDbConnectionUrl, mongoDbDatabaseName);
LegalTag legalTag = new LegalTag();
legalTag.setName(integrationTagTestName);
legalTag.setId((long) integrationTagTestName.hashCode());
legalTag.setDefaultId();
legalTag.setDescription("Expired integration test tag");
legalTag.setProperties(getLegalTagProperties());
basicMongoDBHelper.save(legalTag, COLLECTION_PREFIX + System.getenv("MY_TENANT"));
}
private org.opengroup.osdu.core.common.model.legal.Properties getLegalTagProperties(){
org.opengroup.osdu.core.common.model.legal.Properties properties = new org.opengroup.osdu.core.common.model.legal.Properties();
List<String> countryOfOrigin = new ArrayList<>();
Date date = new Date(1234567898765L);
countryOfOrigin.add("US");
properties.setCountryOfOrigin(countryOfOrigin);
properties.setContractId("A1234");
properties.setExpirationDate(date);
properties.setOriginator("MyCompany");
properties.setDataType("Transferred Data");
properties.setSecurityClassification("Public");
properties.setPersonalData("No Personal Data");
properties.setExportClassification("EAR99");
return properties;
}
}
// Copyright MongoDB, Inc or its affiliates. All Rights Reserved.
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.legal.util.mongo;
import org.opengroup.osdu.core.aws.mongodb.MongoDBSimpleFactory;
import org.opengroup.osdu.core.aws.mongodb.helper.BasicMongoDBHelper;
import org.springframework.data.mongodb.MongoDatabaseFactory;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory;
public class MongoDbSimpleTestFactory extends MongoDBSimpleFactory {
public BasicMongoDBHelper getHelper(String url, String dbName) {
MongoDatabaseFactory mongoFactory = new SimpleMongoClientDatabaseFactory(this.mongoClient(url), dbName);
MongoTemplate mongoTemplate = super.mongoTemplate(mongoFactory);
return new BasicMongoDBHelper(mongoTemplate);
}
}
Supports Markdown
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