Commit f63d4827 authored by Abhishek Kumar's avatar Abhishek Kumar
Browse files

Merge remote-tracking branch 'origin/master' into springweb-whitesource-issue-slb

parents 2be5f6fc 6443f666
Pipeline #66274 failed with stages
in 37 minutes and 3 seconds
......@@ -308,6 +308,7 @@ The following software have components provided under the terms of this license:
- Cloud Storage JSON API v1-rev20210127-1.31.5 (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-storage)
- CloudWatch Metrics for AWS Java SDK (from https://aws.amazon.com/sdkforjava)
- Converter: Jackson (from https://repo1.maven.org/maven2/com/squareup/retrofit2/converter-jackson)
- Core Reactor components (from https://github.com/reactor/reactor)
- Core functionality for the Reactor Netty library (from https://github.com/reactor/reactor-netty)
- Elastic JNA Distribution (from https://github.com/java-native-access/jna)
- FindBugs-jsr305 (from http://findbugs.sourceforge.net/)
......@@ -316,7 +317,7 @@ The following software have components provided under the terms of this license:
- Google Cloud Core (from https://github.com/googleapis/java-core)
- Google Cloud Core HTTP (from https://github.com/googleapis/java-core)
- Google Cloud Core gRPC (from https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-core-grpc)
- Google Cloud Datastore (from https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-datastore)
- Google Cloud Datastore (from https://github.com/googleapis/java-datastore)
- Google Cloud Key Management Service (KMS) API v1-rev9-1.22.0 (from https://repo1.maven.org/maven2/com/google/apis/google-api-services-cloudkms)
- Google Cloud Logging (from https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-logging)
- Google Cloud Pub/Sub (from https://github.com/googleapis/java-pubsub)
......@@ -335,7 +336,7 @@ The following software have components provided under the terms of this license:
- Hibernate Validator Engine (from https://repo1.maven.org/maven2/org/hibernate/validator/hibernate-validator)
- HttpClient (from http://hc.apache.org/httpcomponents-client)
- HttpClient Cache (from http://hc.apache.org/httpcomponents-client)
- HttpCore (from http://hc.apache.org/httpcomponents-core-ga/)
- HttpCore (from http://hc.apache.org/httpcomponents-core-ga)
- IBM COS Java SDK for Amazon S3 (from https://github.com/ibm/ibm-cos-sdk-java)
- IBM COS Java SDK for COS KMS (from https://github.com/ibm/ibm-cos-sdk-java)
- IBM COS SDK For Java (from https://github.com/ibm/ibm-cos-sdk-java)
......@@ -354,10 +355,10 @@ The following software have components provided under the terms of this license:
- Jackson 2 extensions to the Google HTTP Client Library for Java. (from https://repo1.maven.org/maven2/com/google/http-client/google-http-client-jackson2)
- Jackson dataformat: CBOR (from http://github.com/FasterXML/jackson-dataformats-binary)
- Jackson dataformat: CBOR (from http://github.com/FasterXML/jackson-dataformats-binary)
- Jackson datatype: JSR310 (from http://wiki.fasterxml.com/JacksonModuleJSR310)
- Jackson datatype: JSR310 (from https://repo1.maven.org/maven2/com/fasterxml/jackson/datatype/jackson-datatype-jsr310)
- Jackson datatype: jdk8 (from https://repo1.maven.org/maven2/com/fasterxml/jackson/datatype/jackson-datatype-jdk8)
- Jackson module: Afterburner (from https://github.com/FasterXML/jackson-modules-base)
- Jackson module: JAXB-annotations (from http://github.com/FasterXML/jackson-module-jaxb-annotations)
- Jackson module: JAXB Annotations (from https://github.com/FasterXML/jackson-modules-base)
- Jackson-annotations (from http://github.com/FasterXML/jackson)
- Jackson-core (from https://github.com/FasterXML/jackson-core)
- Jackson-dataformat-Smile (from http://wiki.fasterxml.com/JacksonForSmile)
......@@ -430,14 +431,11 @@ The following software have components provided under the terms of this license:
- Nimbus JOSE+JWT (from https://bitbucket.org/connect2id/nimbus-jose-jwt)
- Nimbus JOSE+JWT (from https://bitbucket.org/connect2id/nimbus-jose-jwt)
- Nimbus LangTag (from https://bitbucket.org/connect2id/nimbus-language-tags)
- Non-Blocking Reactive Foundation for the JVM (from https://github.com/reactor/reactor)
- OAuth 2.0 SDK with OpenID Connect extensions (from https://bitbucket.org/connect2id/oauth-2.0-sdk-with-openid-connect-extensions)
- OAuth 2.0 SDK with OpenID Connect extensions (from https://bitbucket.org/connect2id/oauth-2.0-sdk-with-openid-connect-extensions)
- Objenesis (from http://objenesis.org)
- Objenesis (from http://objenesis.org)
- OkHttp Logging Interceptor (from https://repo1.maven.org/maven2/com/squareup/okhttp3/logging-interceptor)
- Okio (from https://github.com/square/okio/)
- Okio (from https://github.com/square/okio/)
- OpenCensus (from https://github.com/census-instrumentation/opencensus-java)
- OpenCensus (from https://github.com/census-instrumentation/opencensus-java)
- OpenCensus (from https://github.com/census-instrumentation/opencensus-java)
......@@ -454,6 +452,8 @@ The following software have components provided under the terms of this license:
- Spring AOP (from https://github.com/spring-projects/spring-framework)
- Spring Beans (from https://github.com/spring-projects/spring-framework)
- Spring Beans (from https://github.com/spring-projects/spring-framework)
- Spring Boot Security Starter (from http://projects.spring.io/spring-boot/)
- Spring Boot Security Starter (from http://projects.spring.io/spring-boot/)
- Spring Boot Tomcat Starter (from https://projects.spring.io/spring-boot/#/spring-boot-parent/spring-boot-starters/spring-boot-starter-tomcat)
- Spring Boot Tomcat Starter (from https://projects.spring.io/spring-boot/#/spring-boot-parent/spring-boot-starters/spring-boot-starter-tomcat)
- Spring Commons Logging Bridge (from https://github.com/spring-projects/spring-framework)
......@@ -493,12 +493,12 @@ The following software have components provided under the terms of this license:
- boto3 (from https://github.com/boto/boto3)
- botocore (from https://github.com/boto/botocore)
- cli (from https://github.com/elastic/elasticsearch)
- com.google.api.grpc:proto-google-cloud-datastore-v1 (from https://github.com/googleapis/googleapis)
- compiler (from http://github.com/spullara/mustache.java)
- core (from https://github.com/elastic/elasticsearch)
- core (from https://github.com/elastic/elasticsearch)
- datastore-v1-proto-client (from https://repo1.maven.org/maven2/com/google/cloud/datastore/datastore-v1-proto-client)
- elasticsearch-core (from https://github.com/elastic/elasticsearch)
- elasticsearch-geo (from https://github.com/elastic/elasticsearch)
- elasticsearch-x-content (from https://github.com/elastic/elasticsearch)
- error-prone annotations (from https://repo1.maven.org/maven2/com/google/errorprone/error_prone_annotations)
- error-prone annotations (from https://repo1.maven.org/maven2/com/google/errorprone/error_prone_annotations)
- google-auth (from https://github.com/googleapis/google-auth-library-python)
......@@ -532,11 +532,14 @@ The following software have components provided under the terms of this license:
- mockito-core (from https://github.com/mockito/mockito)
- okhttp (from https://square.github.io/okhttp/)
- okhttp-urlconnection (from https://github.com/square/okhttp)
- okio (from https://github.com/square/okio/)
- okio (from https://github.com/square/okio/)
- org.apiguardian:apiguardian-api (from https://github.com/apiguardian-team/apiguardian)
- org.opentest4j:opentest4j (from https://github.com/ota4j-team/opentest4j)
- org.xmlunit:xmlunit-core (from https://www.xmlunit.org/)
- org.xmlunit:xmlunit-core (from http://www.xmlunit.org/)
- parent-join (from https://github.com/elastic/elasticsearch)
- project ':json-path' (from https://github.com/jayway/JsonPath)
- proto-google-cloud-datastore-v1 (from https://github.com/googleapis/java-datastore/proto-google-cloud-datastore-v1)
- proto-google-cloud-logging-v2 (from https://repo1.maven.org/maven2/com/google/api/grpc/proto-google-cloud-logging-v2)
- proto-google-cloud-pubsub-v1 (from https://github.com/googleapis/java-pubsub/proto-google-cloud-pubsub-v1)
- proto-google-common-protos (from https://github.com/googleapis/java-iam/proto-google-common-protos)
......@@ -545,8 +548,8 @@ The following software have components provided under the terms of this license:
- requests (from https://requests.readthedocs.io)
- resilience4j (from https://resilience4j.readme.io)
- resilience4j (from https://resilience4j.readme.io)
- resilience4j (from https://github.com/resilience4j/resilience4j)
- resilience4j (from https://github.com/resilience4j/resilience4j)
- resilience4j (from https://resilience4j.readme.io)
- resilience4j (from https://resilience4j.readme.io)
- resilience4j (from https://resilience4j.readme.io)
- resilience4j (from https://resilience4j.readme.io)
- resilience4j (from https://resilience4j.readme.io)
......@@ -576,8 +579,6 @@ The following software have components provided under the terms of this license:
- spring-boot-starter-log4j2 (from https://spring.io/projects/spring-boot)
- spring-boot-starter-logging (from https://spring.io/projects/spring-boot)
- spring-boot-starter-reactor-netty (from https://spring.io/projects/spring-boot)
- spring-boot-starter-security (from https://spring.io/projects/spring-boot)
- spring-boot-starter-security (from https://spring.io/projects/spring-boot)
- spring-boot-starter-test (from https://spring.io/projects/spring-boot)
- spring-boot-starter-test (from https://spring.io/projects/spring-boot)
- spring-boot-starter-validation (from https://spring.io/projects/spring-boot)
......@@ -610,7 +611,6 @@ The following software have components provided under the terms of this license:
- swagger-models (from https://repo1.maven.org/maven2/io/swagger/swagger-models)
- tomcat-embed-core (from http://tomcat.apache.org/)
- tomcat-embed-websocket (from http://tomcat.apache.org/)
- x-content (from https://github.com/elastic/elasticsearch)
========================================================================
BSD-2-Clause
......
FROM google/cloud-sdk:slim
COPY ./devops/gcp/bootstrap-osdu-module/bootstrap_schema.sh /opt
COPY ./deployments /opt/
RUN chmod 775 /opt/bootstrap_schema.sh
RUN pip3 install -r /opt/scripts/requirements.txt && pip3 install -r /opt/scripts/gcp-deployment-requirements.txt
CMD ["/bin/bash", "-c", "source /opt/bootstrap_schema.sh"]
## Prerequisites
* create workload identity gke service account (it is mandatory that bootstrap script will be running from SA)
* kubernetes job should be create in namespace that is free from istio-injection (job will be in RUNNING state indefenetly with side-car container)
* set all required ENV variables, they are listed in job.yml under env directive
## Verify
Schema service bootstrap is based on python bootstrap scripts at schema service repository -> `https://community.opengroup.org/osdu/platform/system/schema-service/-/tree/master/deployments/scripts`
Boostrap scripts contains python script which executes clean-up on Datastore to prevent incorect bootstrap for schema service.
After execution of bootstrap-script, you could go to **GCP console** and look for logs under `Kubernetes Engine -> Workloads -> bootstrap-schema pod`
Successful execution will lead to similar output (disclaimer: output could be different due to changes at python3 bootstrap scripts)
```
The kind osdu:wks:work-product-component--WellboreTrajectory:1.0.0 was registered successfully.
Try POST for id: osdu:wks:work-product-component--WellboreTrajectory:1.1.0
The kind osdu:wks:work-product-component--WellboreTrajectory:1.1.0 was registered successfully.
Try POST for id: osdu:wks:reference-data--WellboreTrajectoryType:1.0.0
The kind osdu:wks:reference-data--WellboreTrajectoryType:1.0.0 was registered successfully.
Try POST for id: osdu:wks:reference-data--WordFormatType:1.0.0
The kind osdu:wks:reference-data--WordFormatType:1.0.0 was registered successfully.
Try POST for id: osdu:wks:work-product--WorkProduct:1.0.0
The kind osdu:wks:work-product--WorkProduct:1.0.0 was registered successfully.
This update took 156.52 seconds.
All 216 schemas registered, updated or left unchanged because of status PUBLISHED.
```
Additionally new **Datastore Entities** should be created:
Go to `Datastore -> Entitites -> Namespace (dataecosystem) -> Kind (schema)`, this kind should be populated with schema records.
#!/usr/bin/env bash
set -ex
export BEARER_TOKEN=`gcloud auth print-identity-token --audiences=${AUDIENCES}`
echo "Clean-up for Datastore schemas"
python3 /opt/scripts/GcpDatastoreCleanUp.py
sleep 5
echo "Bootstrap Schema Service"
python3 /opt/scripts/DeploySharedSchemas.py -u ${SCHEMA_URL}/api/schema-service/v1/schema
......@@ -22,3 +22,24 @@ osdu-gcp-test:
only:
variables:
- $OSDU_GCP == 'true'
containerize_osdu_gcp_schema_bootstrap:
stage: containerize
image: docker:19.03.15
tags: ["osdu-medium"]
services:
- docker:20.10.7-dind
script:
- export EXTRA_DOCKER_TAG=""; if [ "$CI_COMMIT_TAG" != "" ] ; then EXTRA_DOCKER_TAG="-t $CI_REGISTRY_IMAGE/osdu-gcp-bootstrap:$CI_COMMIT_TAG" ; elif [ "$CI_COMMIT_REF_NAME" = "master" ] ; then EXTRA_DOCKER_TAG="-t $CI_REGISTRY_IMAGE/osdu-gcp-bootstrap:latest" ; fi
- docker build -t $CI_REGISTRY_IMAGE/osdu-gcp-bootstrap:$CI_COMMIT_SHORT_SHA $EXTRA_DOCKER_TAG --file devops/$OSDU_GCP_VENDOR/bootstrap-osdu-module/Dockerfile .
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker push $CI_REGISTRY_IMAGE/osdu-gcp-bootstrap
only:
refs:
- master
- /.*bootstrap.*/
- tags
variables:
- $OSDU_GCP == 'true'
......@@ -20,13 +20,17 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import org.joda.time.DateTime;
import org.opengroup.osdu.azure.eventgrid.EventGridTopicStore;
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.DpsHeaders;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory;
import org.opengroup.osdu.schema.azure.di.EventGridConfig;
import org.opengroup.osdu.schema.azure.di.SystemResourceConfig;
import org.opengroup.osdu.schema.azure.impl.messagebus.model.SchemaPubSubInfo;
import org.opengroup.osdu.schema.constants.SchemaConstants;
import org.opengroup.osdu.schema.logging.AuditLogger;
......@@ -49,15 +53,26 @@ public class MessageBusImpl implements IMessageBus {
private AuditLogger auditLogger;
@Autowired
DpsHeaders headers;
@Autowired
private ITenantFactory tenantFactory;
@Autowired
SystemResourceConfig systemResourceConfig;
private final static String EVENT_DATA_VERSION = "1.0";
@Override
public void publishMessage(String schemaId, String eventType) {
// This if block will be removed once schema-core starts consuming *System* methods.
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
this.publishMessageForSystemSchema(schemaId, eventType);
return;
}
if (eventGridConfig.isEventGridEnabled()) {
logger.info("Generating event of type {}",eventType);
try {
publishToEventGrid(schemaId, eventType);
publishToEventGrid(schemaId, eventType, headers.getPartitionId());
auditLogger.schemaNotificationSuccess(Collections.singletonList(schemaId));
}catch (AppException ex) {
......@@ -71,7 +86,38 @@ public class MessageBusImpl implements IMessageBus {
}
}
private void publishToEventGrid(String schemaId, String eventType) {
/**
* Method to publish schema create notification for system schemas.
* @param schemaId
* @param eventType
*/
@Override
public void publishMessageForSystemSchema(String schemaId, String eventType) {
if (eventGridConfig.isEventGridEnabled()) {
logger.info("Generating event of type {}",eventType);
try {
// Publish the event for all the tenants.
List<String> privateTenantList = tenantFactory.listTenantInfo().stream().map(TenantInfo::getName)
.collect(Collectors.toList());
for (String tenant : privateTenantList) {
publishToEventGrid(schemaId, eventType, tenant);
}
auditLogger.schemaNotificationSuccess(Collections.singletonList(schemaId));
}catch (AppException ex) {
//We do not want to fail schema creation if notification delivery has failed, hence just logging the exception
auditLogger.schemaNotificationFailure(Collections.singletonList(schemaId));
logger.warning(SchemaConstants.SCHEMA_NOTIFICATION_FAILED);
}
}else {
logger.info(SchemaConstants.SCHEMA_NOTIFICATION_IS_DISABLED);
}
}
private void publishToEventGrid(String schemaId, String eventType, String dataPartitionId) {
String messageId = UUID.randomUUID().toString();
SchemaPubSubInfo[] schemaPubSubMsgs = new SchemaPubSubInfo [1];
......@@ -79,8 +125,8 @@ public class MessageBusImpl implements IMessageBus {
List<EventGridEvent> eventsList = new ArrayList<>();
HashMap<String, Object> message = new HashMap<>();
message.put("data", schemaPubSubMsgs);
message.put(DpsHeaders.ACCOUNT_ID, headers.getPartitionIdWithFallbackToAccountId());
message.put(DpsHeaders.DATA_PARTITION_ID, headers.getPartitionIdWithFallbackToAccountId());
message.put(DpsHeaders.ACCOUNT_ID, dataPartitionId);
message.put(DpsHeaders.DATA_PARTITION_ID, dataPartitionId);
message.put(DpsHeaders.CORRELATION_ID, headers.getCorrelationId());
//EventGridEvent supports array of messages to be triggered in a batch but at present we do not support
......@@ -95,7 +141,7 @@ public class MessageBusImpl implements IMessageBus {
);
eventsList.add(eventGridEvent);
logger.info("Schema event created: " + messageId);
eventGridTopicStore.publishToEventGridTopic(headers.getPartitionId(), eventGridConfig.getCustomTopicName(), eventsList);
eventGridTopicStore.publishToEventGridTopic(dataPartitionId, eventGridConfig.getCustomTopicName(), eventsList);
logger.info("Schema event generated successfully");
}
......
......@@ -72,17 +72,32 @@ public class AzureAuthorityStore implements IAuthorityStore {
*/
@Override
public Authority get(String authorityId) throws NotFoundException, ApplicationException {
// This if block will be removed once schema-core starts consuming *System* methods.
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
return this.getSystemAuthority(authorityId);
}
String id = headers.getPartitionId() + ":" + authorityId;
AuthorityDoc authorityDoc;
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
authorityDoc = cosmosStore.findItem(systemResourceConfig.getCosmosDatabase(), authorityContainer, id, authorityId, AuthorityDoc.class)
.orElseThrow(() -> new NotFoundException("bad input parameter"));
} else {
authorityDoc = cosmosStore.findItem(headers.getPartitionId(), cosmosDBName, authorityContainer, id, authorityId, AuthorityDoc.class)
.orElseThrow(() -> new NotFoundException("bad input parameter"));
}
authorityDoc = cosmosStore.findItem(headers.getPartitionId(), cosmosDBName, authorityContainer, id, authorityId, AuthorityDoc.class)
.orElseThrow(() -> new NotFoundException("bad input parameter"));
return authorityDoc.getAuthority();
}
/**
* Method to get system Authority
* @param authorityId
* @return
* @throws NotFoundException
* @throws ApplicationException
*/
@Override
public Authority getSystemAuthority(String authorityId) throws NotFoundException, ApplicationException {
AuthorityDoc authorityDoc;
authorityDoc = cosmosStore.findItem(systemResourceConfig.getCosmosDatabase(), authorityContainer, authorityId, authorityId, AuthorityDoc.class)
.orElseThrow(() -> new NotFoundException("bad input parameter"));
return authorityDoc.getAuthority();
}
......@@ -96,27 +111,52 @@ public class AzureAuthorityStore implements IAuthorityStore {
*/
@Override
public Authority create(Authority authority) throws ApplicationException, BadRequestException {
// This if block will be removed once schema-core starts consuming *System* methods.
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
return this.createSystemAuthority(authority);
}
String id = headers.getPartitionId() + ":" + authority.getAuthorityId();
try {
AuthorityDoc authorityDoc = new AuthorityDoc(id, authority);
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
cosmosStore.createItem(systemResourceConfig.getCosmosDatabase(), authorityContainer, id, authorityDoc);
} else {
cosmosStore.createItem(headers.getPartitionId(), cosmosDBName, authorityContainer, id, authorityDoc);
}
cosmosStore.createItem(headers.getPartitionId(), cosmosDBName, authorityContainer, id, authorityDoc);
} catch (AppException ex) {
if (ex.getError().getCode() == 409) {
log.warning(SchemaConstants.AUTHORITY_EXISTS_ALREADY_REGISTERED);
throw new BadRequestException(MessageFormat.format(SchemaConstants.AUTHORITY_EXISTS_EXCEPTION,
authority.getAuthorityId()));
} else {
log.error(MessageFormat.format(SchemaConstants.OBJECT_INVALID, ex.getMessage()));
throw new ApplicationException(SchemaConstants.INVALID_INPUT);
}
handleAppException(ex, authority);
}
log.info(SchemaConstants.AUTHORITY_CREATED);
return authority;
}
/**
* Method to register a System Authority
* @param authority
* @return
* @throws ApplicationException
* @throws BadRequestException
*/
@Override
public Authority createSystemAuthority(Authority authority) throws ApplicationException, BadRequestException {
try {
AuthorityDoc authorityDoc = new AuthorityDoc(authority.getAuthorityId(), authority);
cosmosStore.createItem(systemResourceConfig.getCosmosDatabase(), authorityContainer, authority.getAuthorityId(), authorityDoc);
} catch (AppException ex) {
handleAppException(ex, authority);
}
log.info(SchemaConstants.AUTHORITY_CREATED);
return authority;
}
private void handleAppException(AppException ex, Authority authority) throws ApplicationException, BadRequestException {
if (ex.getError().getCode() == 409) {
log.warning(SchemaConstants.AUTHORITY_EXISTS_ALREADY_REGISTERED);
throw new BadRequestException(MessageFormat.format(SchemaConstants.AUTHORITY_EXISTS_EXCEPTION,
authority.getAuthorityId()));
} else {
log.error(MessageFormat.format(SchemaConstants.OBJECT_INVALID, ex.getMessage()));
throw new ApplicationException(SchemaConstants.INVALID_INPUT);
}
}
}
......@@ -69,17 +69,31 @@ public class AzureEntityTypeStore implements IEntityTypeStore {
*/
@Override
public EntityType get(String entityTypeId) throws NotFoundException, ApplicationException {
// This if block will be removed once schema-core starts consuming *System* methods.
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
return this.getSystemEntity(entityTypeId);
}
String id = headers.getPartitionId() + ":" + entityTypeId;
EntityTypeDoc entityTypeDoc;
entityTypeDoc = cosmosStore.findItem(headers.getPartitionId(), cosmosDBName, entityTypeContainer, id, entityTypeId, EntityTypeDoc.class)
.orElseThrow(() -> new NotFoundException("bad input parameter"));
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
entityTypeDoc = cosmosStore.findItem(systemResourceConfig.getCosmosDatabase(), entityTypeContainer, id, entityTypeId, EntityTypeDoc.class)
.orElseThrow(() -> new NotFoundException("bad input parameter"));
} else {
entityTypeDoc = cosmosStore.findItem(headers.getPartitionId(), cosmosDBName, entityTypeContainer, id, entityTypeId, EntityTypeDoc.class)
.orElseThrow(() -> new NotFoundException("bad input parameter"));
}
return entityTypeDoc.getEntityType();
}
/**
* Method to get system Entity
* @param entityTypeId
* @return
* @throws NotFoundException
* @throws ApplicationException
*/
@Override
public EntityType getSystemEntity(String entityTypeId) throws NotFoundException, ApplicationException {
EntityTypeDoc entityTypeDoc;
entityTypeDoc = cosmosStore.findItem(systemResourceConfig.getCosmosDatabase(), entityTypeContainer, entityTypeId, entityTypeId, EntityTypeDoc.class)
.orElseThrow(() -> new NotFoundException("bad input parameter"));
return entityTypeDoc.getEntityType();
}
......@@ -93,27 +107,51 @@ public class AzureEntityTypeStore implements IEntityTypeStore {
*/
@Override
public EntityType create(EntityType entityType) throws BadRequestException, ApplicationException {
String id = headers.getPartitionId() + ":" + entityType.getEntityTypeId();
// This if block will be removed once schema-core starts consuming *System* methods.
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
return this.createSystemEntity(entityType);
}
String id = headers.getPartitionId() + ":" + entityType.getEntityTypeId();
try {
EntityTypeDoc entityTypeDoc = new EntityTypeDoc(id, entityType);
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
cosmosStore.createItem(systemResourceConfig.getCosmosDatabase(), entityTypeContainer, id, entityTypeDoc);
} else {
cosmosStore.createItem(headers.getPartitionId(), cosmosDBName, entityTypeContainer, id, entityTypeDoc);
}
cosmosStore.createItem(headers.getPartitionId(), cosmosDBName, entityTypeContainer, id, entityTypeDoc);
} catch (AppException ex) {
if (ex.getError().getCode() == 409) {
log.warning(SchemaConstants.ENTITY_TYPE_EXISTS);
throw new BadRequestException(MessageFormat.format(SchemaConstants.ENTITY_TYPE_EXISTS_EXCEPTION,
entityType.getEntityTypeId()));
} else {
log.error(MessageFormat.format(SchemaConstants.OBJECT_INVALID, ex.getMessage()));
throw new ApplicationException(SchemaConstants.INVALID_INPUT);
}
handleAppException(ex, entityType);
}
log.info(SchemaConstants.ENTITY_TYPE_CREATED);
return entityType;
}
/**
* Method to create a system Entity
* @param entityType
* @return
* @throws BadRequestException
* @throws ApplicationException
*/
@Override
public EntityType createSystemEntity(EntityType entityType) throws BadRequestException, ApplicationException {
try {
EntityTypeDoc entityTypeDoc = new EntityTypeDoc(entityType.getEntityTypeId(), entityType);
cosmosStore.createItem(systemResourceConfig.getCosmosDatabase(), entityTypeContainer, entityType.getEntityTypeId(), entityTypeDoc);
} catch (AppException ex) {
handleAppException(ex, entityType);
}
log.info(SchemaConstants.ENTITY_TYPE_CREATED);
return entityType;
}
private void handleAppException(AppException ex, EntityType entityType) throws BadRequestException, ApplicationException {
if (ex.getError().getCode() == 409) {
log.warning(SchemaConstants.ENTITY_TYPE_EXISTS);
throw new BadRequestException(MessageFormat.format(SchemaConstants.ENTITY_TYPE_EXISTS_EXCEPTION,
entityType.getEntityTypeId()));
} else {
log.error(MessageFormat.format(SchemaConstants.OBJECT_INVALID, ex.getMessage()));
throw new ApplicationException(SchemaConstants.INVALID_INPUT);
}
}
}
......@@ -67,17 +67,32 @@ public class AzureSourceStore implements ISourceStore {
*/
@Override
public Source get(String sourceId) throws NotFoundException, ApplicationException {
// This if block will be removed once schema-core starts consuming *System* methods.
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
return this.getSystemSource(sourceId);
}
String id = headers.getPartitionId().toString() + ":" + sourceId;
SourceDoc sourceDoc;
sourceDoc = cosmosStore.findItem(headers.getPartitionId(), cosmosDBName, sourceContainer, id, sourceId, SourceDoc.class)
.orElseThrow(() -> new NotFoundException("bad input parameter"));
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
sourceDoc = cosmosStore.findItem(systemResourceConfig.getCosmosDatabase(), sourceContainer, id, sourceId, SourceDoc.class)
.orElseThrow(() -> new NotFoundException("bad input parameter"));
} else {
sourceDoc = cosmosStore.findItem(headers.getPartitionId(), cosmosDBName, sourceContainer, id, sourceId, SourceDoc.class)
.orElseThrow(() -> new NotFoundException("bad input parameter"));
}
return sourceDoc.getSource();
}
/**
* Method to get system Source
* @param sourceId
* @return
* @throws NotFoundException
* @throws ApplicationException
*/
@Override
public Source getSystemSource(String sourceId) throws NotFoundException, ApplicationException {
SourceDoc sourceDoc;
sourceDoc = cosmosStore.findItem(systemResourceConfig.getCosmosDatabase(), sourceContainer, sourceId, sourceId, SourceDoc.class)
.orElseThrow(() -> new NotFoundException("bad input parameter"));
return sourceDoc.getSource();
}
......@@ -91,27 +106,52 @@ public class AzureSourceStore implements ISourceStore {
*/
@Override
public Source create(Source source) throws BadRequestException, ApplicationException {
// This if block will be removed once schema-core starts consuming *System* methods.
if (systemResourceConfig.getSharedTenant().equalsIgnoreCase(headers.getPartitionId())) {
return this.createSystemSource(source);
}