You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by is...@apache.org on 2021/05/13 12:25:42 UTC
[airavata-data-lake] 06/30: Adding repository support for SFTP
Remotes
This is an automated email from the ASF dual-hosted git repository.
isjarana pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-data-lake.git
commit ace1dc1bdfd9b3058574686cb1fc719901700bd8
Author: Dimuthu Wannipurage <di...@gmail.com>
AuthorDate: Tue Jan 5 19:00:19 2021 -0500
Adding repository support for SFTP Remotes
---
data-orchestrator/data-orchestrator-api/pom.xml | 19 +++
.../api/controller/remote/SFTPController.java | 46 +++++--
.../api/db/entity/SFTPCredentialEntity.java | 140 +++++++++++++++++++++
.../api/db/entity/SFTPRemoteEntity.java | 92 ++++++++++++++
.../api/db/repo/SFTPCredentialRepository.java | 26 ++++
.../api/db/repo/SFTPRemoteRepository.java | 26 ++++
6 files changed, 337 insertions(+), 12 deletions(-)
diff --git a/data-orchestrator/data-orchestrator-api/pom.xml b/data-orchestrator/data-orchestrator-api/pom.xml
index c840c04..e6433cb 100644
--- a/data-orchestrator/data-orchestrator-api/pom.xml
+++ b/data-orchestrator/data-orchestrator-api/pom.xml
@@ -41,6 +41,25 @@
<dependency>
<groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-data-jpa</artifactId>
+ <version>2.4.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>net.sf.dozer</groupId>
+ <artifactId>dozer</artifactId>
+ <version>5.5.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <version>1.4.197</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
diff --git a/data-orchestrator/data-orchestrator-api/src/main/java/org/apache/airavata/datalake/orchestrator/api/controller/remote/SFTPController.java b/data-orchestrator/data-orchestrator-api/src/main/java/org/apache/airavata/datalake/orchestrator/api/controller/remote/SFTPController.java
index 5492889..e7bced6 100644
--- a/data-orchestrator/data-orchestrator-api/src/main/java/org/apache/airavata/datalake/orchestrator/api/controller/remote/SFTPController.java
+++ b/data-orchestrator/data-orchestrator-api/src/main/java/org/apache/airavata/datalake/orchestrator/api/controller/remote/SFTPController.java
@@ -19,39 +19,61 @@
*/
package org.apache.airavata.datalake.orchestrator.api.controller.remote;
-import org.apache.airavata.datalake.orchestrator.api.model.remote.SFTPCredential;
+import org.apache.airavata.datalake.orchestrator.api.db.entity.SFTPRemoteEntity;
+import org.apache.airavata.datalake.orchestrator.api.db.repo.SFTPRemoteRepository;
import org.apache.airavata.datalake.orchestrator.api.model.remote.SFTPRemote;
+import org.dozer.DozerBeanMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
+import org.springframework.web.server.ResponseStatusException;
+
+import java.util.Optional;
@RestController
@RequestMapping(path = "/remotes/sftp")
public class SFTPController {
+ @Autowired
+ private SFTPRemoteRepository sftpRemoteRepository;
+
@GetMapping(value = "/{remoteId}", produces = "application/json")
public SFTPRemote fetchSFTPRemote(@PathVariable(name = "remoteId") String remoteId) {
- return new SFTPRemote()
- .setHost("localhost")
- .setPort(22)
- .setCredential(
- new SFTPCredential()
- .setAuthMethod(SFTPCredential.AuthMethod.SSH_KEY)
- .setPrivateKey("")
- .setPublicKey(""));
+
+ Optional<SFTPRemoteEntity> entityOp = sftpRemoteRepository.findById(remoteId);
+ SFTPRemoteEntity sftpRemoteEntity = entityOp.orElseThrow(
+ () -> new ResponseStatusException(HttpStatus.NOT_FOUND, remoteId + " not found"));
+ DozerBeanMapper mapper = new DozerBeanMapper();
+ return mapper.map(sftpRemoteEntity, SFTPRemote.class);
}
@PostMapping(value = "")
public String createSFTPRemote(@RequestBody SFTPRemote sftpRemote) {
- return "Remote id";
+
+ DozerBeanMapper mapper = new DozerBeanMapper();
+ SFTPRemoteEntity sftpRemoteEntity = mapper.map(sftpRemote, SFTPRemoteEntity.class);
+ SFTPRemoteEntity saved = sftpRemoteRepository.save(sftpRemoteEntity);
+ return saved.getId();
}
@PutMapping(value = "/{remoteId}")
public String updateSFTPRemote(@RequestBody SFTPRemote sftpRemote,
@PathVariable(name = "remoteId") String remoteId) {
- return "Remote id";
+
+ DozerBeanMapper mapper = new DozerBeanMapper();
+ SFTPRemoteEntity sftpRemoteEntity = mapper.map(sftpRemote, SFTPRemoteEntity.class);
+ sftpRemoteEntity.setId(remoteId);
+ SFTPRemoteEntity saved = sftpRemoteRepository.save(sftpRemoteEntity);
+ return saved.getId();
}
@DeleteMapping(value = "/{remoteId}")
public String removeSFTPRemote(@PathVariable(name = "remoteId") String remoteId) {
- return "Deleted";
+
+ if (! sftpRemoteRepository.existsById(remoteId)) {
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, remoteId + " not found");
+ }
+ sftpRemoteRepository.deleteById(remoteId);
+ return "Success";
}
}
diff --git a/data-orchestrator/data-orchestrator-api/src/main/java/org/apache/airavata/datalake/orchestrator/api/db/entity/SFTPCredentialEntity.java b/data-orchestrator/data-orchestrator-api/src/main/java/org/apache/airavata/datalake/orchestrator/api/db/entity/SFTPCredentialEntity.java
new file mode 100644
index 0000000..6b5a294
--- /dev/null
+++ b/data-orchestrator/data-orchestrator-api/src/main/java/org/apache/airavata/datalake/orchestrator/api/db/entity/SFTPCredentialEntity.java
@@ -0,0 +1,140 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.airavata.datalake.orchestrator.api.db.entity;
+
+import org.hibernate.annotations.GenericGenerator;
+
+import javax.persistence.*;
+import java.util.List;
+
+@Entity
+public class SFTPCredentialEntity {
+
+ @Id
+ @GeneratedValue(generator = "uuid")
+ @GenericGenerator(name = "uuid", strategy = "uuid2")
+ @Column(name = "ID")
+ private String id;
+
+ @Column(name = "USER_NAME")
+ private String userName;
+
+ @Column(name = "EXISTING_KEY_ID")
+ private String existingKeyId;
+
+ @Column(name = "PUBLIC_KEY")
+ private String publicKey;
+
+ @Column(name = "PRIVATE_KEY")
+ private String privateKey;
+
+ @Column(name = "PASSPHRASE")
+ private String passphrase;
+
+ @Column(name = "PASSWORD")
+ private String password;
+
+ @Column(name = "AUTH_METHOD")
+ private String authMethod;
+
+ @OneToMany(mappedBy = "credential", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
+ private List<SFTPRemoteEntity> sftpRemotes;
+
+ public String getId() {
+ return id;
+ }
+
+ public SFTPCredentialEntity setId(String id) {
+ this.id = id;
+ return this;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public SFTPCredentialEntity setUserName(String userName) {
+ this.userName = userName;
+ return this;
+ }
+
+ public String getExistingKeyId() {
+ return existingKeyId;
+ }
+
+ public SFTPCredentialEntity setExistingKeyId(String existingKeyId) {
+ this.existingKeyId = existingKeyId;
+ return this;
+ }
+
+ public String getPublicKey() {
+ return publicKey;
+ }
+
+ public SFTPCredentialEntity setPublicKey(String publicKey) {
+ this.publicKey = publicKey;
+ return this;
+ }
+
+ public String getPrivateKey() {
+ return privateKey;
+ }
+
+ public SFTPCredentialEntity setPrivateKey(String privateKey) {
+ this.privateKey = privateKey;
+ return this;
+ }
+
+ public String getPassphrase() {
+ return passphrase;
+ }
+
+ public SFTPCredentialEntity setPassphrase(String passphrase) {
+ this.passphrase = passphrase;
+ return this;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public SFTPCredentialEntity setPassword(String password) {
+ this.password = password;
+ return this;
+ }
+
+ public String getAuthMethod() {
+ return authMethod;
+ }
+
+ public SFTPCredentialEntity setAuthMethod(String authMethod) {
+ this.authMethod = authMethod;
+ return this;
+ }
+
+ public List<SFTPRemoteEntity> getSftpRemotes() {
+ return sftpRemotes;
+ }
+
+ public SFTPCredentialEntity setSftpRemotes(List<SFTPRemoteEntity> sftpRemotes) {
+ this.sftpRemotes = sftpRemotes;
+ return this;
+ }
+}
diff --git a/data-orchestrator/data-orchestrator-api/src/main/java/org/apache/airavata/datalake/orchestrator/api/db/entity/SFTPRemoteEntity.java b/data-orchestrator/data-orchestrator-api/src/main/java/org/apache/airavata/datalake/orchestrator/api/db/entity/SFTPRemoteEntity.java
new file mode 100644
index 0000000..2ab128b
--- /dev/null
+++ b/data-orchestrator/data-orchestrator-api/src/main/java/org/apache/airavata/datalake/orchestrator/api/db/entity/SFTPRemoteEntity.java
@@ -0,0 +1,92 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.airavata.datalake.orchestrator.api.db.entity;
+
+import org.hibernate.annotations.GenericGenerator;
+
+import javax.persistence.*;
+
+@Entity
+public class SFTPRemoteEntity {
+
+ @Id
+ @GeneratedValue(generator = "uuid")
+ @GenericGenerator(name = "uuid", strategy = "uuid2")
+ @Column(name = "ID")
+ private String id;
+
+ @Column(name = "NAME")
+ private String name;
+
+ @Column(name = "HOST")
+ private String host;
+
+ @Column(name = "PORT")
+ private Integer port;
+
+ @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
+ @JoinColumn(name = "CREDENTIAL_ID")
+ private SFTPCredentialEntity credential;
+
+ public String getId() {
+ return id;
+ }
+
+ public SFTPRemoteEntity setId(String id) {
+ this.id = id;
+ return this;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public SFTPRemoteEntity setName(String name) {
+ this.name = name;
+ return this;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public SFTPRemoteEntity setHost(String host) {
+ this.host = host;
+ return this;
+ }
+
+ public Integer getPort() {
+ return port;
+ }
+
+ public SFTPRemoteEntity setPort(Integer port) {
+ this.port = port;
+ return this;
+ }
+
+ public SFTPCredentialEntity getCredential() {
+ return credential;
+ }
+
+ public SFTPRemoteEntity setCredential(SFTPCredentialEntity credential) {
+ this.credential = credential;
+ return this;
+ }
+}
diff --git a/data-orchestrator/data-orchestrator-api/src/main/java/org/apache/airavata/datalake/orchestrator/api/db/repo/SFTPCredentialRepository.java b/data-orchestrator/data-orchestrator-api/src/main/java/org/apache/airavata/datalake/orchestrator/api/db/repo/SFTPCredentialRepository.java
new file mode 100644
index 0000000..7548008
--- /dev/null
+++ b/data-orchestrator/data-orchestrator-api/src/main/java/org/apache/airavata/datalake/orchestrator/api/db/repo/SFTPCredentialRepository.java
@@ -0,0 +1,26 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.airavata.datalake.orchestrator.api.db.repo;
+
+import org.apache.airavata.datalake.orchestrator.api.db.entity.SFTPCredentialEntity;
+import org.springframework.data.repository.CrudRepository;
+
+public interface SFTPCredentialRepository extends CrudRepository<SFTPCredentialEntity, String> {
+}
diff --git a/data-orchestrator/data-orchestrator-api/src/main/java/org/apache/airavata/datalake/orchestrator/api/db/repo/SFTPRemoteRepository.java b/data-orchestrator/data-orchestrator-api/src/main/java/org/apache/airavata/datalake/orchestrator/api/db/repo/SFTPRemoteRepository.java
new file mode 100644
index 0000000..04aa5bb
--- /dev/null
+++ b/data-orchestrator/data-orchestrator-api/src/main/java/org/apache/airavata/datalake/orchestrator/api/db/repo/SFTPRemoteRepository.java
@@ -0,0 +1,26 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.airavata.datalake.orchestrator.api.db.repo;
+
+import org.apache.airavata.datalake.orchestrator.api.db.entity.SFTPRemoteEntity;
+import org.springframework.data.repository.CrudRepository;
+
+public interface SFTPRemoteRepository extends CrudRepository<SFTPRemoteEntity, String> {
+}