README.md 6.99 KB
Newer Older
Rustam Lotsmanenko (EPAM)'s avatar
Rustam Lotsmanenko (EPAM) committed
1
2
# Backup service

3
Backup service provide a set of APIs  to back up Schedule, list registered Schedules, list available Backups, restore Asset state from Backup.
Rustam Lotsmanenko (EPAM)'s avatar
Rustam Lotsmanenko (EPAM) committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

In implementation were used datastore admin API : https://cloud.google.com/datastore/docs/reference/admin/rest

## Getting Started
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

### Prerequisites
Pre-requisites

* GCloud SDK with java (latest version)
* JDK 8
* Lombok 1.16 or later
* Maven

### Installation
In order to run the service locally or remotely, you will need to have the following environment variables defined.

| name | value | description | sensitive? | source |
| ---  | ---   | ---         | ---        | ---    |
23
| `OSDU_ENTITLEMENTS_URL` | ex `https://os-entitlements-gcp-jvmvia5dea-uc.a.run.app/entitlements/v1` | Entitlements API endpoint | no | output of infrastructure deployment |
Rustam Lotsmanenko (EPAM)'s avatar
Rustam Lotsmanenko (EPAM) committed
24
| `GCP_BACKUP_BUCKET` | ex `osdu-cicd-epam-backup-service` | Storage bucket for backups | no | https://console.cloud.google.com/storage |
Rustam Lotsmanenko (EPAM)'s avatar
Rustam Lotsmanenko (EPAM) committed
25
26
| `GCP_PROJECT_ID` | ex `osdu-cicd-epam` | GCP project id | no | - |
| `GOOGLE_APPLICATION_CREDENTIALS` | ex `/path/to/directory/service-key.json` | Service account credentials, you only need this if running locally | yes | https://console.cloud.google.com/iam-admin/serviceaccounts |
27
| `SPRING_CLOUD_GCP_DATASTORE_NAMESPACE` | ex `opendes` | The namespace of the datastore to keep backup configurations | no |  |
Igor Filippov (EPAM)'s avatar
Igor Filippov (EPAM) committed
28
29
30
31
| `SPRING_CLOUD_GCP_SQL_DATABASENAME` | ex `postgres` | The name of the database to connect | yes |  |
| `SPRING_CLOUD_GCP_SQL_INSTANCECONNECTIONNAME` | ex `xxx-xx-xxxx:us-central1:test-mysql` | Connection name | yes |  |
| `GCP_SQL_BACKUP_KIND` | ex `sql#backupRun` |  | yes |  |
| `GCP_SQL_RESTORE_BACKUP_KIND` | ex `sql#restoreBackupContext` |  | yes |  |
32
33
34
| `GOOGLE_AUDIENCES` | ex `*****.apps.googleusercontent.com` | Client ID for getting access to cloud resources | yes | https://console.cloud.google.com/apis/credentials |
| `PARTITION_API` | ex `http://localhost:8081/api/partition/v1` | Partition service endpoint | no | - |
  
35
36
37
38
39
40
41
42
43
Schedulers can be configured with following variables, if not defined default values will be used

| name | value | description | default |
| ---  | ---   | ---         |  ---    |
| `OSDU_SCHEDULER_TEAR-DOWN-TIME-UNIT` | ex `seconds OR minutes OR hours etc` | Time unit for tear down scheduler | `hours`  |
| `OSDU_SCHEDULER_TEAR-DOWN-PERIOD` | ex `24` | The period with which expired backups will be deleted | `24` |
| `OSDU_SCHEDULER_BACKUP-TIME-UNIT` | ex `seconds OR minutes OR hours etc` | Time unit for backup export scheduler (Period will be configured with saved schedule) | `hours` |
| `OSDU_SCHEDULER_INITIAL-DELAY` | ex `1` | Delay before start exporting new added assets, helpful for int tests, to not overwhelm backup storage | `1` |

Rustam Lotsmanenko (EPAM)'s avatar
Rustam Lotsmanenko (EPAM) committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
### Run Locally
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
...
```

You may need to configure access to the remote maven repository that holds the OSDU dependencies. This file should live within `~/.mvn/community-maven.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>community-maven-via-private-token</id>
            <!-- Treat this auth token like a password. Do not share it with anyone, including Microsoft support. -->
            <!-- The generated token expires on or before 11/14/2019 -->
             <configuration>
              <httpHeaders>
                  <property>
                      <name>Private-Token</name>
                      <value>${env.COMMUNITY_MAVEN_TOKEN}</value>
                  </property>
              </httpHeaders>
             </configuration>
        </server>
    </servers>
</settings>
```
* Update the Google cloud SDK to the latest version:

```bash
gcloud components update
```
* Set Google Project Id:

```bash
gcloud config set project <YOUR-PROJECT-ID>
```

* Perform a basic authentication in the selected project:

```bash
gcloud auth application-default login
```

* Navigate to Backup service's root folder and run:

```bash
mvn clean install   
```

* If you wish to build the project without running tests

```bash
mvn clean install -DskipTests
```

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.*

```bash
cd provider/backup-gcp && mvn spring-boot:run
```
114
115
116
117
118
119
120
121
122
## Testing
 
 ### Running E2E Tests 
 This section describes how to run cloud OSDU E2E tests (testing/backup-test-gcp).
 
 You will need to have the following environment variables defined.
 
 | name | value | description | sensitive? | source |
 | ---  | ---   | ---         | ---        | ---    |
123
 | `BACKUP_SERVICE_HOST` | ex`http://localhost:8080` | Service endpoint | no | - |
124
 | `DATA_PARTITION_ID` | `opendes` | OSDU tenant used for testing | no | - |
125
 | `INTEGRATION_TESTER` | ex`ew0KIC***` | Service account for API calls as Base64 encoded string | yes | https://console.cloud.google.com/iam-admin/serviceaccounts |
126
 | `INTEGRATION_TEST_AUDIENCE` | `****` | client application ID | yes | https://console.cloud.google.com/apis/credentials |
127

128
129
130
 
 **Entitlements configuration for integration accounts**
 
131
132
133
 | INTEGRATION_TESTER |
 | ---  | 
 | users<br/>service.backup.admin| 
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
 
 
 Execute following command to build code and run all the integration tests:
 
 ```bash
 # Note: this assumes that the environment variables for integration tests as outlined
 #       above are already exported in your environment.
 # build + install integration test core
 $ (cd testing/backup-test-core/ && mvn clean install)
 ```
 ```bash
 # build + run GCP integration tests.
 $ (cd testing/backup-test-gcp/ && mvn clean test)
 ```

## Deployment

* To deploy into Cloud run, please, use this documentation:
https://cloud.google.com/run/docs/quickstarts/build-and-deploy

* To deploy into App Engine, please, use this documentation:
https://cloud.google.com/appengine/docs/flexible/java/quickstart
Rustam Lotsmanenko (EPAM)'s avatar
Rustam Lotsmanenko (EPAM) committed
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173

## License

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

    https://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.