Commit 91c497e8 authored by neelesh thakur's avatar neelesh thakur
Browse files

Merge branch 'osdu-delfi-changes' into 'master'

osdu-delfi updates

See merge request !2
parents 6a37c366 72a08c0f
Pipeline #7798 passed with stages
in 6 minutes and 13 seconds
swagger: '2.0'
info:
description: API documentation for Partition service
version: '1.0.0'
title: Partition
contact:
name: OSDU Support
email: devportal-help@osdu.com
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0'
basePath: /api/partition/v1
tags:
- name: partition-api
description: Partition Api
- name: health-check
description: Health Check
paths:
/_ah/liveness_check:
get:
tags:
- health-check
summary: livenessCheck
operationId: livenessCheckUsingGET
consumes:
- application/json
produces:
- application/json
responses:
'200':
description: OK
schema:
type: string
'401':
description: Unauthorized
'403':
description: Forbidden
'404':
description: Not Found
security:
- JWT:
- global
/_ah/readiness_check:
get:
tags:
- health-check
summary: readinessCheck
operationId: readinessCheckUsingGET
consumes:
- application/json
produces:
- application/json
responses:
'200':
description: OK
schema:
type: string
'401':
description: Unauthorized
'403':
description: Forbidden
'404':
description: Not Found
security:
- JWT:
- global
'/partitions/{partitionId}':
get:
tags:
- partition-api
summary: get
operationId: getUsingGET
consumes:
- application/json
produces:
- application/json
parameters:
- name: partitionId
in: path
description: partitionId
required: true
type: string
responses:
'200':
description: OK
schema:
$ref: '#/definitions/PartitionInfo'
'401':
description: Unauthorized
'403':
description: Forbidden
'404':
description: Not Found
security:
- JWT:
- global
post:
tags:
- partition-api
summary: create
operationId: createUsingPOST
consumes:
- application/json
produces:
- application/json
parameters:
- name: partitionId
in: path
description: partitionId
required: true
type: string
- in: body
name: partitionInfo
description: partitionInfo
required: true
schema:
$ref: '#/definitions/PartitionInfo'
responses:
'200':
description: OK
schema:
$ref: '#/definitions/PartitionInfo'
'201':
description: Created
'401':
description: Unauthorized
'403':
description: Forbidden
'404':
description: Not Found
security:
- JWT:
- global
delete:
tags:
- partition-api
summary: delete
operationId: deleteUsingDELETE
consumes:
- application/json
produces:
- application/json
parameters:
- name: partitionId
in: path
description: partitionId
required: true
type: string
responses:
'204':
description: No Content
'401':
description: Unauthorized
'403':
description: Forbidden
security:
- JWT:
- global
securityDefinitions:
JWT:
type: oauth2
name: Authorization
in: header
definitions:
PartitionInfo:
type: object
properties:
labels:
type: object
description: 'Free form key value pair object for any data partition specific values'
example:
id: 'common'
compliance-ruleset: 'shared'
elastic-username: 'elastic'
cosmos-endpoint: 'https://ado-dev-n-abc123-cosmosdb.documents.azure.com:443/'
elastic-endpoint: 'https://partition-dev.evd.ece-osdu.cloud.osdu-ds.com:9243'
storage-account-name: 'myStorageAccount'
\ No newline at end of file
## Partition Service
## Table of Contents <a name="TOC"></a>
* [Introduction](#introduction)
* [Checking Service Health](#checking-service-health)
* [Partition API access](#partition-api-access)
* [APIs](#apis)
* [Get partition details](#get-partition)
* [Create a new partition](#create-partition)
* [Delete an existing partition](#delete-partition)
## Introduction <a name="introduction"></a>
Partition service is responsible for creating and retrieving the partition specific properties (secret and non-secret) on behalf of other services.
## Health Check <a name="checking-service-health"></a>
An endpoint to check if service is up and running.
```
GET api/partition/v1/_ah/liveness_check
```
<details><summary>curl</summary>
```
curl --request GET \
--url 'https://<base_url>/api/partition/v1/_ah/liveness_check'
```
</details>
## Partition API access <a name="partition-api-access"></a>
As Partition service APIs are mostly consumed by other services, API access is limited to admins/service accounts only.
## APIs <a name="apis"></a>
### Get partition details<a name="get-partition"></a>
Consuming services can use this API to get details of a partition. Partition details consists of a set of key-value pairs of properties.
```
GET api/partition/v1/partitions/{partitionId}
```
<details><summary>curl</summary>
```
curl --request GET \
--url 'https://<base_url>/api/partition/v1/partitions/common' \
--header 'Authorization: Bearer <JWT>' \
--header 'Content-Type: application/json'
```
</details>
A sample output is shown below.
<details><summary>Sample response</summary>
```
{
"elastic-username": "elastic",
"elastic-endpoint": "test-elastic-endpoint",
"compliance-ruleset": "shared",
"storage-account-name": "sampleAcc",
"elastic-password": "test-password",
"storage-account-key": "sampleKey",
"id": "common"
}
```
</details>
[Back to Table of Contents](#TOC)
### Create a new partition<a name="create-partition"></a>
This api can be used to create a new partition. A plausible use case would be partition provisioning infrastructure script.
```
POST api/partition/v1/partitions/{partitionId}
```
<details><summary>curl</summary>
```
curl --request POST \
--url 'https://<base_url>/api/partition/v1/partitions/mypartition' \
--header 'Authorization: Bearer <JWT>' \
--header 'Content-Type: application/json' \
--data-raw '{
"properties":
{
"elasticPassword": "test-password",
"elasticUsername": "elastic",
"elasticEndpoint": "test-elastic-endpoint",
"complianceRuleSet": "shared",
"storageAccountKey": "test-storage-key",
"id": "mypartition"
}
}'
```
</details>
### Delete an existing partition<a name="delete-partition"></a>
This api is used to delete an existing partition. A plausible use case would be partition teardown infrastructure script.
```
DELETE api/partition/v1/partitions/{partitionId}
```
<details><summary>curl</summary>
```
curl --request DELETE \
--url 'https://<base_url>/api/partition/v1/partitions/mypartition' \
--header 'Authorization: Bearer <JWT>' \
--header 'Content-Type: application/json'
```
</details>
\ No newline at end of file
......@@ -21,7 +21,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/_ah")
@RequestMapping(path= "/_ah", produces = "application/json")
public class HealthCheck {
@GetMapping("/liveness_check")
......
......@@ -17,6 +17,7 @@ package org.opengroup.osdu.partition.api;
import org.opengroup.osdu.partition.model.PartitionInfo;
import org.opengroup.osdu.partition.provider.interfaces.IPartitionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
......@@ -27,10 +28,11 @@ import java.util.Map;
@RestController
@RequestScope
@RequestMapping("/partitions")
@RequestMapping(path = "/partitions", produces = "application/json")
public class PartitionApi {
@Autowired
@Qualifier("cachedPartitionServiceImpl")
private IPartitionService partitionService;
@PostMapping("/{partitionId}")
......
// Copyright 2017-2020, Schlumberger
//
// 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.partition.provider.interfaces;
import org.opengroup.osdu.core.common.cache.ICache;
import org.opengroup.osdu.partition.model.PartitionInfo;
public interface IPartitionServiceCache extends ICache<String, PartitionInfo> {
}
// Copyright 2017-2020, Schlumberger
//
// 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.partition.service;
import org.opengroup.osdu.partition.model.PartitionInfo;
import org.opengroup.osdu.partition.provider.interfaces.IPartitionService;
import org.opengroup.osdu.partition.provider.interfaces.IPartitionServiceCache;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import javax.inject.Inject;
@Service
public class CachedPartitionServiceImpl implements IPartitionService {
@Inject
@Qualifier("partitionServiceImpl")
private IPartitionService partitionService;
@Inject
private IPartitionServiceCache partitionServiceCache;
@Override
public PartitionInfo createPartition(String partitionId, PartitionInfo partitionInfo) {
PartitionInfo pi = partitionService.createPartition(partitionId, partitionInfo);
if (pi != null) {
partitionServiceCache.put(partitionId, partitionInfo);
}
return pi;
}
@Override
public PartitionInfo getPartition(String partitionId) {
PartitionInfo pi = partitionServiceCache.get(partitionId);
if (pi == null) {
pi = partitionService.getPartition(partitionId);
if (pi != null) {
partitionServiceCache.put(partitionId, pi);
}
}
return pi;
}
@Override
public boolean deletePartition(String partitionId) {
if (partitionService.deletePartition(partitionId)) {
if (partitionServiceCache.get(partitionId) != null) {
partitionServiceCache.delete(partitionId);
}
return true;
}
return false;
}
}
// Copyright 2017-2020, Schlumberger
//
// 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.partition.service;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.opengroup.osdu.partition.model.PartitionInfo;
import org.opengroup.osdu.partition.provider.interfaces.IPartitionService;
import org.opengroup.osdu.partition.provider.interfaces.IPartitionServiceCache;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
@RunWith(MockitoJUnitRunner.class)
public class CachedPartitionServiceImplTest {
@Mock
private IPartitionService partitionServiceImpl;
@Mock
private IPartitionServiceCache partitionServiceCache;
@InjectMocks
private CachedPartitionServiceImpl cachedPartitionServiceImpl;
@Test
public void createPartitionSucceed() {
String partId = "key";
PartitionInfo newPi = PartitionInfo.builder().build();
PartitionInfo retPi = PartitionInfo.builder().build();
when(partitionServiceImpl.createPartition(partId, newPi)).thenReturn(retPi);
cachedPartitionServiceImpl.createPartition(partId, newPi);
verify(partitionServiceImpl, times(1)).createPartition(partId, newPi);
verify(partitionServiceCache, times(1)).put(partId, retPi);
}
@Test
public void createPartitionFailed() {
String partId = "key";
PartitionInfo newPi = PartitionInfo.builder().build();
when(partitionServiceImpl.createPartition(partId, newPi)).thenReturn(null);
cachedPartitionServiceImpl.createPartition(partId, newPi);
verify(partitionServiceImpl, times(1)).createPartition(partId, newPi);
verify(partitionServiceCache, times(0)).put(any(), any());
verify(partitionServiceCache, times(0)).get(any());
}
@Test
public void getPartition() {
String partId = "key";
PartitionInfo retPi = PartitionInfo.builder().build();
when(partitionServiceImpl.getPartition(partId)).thenReturn(retPi);
cachedPartitionServiceImpl.getPartition(partId);
verify(partitionServiceCache, times(1)).get(partId);
verify(partitionServiceImpl, times(1)).getPartition(partId);
verify(partitionServiceCache, times(1)).put(partId, retPi);
}
@Test
public void deletePartition() {
String partId = "key";
PartitionInfo retPi = PartitionInfo.builder().build();
when(partitionServiceImpl.deletePartition(partId)).thenReturn(true);
when(partitionServiceCache.get(partId)).thenReturn(retPi);
cachedPartitionServiceImpl.deletePartition(partId);
verify(partitionServiceImpl, times(1)).deletePartition(partId);
verify(partitionServiceCache, times(1)).delete(partId);
verify(partitionServiceCache, times(1)).get(partId);
}
}
\ No newline at end of file
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis-partition-master
spec:
replicas: 1
selector:
matchLabels:
app: redis-partition-master
template:
metadata:
name: redis-partition-master
labels:
app: redis-partition-master
master: "true"
spec:
volumes:
- hostPath:
path: /tmp/data/1
name: redis-directory-binding
restartPolicy: Always
containers:
- name: redis-partition-master
image: delfi.azurecr.io/redis-partition-cluster:latest
resources:
requests:
memory: "100Mi"
cpu: .2
limits:
memory: "200Mi"
cpu: .5
imagePullPolicy: Always
ports:
- containerPort: 6379
volumeMounts:
- mountPath: /redis-data
name: redis-directory-binding
readOnly: false
env:
- name: MASTER
value: "true"
imagePullSecrets:
- name: acr
\ No newline at end of file
FROM redis:latest
MAINTAINER Alok Joshi
RUN apt-get install bash \
sed
RUN mkdir /redis-master && \
mkdir /redis-slave
COPY redis-master.conf /redis-master/redis.conf
COPY redis-slave.conf /redis-slave/redis.conf
COPY entrypoint.sh /entrypoint.sh
RUN chmod 777 /entrypoint.sh
CMD [ "/entrypoint.sh" ]
ENTRYPOINT [ "bash", "-c" ]
\ No newline at end of file
#!/bin/bash
set -e
export imageName="redis-partition-cluster"
export tag="v1"