Commit dde9f6b9 authored by harshit aggarwal's avatar harshit aggarwal
Browse files

Merge branch 'master' into abpatil/dpndncy_mngmnt_az_sdk_upgrd

parents 8f9e7de5 c219e75f
Pipeline #20808 failed with stages
in 68 minutes and 38 seconds
# Copyright © Microsoft Corporation
#
# 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.
# This file contains the essential configs for the osdu on azure helm chart
global:
# Service(s) Replica Count
replicaCount: 1
################################################################################
# Specify the Gitlab branch being used for image creation
# ie: community.opengroup.org:5555/osdu/platform/system/storage/{{ .Values.global.branch }}/storage:latest
#
image:
repository: #{container-registry}#.azurecr.io
branch: #{ENVIRONMENT_NAME}#
tag: #{Build.SourceVersion}#
......@@ -94,7 +94,5 @@ spec:
value: http://entitlements-azure/entitlements/v1
- name: RECORDS_CHANGE_PUBSUB_ENDPOINT
value: https://haaggarw-eventgrid-viewer.azurewebsites.net/api/updates
- name: SUBSCRIBER_SECRET
value: "395f1b05e95171d7c0dde0b19fd6cf"
- name: ACCEPT_HTTP # TEMPORARY UNTIL HTTPS
value: "true"
\ No newline at end of file
......@@ -29,4 +29,4 @@ spec:
to:
- operation:
notPaths: ["/","*/swagger-resources","*/swagger",
"/api/register/v1/swagger-resources/*","*/swagger-ui.html","*/actuator/health","/api/register/v1/test/challenge/*"]
\ No newline at end of file
"/api/register/v1/swagger-resources/*","*/swagger-ui.html","*/actuator/health","/api/register/v1/test/challenge/*", "/api/register/v1/webjars/*", "*/v2/api-docs"]
\ No newline at end of file
# Copyright © Microsoft Corporation
#
# 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.
trigger:
batch: true
branches:
include:
- master
paths:
exclude:
- /**/*.md
- .gitignore
- /docs
- /provider/register-aws
- /provider/register-gcp
- /provider/register-ibm
resources:
repositories:
- repository: FluxRepo
type: git
name: k8-gitops-manifests
- repository: TemplateRepo
type: git
name: infra-azure-provisioning
variables:
- group: 'Azure - OSDU'
- group: 'Azure - OSDU Secrets'
- name: serviceName
value: "register"
- name: chartPath
value: "devops/azure/chart"
- name: valuesFile
value: "devops/azure/chart/helm-config.yaml"
- name: 'MANIFEST_REPO'
value: $[ resources.repositories['FluxRepo'].name ]
- name: 'MAVEN_CACHE_FOLDER'
value: $(Pipeline.Workspace)/.m2/repository
- name: SKIP_TESTS
value: 'false'
stages:
- template: /devops/build-stage.yml@TemplateRepo
parameters:
mavenGoal: 'package'
mavenPublishJUnitResults: true
serviceCoreMavenOptions: '-P register-core --settings .mvn/community-maven.settings.xml'
mavenOptions: '-P register-azure --settings .mvn/community-maven.settings.xml -Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'
copyFileContents: |
pom.xml
provider/register-azure/maven/settings.xml
provider/register-azure/pom.xml
provider/register-azure/target/*-spring-boot.jar
.mvn/community-maven.settings.xml
copyFileContentsToFlatten: ''
mavenSettingsFile: '.mvn/community-maven.settings.xml'
serviceBase: ${{ variables.serviceName }}
testingRootFolder: 'testing'
chartPath: ${{ variables.chartPath }}
- template: /devops/deploy-stages.yml@TemplateRepo
parameters:
serviceName: ${{ variables.serviceName }}
chartPath: ${{ variables.chartPath }}
valuesFile: ${{ variables.valuesFile }}
testCoreMavenPomFile: 'testing/register-test-core/pom.xml'
testCoreMavenOptions: '--settings $(System.DefaultWorkingDirectory)/drop/.mvn/community-maven.settings.xml'
skipDeploy: ${{ variables.SKIP_DEPLOY }}
skipTest: ${{ variables.SKIP_TESTS }}
providers:
- name: Azure
environments: ['dev']
# Copyright © Microsoft Corporation
#
# 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.
trigger:
batch: true
branches:
include:
- master
paths:
exclude:
- /**/*.md
- .gitignore
- /docs
- /provider/register-aws
- /provider/register-gcp
- /provider/register-ibm
resources:
repositories:
- repository: FluxRepo
type: git
name: k8-gitops-manifests
- repository: TemplateRepo
type: git
name: infra-azure-provisioning
variables:
- group: 'Azure - OSDU'
- group: 'Azure - OSDU Secrets'
- name: serviceName
value: "register"
- name: chartPath
value: "devops/azure/chart"
- name: valuesFile
value: "devops/azure/chart/helm-config.yaml"
- name: 'MANIFEST_REPO'
value: $[ resources.repositories['FluxRepo'].name ]
- name: 'MAVEN_CACHE_FOLDER'
value: $(Pipeline.Workspace)/.m2/repository
- name: SKIP_TESTS
value: 'false'
stages:
- template: /devops/build-stage.yml@TemplateRepo
parameters:
mavenGoal: 'package'
mavenPublishJUnitResults: true
serviceCoreMavenOptions: '-P register-core --settings .mvn/community-maven.settings.xml'
mavenOptions: '-P register-azure --settings .mvn/community-maven.settings.xml -Dmaven.repo.local=$(MAVEN_CACHE_FOLDER)'
copyFileContents: |
pom.xml
provider/register-azure/maven/settings.xml
provider/register-azure/pom.xml
provider/register-azure/target/*-spring-boot.jar
.mvn/community-maven.settings.xml
copyFileContentsToFlatten: ''
mavenSettingsFile: '.mvn/community-maven.settings.xml'
serviceBase: ${{ variables.serviceName }}
testingRootFolder: 'testing'
chartPath: ${{ variables.chartPath }}
- template: /devops/deploy-stages.yml@TemplateRepo
parameters:
serviceName: ${{ variables.serviceName }}
chartPath: ${{ variables.chartPath }}
valuesFile: ${{ variables.valuesFile }}
testCoreMavenPomFile: 'testing/register-test-core/pom.xml'
testCoreMavenOptions: '--settings $(System.DefaultWorkingDirectory)/drop/.mvn/community-maven.settings.xml'
skipDeploy: ${{ variables.SKIP_DEPLOY }}
skipTest: ${{ variables.SKIP_TESTS }}
providers:
- name: Azure
environments: ['demo']
Copyright © Microsoft Corporation
## os-register-azure
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
os-register-azure is a [Spring Boot](https://spring.io/projects/spring-boot) service that hosts CRUD APIs that allows consumers to register a push endpoint that can be triggered when data change events happen within the OSDU R2 ecosystem.
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.
# os-register-azure
## Running Locally
os-register-azure is a [Spring Boot](https://spring.io/projects/spring-boot) service that hosts CRUD APIs that allows consumers to register a push endpoint that can be triggered when data change events happen within the OSDU R2 ecosystem.
### Requirements
## Running locally
In order to run this service locally, you will need the following:
### Requirements
* Java 8
* [Maven 3.6.0+](https://maven.apache.org/download.cgi)
- [Maven 3.6.0+](https://maven.apache.org/download.cgi)
- [AdoptOpenJDK8](https://adoptopenjdk.net/)
### General Tips
......@@ -34,70 +24,65 @@ This project uses [Lombok](https://projectlombok.org/) for code generation. You
- [Intellij configuration](https://projectlombok.org/setup/intellij)
- [VSCode configuration](https://projectlombok.org/setup/vscode)
### Service Dependencies
- [Entitlements-azure](https://community.opengroup.org/osdu/platform/security-and-compliance/entitlements-azure)
- [Notification](https://community.opengroup.org/osdu/platform/system/notification)
### Configure Maven
Check that maven is installed:
```bash
$ mvn --version
Apache Maven 3.6.0
Maven home: /usr/share/maven
Java version: 1.8.0_212, vendor: AdoptOpenJDK, runtime: /usr/lib/jvm/jdk8u212-b04/jre
...
```
### Entitlements
You will need to configure access to the remote maven repository that holds the OSDU dependencies. This file should live within `~/.m2/settings.xml`:
```bash
$ cat ~/.m2/settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>os-core</id>
<username>slb-des-ext-collaboration</username>
<!-- Treat this auth token like a password. Do not share it with anyone, including Microsoft support. -->
<password>${VSTS_FEED_TOKEN}</password>
</server>
</servers>
</settings>
```
| name | description
| --- | --- |
| `users.datalake.admin` | Entitles users to access all the API's in register |
### Environment Variables
### Understanding Environment Variables
In order to run the service locally, you will need to have the following environment variables defined.
**System Environment required to run service**
Refer to [application.properties](./src/main/resources/application.properties)
Definitions for some variables used
**Required to run service**
| name | value | description | sensitive? | source |
| --- | --- | --- | --- | --- |
| `LOG_PREFIX` | `storage` | Logging prefix | no | - |
| `server.servlet.contextPath` | `/api/storage/v2/` | Servlet context path | no | - |
| `AUTHORIZE_API` | ex `https://foo-entitlements.azurewebsites.net` | Entitlements API endpoint | no | output of infrastructure deployment |
| `AUTHORIZE_API_KEY` | `********` | The API key clients will need to use when calling the entitlements | yes | -- |
| `azure.application-insights.instrumentation-key` | `********` | API Key for App Insights | yes | output of infrastructure deployment |
| `azure.activedirectory.client-id` | `********` | AAD client application ID | yes | output of infrastructure deployment |
| `azure.activedirectory.AppIdUri` | `api://${azure.activedirectory.client-id}` | URI for AAD Application | no | -- |
| `azure.activedirectory.session-stateless` | `true` | Flag run in stateless mode (needed by AAD dependency) | no | -- |
| `cosmosdb_account` | ex `devintosdur2cosmosacct` | Cosmos account name | no | output of infrastructure deployment |
| `cosmosdb_key` | `********` | Key for CosmosDB | yes | output of infrastructure deployments |
| `cosmosdb_database` | ex `dev-osdu-r2-db` | Cosmos database for storage documents | no | output of infrastructure deployment |
| `azure.storage.account-name` | ex `foo-storage-account` | Storage account for storing documents | no | output of infrastructure deployment |
| `azure.storage.enable-https` | `true` | Used by spring boot starter library | no | - |
| `servicebus_topic_name` | `recordstopic` | Topic for async messaging | no | output of infrastructure deployment |
| `servicebus_namespace_name` | ex `foo-sb-namespace` | Namespace for async messaging | no | output of infrastructure deployment |
| `KEYVAULT_URI` | ex `https://foo-keyvault.vault.azure.net/` | URI of KeyVault that holds application secrets | no | output of infrastructure deployment |
| `LOG_PREFIX` | `register` | Logging prefix | no | - |
| `server.servlet.contextPath` | `/api/register/v1/` | Servlet context path | no | - |
| `AZURE_CLIENT_ID` | `********` | Identity to run the service locally. This enables access to Azure resources. You only need this if running locally | yes | keyvault secret: `$KEYVAULT_URI/secrets/app-dev-sp-username` |
| `AZURE_TENANT_ID` | `********` | AD tenant to authenticate users from | yes | keyvault secret: `$KEYVAULT_URI/secrets/app-dev-sp-tenant-id` |
| `AZURE_TENANT_ID` | `********` | AD tenant to authenticate users from | yes | -- |
| `AZURE_CLIENT_SECRET` | `********` | Secret for `$AZURE_CLIENT_ID` | yes | keyvault secret: `$KEYVAULT_URI/secrets/app-dev-sp-password` |
| `KEY_IDENTIFIER` | `******` | Key Identifier for key used for encryption/decryption | yes | - |
| `AZURE_RESOURCE_GROUP_NAME` | `********` | Resource group name for event grid system topic | no | -- |
| `AZURE_SUBSCRIPTION_ID` | `******` | Azure tenant subscription id| no | -- |
| `KEYVAULT_URL` | ex `https://foo-keyvault.vault.azure.net/` | URI of KeyVault that holds application secrets | no | output of infrastructure deployment |
| `appinsights_key` | `********` | API Key for App Insights | yes | output of infrastructure deployment |
| `cosmosdb_database` | ex `foo-db` | The name of the CosmosDB database | no | output of infrastructure deployment |
| `spring.application.name` | `register-azure` | Name of application. Needed by App Insights | no | -- |
| `ENTITLEMENTS_API` | `https://entitlements.azurewebsites.net/entitlements/v1` | Entitlements API endpoint | no | -- |
| `server_port` | ex `8082` | Port the service will run on | no | -- |
| `RECORDS_CHANGE_PUBSUB_ENDPOINT` | ex `https://notification.azurewebsites.net/api/notification/v1/push-handler/records-changed` | This will be the notification service endpoint where record changed events will be pushed | no | -- |
| `ACCEPT_HTTP` | ex `true/false` | to Enable/disable http requests | no | -- |
**Required to run integration tests**
| name | value | description | sensitive? | source |
| --- | --- | --- | --- | --- |
| `REGISTER_BASE_URL` | ex `http://localhost:8080/` | The host where the service is running | no | -- |
| `INTEGRATION_TESTER` | `********` | System identity to assume for API calls. Note: this user must have entitlements configured already | no | -- |
| `TESTER_SERVICEPRINCIPAL_SECRET` | `********` | Secret for `$INTEGRATION_TESTER` | yes | -- |
| `AZURE_AD_TENANT_ID` | `********` | AD tenant to authenticate users from | yes | -- |
| `AZURE_AD_APP_RESOURCE_ID` | `********` | AAD client application ID | yes | output of infrastructure deployment |
| `NO_DATA_ACCESS_TESTER` | `********` | Service principal ID of a service principal without entitlements | yes | `aad-no-data-access-tester-client-id` secret from keyvault |
| `NO_DATA_ACCESS_TESTER_SERVICEPRINCIPAL_SECRET` | `********` | Secret for `$NO_DATA_ACCESS_TESTER` | yes | `aad-no-data-access-tester-secret` secret from keyvault |
| `AZURE_STORAGE_ACCOUNT` | ex `foo-storage-account` | Storage account for storing documents | no | output of infrastructure deployment |
| `ENVIRONMENT` | ex local/dev | environment type | no | - |
| `SUBSCRIBER_SECRET` | ex '****' | e: This secret is required for test API, it is required in SubscriberTestListenerApi endpoints to verify HMAC signature | no | - |
| `TEST_TOPIC_NAME` | ex `records-topic` | the event grid topic name | no | - |
| `SUBSCRIPTION_ID` | ex `` | Base64 encoded string formed by concatenating pushEndpoint and topic name [Reference](https://community.opengroup.org/osdu/platform/system/register/-/blob/master/register-core/src/main/java/org/opengroup/osdu/register/subscriber/services/CreateSubscription.java#L54) | no | - |
### Configure Maven
Check that maven is installed:
```bash
$ mvn --version
Apache Maven 3.6.0
Maven home: /usr/share/maven
Java version: 1.8.0_212, vendor: AdoptOpenJDK, runtime: /usr/lib/jvm/jdk8u212-b04/jre
...
```
### Build and run the application
After configuring your environment as specified above, you can follow these steps to build and run the application. These steps should be invoked from the *repository root*.
......@@ -117,5 +102,28 @@ $ mvn spring-boot:run -Dspring-boot.run.profiles=local
$ cd provider/register-azure/ && java -jar target\register-azure-1.0.0-spring-boot.jar
```
### Debugging
Jet Brains - the authors of Intellij IDEA, have written an [excellent guide](https://www.jetbrains.com/help/idea/debugging-your-first-java-application.html) on how to debug java programs.
### Test the application
After the service has started it should be accessible via a web browser by visiting [http://localhost:8080/api/register/v1/swagger-ui.html](http://localhost:8080/api/register/v1/swagger-ui.html). If the request does not fail, you can then run the integration tests.
\ No newline at end of file
After the service has started it should be accessible via a web browser by visiting [http://localhost:8080/api/register/v1/swagger-ui.html](http://localhost:8080/api/register/v1/swagger-ui.html). If the request does not fail, you can then run the integration tests.
### Commands to run tests
* Integration tests are refactored into two pieces: Core and Provider. Core contains business logic for tests and is a dependency for executing the tests from provider module. To build the core module, simply navigate to `register-test-core` directory and run `mvn clean install`. This will build the core module
* Next, to execute the integration tests, navigate to the provider module and execute `mvn test`. Make sure the above environment variables are already set before running maven command
## License
Copyright © Microsoft Corporation
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](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.
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright © Microsoft Corporation
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.
-->
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>azure-auth</id>
<configuration>
<tenant>${AZURE_DEPLOY_TENANT}</tenant>
<client>${AZURE_DEPLOY_CLIENT_ID}</client>
<key>${AZURE_DEPLOY_CLIENT_SECRET}</key>
<environment>AZURE</environment>
</configuration>
</server>
</servers>
</settings>
......@@ -27,6 +27,7 @@
<artifactId>register-azure</artifactId>
<description>Register service on Azure</description>
<packaging>jar</packaging>
<version>1.0.0-SNAPSHOT</version>
<properties>
<azure.appservice.resourcegroup></azure.appservice.resourcegroup>
<azure.appservice.plan></azure.appservice.plan>
......
......@@ -50,6 +50,7 @@ INTEGRATION_TEST_AUDIENCES=
CRON_JOB_EXPECTED_IP=0:0:0:0:0:0:0:1
SUBSCRIBER_PRIVATE_KEY_ID=
ENVIRONMENT=LOCAL
SUBSCRIBER_SECRET=395f1b05e95171d7c0dde0b19fd6cf
management.health.defaults.enabled=false
management.health.azure-key-vault.enabled=false
......
......@@ -20,12 +20,12 @@ steps:
'build',
'--build-arg', 'PROVIDER_NAME=${_PROVIDER_NAME}',
'--build-arg', 'PORT=${_PORT}',
'-t', 'gcr.io/$PROJECT_ID/os-register/register-${_PROVIDER_NAME}:${_SHORT_SHA}',
'-t', 'gcr.io/$PROJECT_ID/os-register/register-${_PROVIDER_NAME}:latest',
'-f', 'provider/register-${_PROVIDER_NAME}/cloudbuild/Dockerfile.cloudbuild',
'-t', 'gcr.io/$PROJECT_ID/${_APPLICATION_NAME}/${_GCP_SERVICE}-${_PROVIDER_NAME}:${_SHORT_SHA}',
'-t', 'gcr.io/$PROJECT_ID/${_APPLICATION_NAME}/${_GCP_SERVICE}-${_PROVIDER_NAME}:latest',
'-f', 'provider/${_GCP_SERVICE}-${_PROVIDER_NAME}/cloudbuild/Dockerfile.cloudbuild',
'.'
]
images:
- 'gcr.io/$PROJECT_ID/os-register/register-${_PROVIDER_NAME}'
- 'gcr.io/$PROJECT_ID/${_APPLICATION_NAME}/${_GCP_SERVICE}-${_PROVIDER_NAME}'
/*
Copyright 2020 Google LLC
Copyright 2020 EPAM Systems, Inc
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.register.provider.gcp;
import org.springframework.boot.SpringApplication;
......
......@@ -36,6 +36,8 @@ import java.util.List;
@Repository
public class DatastoreActionRepo implements IActionRepo {
private static final String CONFLICT_REASON = "Conflict";
@Getter
private static final String NAMESPACE = "DE";
@Getter
......@@ -103,7 +105,7 @@ public class DatastoreActionRepo implements IActionRepo {
if (ex.getMessage().startsWith("too much contention")) {
return throwConflict();
} else {
throw new AppException(409, "Conflict", "ABORTED due to conflict");
throw new AppException(409, CONFLICT_REASON, "ABORTED due to conflict");
}
} else
throw ex;
......@@ -116,7 +118,7 @@ public class DatastoreActionRepo implements IActionRepo {
}
private Action throwConflict() {
throw new AppException(409, "Conflict", "An action already exists with the same message and endpoint combination");
throw new AppException(409, CONFLICT_REASON, "An action already exists with the same message and endpoint combination");
}
private boolean deleteFromDatastore(String id) {
......@@ -135,9 +137,9 @@ public class DatastoreActionRepo implements IActionRepo {
} catch (DatastoreException ex) {
if (ex.getCode() == 10) {
if (ex.getMessage().startsWith("too much contention")) {
throw new AppException(409, "Conflict", "Another request is trying to delete the same DDMS.");
throw new AppException(409, CONFLICT_REASON, "Another request is trying to delete the same DDMS.");
} else {
throw new AppException(409, "Conflict", "ABORTED due to conflict");
throw new AppException(409, CONFLICT_REASON, "ABORTED due to conflict");
}
} else
throw ex;
......@@ -210,17 +212,11 @@ public class DatastoreActionRepo implements IActionRepo {
private FullEntity convertActionToEntity(Action action, Key key) {
List<StringValue> types = new ArrayList<>();
action.getFilter().getEntityType().forEach((t) -> {
types.add(new StringValue(t));
});
action.getFilter().getEntityType().forEach(t -> types.add(new StringValue(t)));
List<StringValue> source = new ArrayList<>();
action.getFilter().getSource().forEach((t) -> {
source.add(new StringValue(t));
});
action.getFilter().getSource().forEach(t -> source.add(new StringValue(t)));
List<StringValue> version = new ArrayList<>();
action.getFilter().getVersion().forEach((t) -> {
version.add(new StringValue(t));
});
action.getFilter().getVersion().forEach(t -> version.add(new StringValue(t)));
FullEntity.Builder entity = FullEntity.newBuilder(key)
.set(NAME, action.getName())
......
......@@ -44,6 +44,7 @@ public class DatastoreDdmsRepository implements IDdmsRepository {
private static final String TYPE = "type";
private static final String SCHEMA = "schema";
private static final String INTERFACE_KIND = "DMS_INTERFACE";
private static final String CONFLICT_REASON = "Conflict";
@Autowired
private DatastoreMultiTenantAccess dataStoreTenants;
......@@ -60,15 +61,15 @@ public class DatastoreDdmsRepository implements IDdmsRepository {
try {
Entity existingEntity = txn.get(entity.getKey());
if (existingEntity != null)
throw new AppException(409, "Conflict", "A DDMS already exists with the same id");
throw new AppException(409, CONFLICT_REASON, "A DDMS already exists with the same id");
txn.put(entity);
txn.commit();
} catch (DatastoreException ex) {
if (ex.getCode() == 10) {
if (ex.getMessage().startsWith("too much contention")) {
throw new AppException(409, "Conflict", "A DDMS already exists with the same id");
throw new AppException(409, CONFLICT_REASON, "A DDMS already exists with the same id");
} else {
throw new AppException(409, "Conflict", "ABORTED due to conflict");
throw new AppException(409, CONFLICT_REASON, "ABORTED due to conflict");
}
} else
throw ex;
......@@ -124,9 +125,9 @@ public class DatastoreDdmsRepository implements IDdmsRepository {
} catch (DatastoreException ex) {
if (ex.getCode() == 10) {
if (ex.getMessage().startsWith("too much contention")) {
throw new AppException(409, "Conflict", "Another request is trying to delete the same DDMS.");
throw new AppException(409, CONFLICT_REASON, "Another request is trying to delete the same DDMS.");
} else {
throw new AppException(409, "Conflict", "ABORTED due to conflict");
throw new AppException(409, CONFLICT_REASON, "ABORTED due to conflict");
}
} else
throw ex;
......