Skip to content
Permalink
Browse files
Adding file based backends for services for local testing. Adding fil…
…e based spring context files
  • Loading branch information
DImuthuUpe committed Mar 13, 2020
1 parent bc70f2a commit 17be4b3c658295fa516409e3c424b12f454457f2
Show file tree
Hide file tree
Showing 35 changed files with 578 additions and 142 deletions.
@@ -20,10 +20,10 @@ agent.id=agent0
agent.host=localhost
agent.user=dimuthu
agent.supported.protocols=SCP,LOCAL
consul.host=localhost
consul.host=149.165.156.124
consul.port=8500

resource.service.host=localhost
resource.service.host=149.165.156.124
resource.service.port=7002
secret.service.host=localhost
secret.service.host=149.165.156.124
secret.service.port=7003
@@ -14,5 +14,5 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
consul.host=localhost
consul.host=149.165.156.124
consul.port=8500
@@ -54,6 +54,11 @@
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>

<build>
@@ -80,6 +85,20 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<excludes>
<exclude>**/*.properties</exclude>
<exclude>**/*.xml</exclude>
<exclude>**/*.sh</exclude>
<exclude>**/*.json</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>

@@ -58,6 +58,8 @@
<includes>
<include>application.properties</include>
<include>logback.xml</include>
<include>applicationContext.xml</include>
<include>resources.json</include>
</includes>
</fileSet>
<fileSet>
@@ -17,17 +17,9 @@

package org.apache.airavata.mft.resource.server;

import org.apache.airavata.mft.resource.server.backend.ResourceBackend;
import org.apache.airavata.mft.resource.server.backend.airavata.AiravataResourceBackend;
import org.apache.airavata.mft.resource.server.backend.sql.SQLResourceBackend;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Configuration
public class AppConfig {
@Bean
public ResourceBackend resourceBackend() {
return new AiravataResourceBackend();
}

}
@@ -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.mft.resource.server;

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;

@Configuration
@ImportResource({"applicationContext.xml"})
public class XmlConfiguration {
}
@@ -24,17 +24,17 @@

public interface ResourceBackend {
public Optional<SCPStorage> getSCPStorage(SCPStorageGetRequest request) throws Exception;
public SCPStorage createSCPStorage(SCPStorageCreateRequest request);
public boolean updateSCPStorage(SCPStorageUpdateRequest request);
public boolean deleteSCPStorage(SCPStorageDeleteRequest request);
public SCPStorage createSCPStorage(SCPStorageCreateRequest request) throws Exception;
public boolean updateSCPStorage(SCPStorageUpdateRequest request) throws Exception;
public boolean deleteSCPStorage(SCPStorageDeleteRequest request) throws Exception;

public Optional<SCPResource> getSCPResource(SCPResourceGetRequest request) throws Exception;
public SCPResource createSCPResource(SCPResourceCreateRequest request);
public boolean updateSCPResource(SCPResourceUpdateRequest request);
public boolean deleteSCPResource(SCPResourceDeleteRequest request);
public SCPResource createSCPResource(SCPResourceCreateRequest request) throws Exception;
public boolean updateSCPResource(SCPResourceUpdateRequest request) throws Exception;
public boolean deleteSCPResource(SCPResourceDeleteRequest request) throws Exception;

public Optional<LocalResource> getLocalResource(LocalResourceGetRequest request);
public LocalResource createLocalResource(LocalResourceCreateRequest request);
public boolean updateLocalResource(LocalResourceUpdateRequest request);
public boolean deleteLocalResource(LocalResourceDeleteRequest request);
public Optional<LocalResource> getLocalResource(LocalResourceGetRequest request) throws Exception;
public LocalResource createLocalResource(LocalResourceCreateRequest request) throws Exception;
public boolean updateLocalResource(LocalResourceUpdateRequest request) throws Exception;
public boolean deleteLocalResource(LocalResourceDeleteRequest request) throws Exception;
}
@@ -47,9 +47,8 @@ public Optional<SCPStorage> getSCPStorage(SCPStorageGetRequest request) throws E
String resourceId = request.getStorageId();
String[] parts = resourceId.split(":");
String type = parts[0];
String path = parts[1];
String gateway = parts[2];
String storageOrComputeId = parts[3];
String user = parts[4];

logger.info("Connecting to registry service {}:{}", registryServerHost, registryServerPort);

@@ -103,10 +102,7 @@ public boolean deleteSCPStorage(SCPStorageDeleteRequest request) {
public Optional<SCPResource> getSCPResource(SCPResourceGetRequest request) throws Exception {
String resourceId = request.getResourceId();
String[] parts = resourceId.split(":");
String type = parts[0];
String path = parts[1];
String gateway = parts[2];
String storageOrComputeId = parts[3];

SCPResource scpResource = SCPResource.newBuilder()
.setResourceId(resourceId)
@@ -0,0 +1,147 @@
/*
* 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.mft.resource.server.backend.file;

import org.apache.airavata.mft.resource.server.backend.ResourceBackend;
import org.apache.airavata.mft.resource.service.*;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public class FileBasedResourceBackend implements ResourceBackend {


@Override
public Optional<SCPStorage> getSCPStorage(SCPStorageGetRequest request) throws Exception {
throw new UnsupportedOperationException();
}

@Override
public SCPStorage createSCPStorage(SCPStorageCreateRequest request) {
throw new UnsupportedOperationException();
}

@Override
public boolean updateSCPStorage(SCPStorageUpdateRequest request) {
throw new UnsupportedOperationException();
}

@Override
public boolean deleteSCPStorage(SCPStorageDeleteRequest request) {
throw new UnsupportedOperationException();
}

@Override
public Optional<SCPResource> getSCPResource(SCPResourceGetRequest request) throws Exception {

InputStream inputStream = FileBasedResourceBackend.class.getClassLoader().getResourceAsStream("resources.json");

JSONParser jsonParser = new JSONParser();

try (InputStreamReader reader = new InputStreamReader(inputStream)) {

Object obj = jsonParser.parse(reader);

JSONArray resourceList = (JSONArray) obj;

List<SCPResource> scpResources = (List<SCPResource>) resourceList.stream()
.filter(resource -> "SCP".equals(((JSONObject) resource).get("type").toString()))
.map(resource -> {
JSONObject r = (JSONObject) resource;

SCPStorage storage = SCPStorage.newBuilder()
.setStorageId(((JSONObject)r.get("scpStorage")).get("storageId").toString())
.setHost(((JSONObject)r.get("scpStorage")).get("host").toString())
.setUser(((JSONObject)r.get("scpStorage")).get("user").toString())
.setPort(Integer.parseInt(((JSONObject)r.get("scpStorage")).get("port").toString())).build();

SCPResource scpResource = SCPResource.newBuilder()
.setResourcePath(r.get("resourcePath").toString())
.setResourceId(r.get("resourceId").toString())
.setScpStorage(storage).build();

return scpResource;
}).collect(Collectors.toList());

return scpResources.stream().filter(r -> request.getResourceId().equals(r.getResourceId())).findFirst();
}
}


@Override
public SCPResource createSCPResource(SCPResourceCreateRequest request) {
throw new UnsupportedOperationException();
}

@Override
public boolean updateSCPResource(SCPResourceUpdateRequest request) {
throw new UnsupportedOperationException();
}

@Override
public boolean deleteSCPResource(SCPResourceDeleteRequest request) {
throw new UnsupportedOperationException();
}

@Override
public Optional<LocalResource> getLocalResource(LocalResourceGetRequest request) throws Exception {
JSONParser jsonParser = new JSONParser();
InputStream inputStream = FileBasedResourceBackend.class.getClassLoader().getResourceAsStream("resources.json");

try (InputStreamReader reader = new InputStreamReader(inputStream)) {
Object obj = jsonParser.parse(reader);

JSONArray resourceList = (JSONArray) obj;

System.out.println("All resources ");
List<LocalResource> localResources = (List<LocalResource>) resourceList.stream()
.filter(resource -> "LOCAL".equals(((JSONObject) resource).get("type").toString()))
.map(resource -> {
JSONObject r = (JSONObject) resource;

LocalResource localResource = LocalResource.newBuilder()
.setResourcePath(r.get("resourcePath").toString())
.setResourceId(r.get("resourceId").toString()).build();

return localResource;
}).collect(Collectors.toList());
return localResources.stream().filter(r -> request.getResourceId().equals(r.getResourceId())).findFirst();
}
}

@Override
public LocalResource createLocalResource(LocalResourceCreateRequest request) {
throw new UnsupportedOperationException();
}

@Override
public boolean updateLocalResource(LocalResourceUpdateRequest request) {
throw new UnsupportedOperationException();
}

@Override
public boolean deleteLocalResource(LocalResourceDeleteRequest request) {
throw new UnsupportedOperationException();
}
}
@@ -38,6 +38,9 @@ public class SCPStorageEntity {
@Column(name = "PORT")
private int port;

@Column(name = "USER")
private int user;

public String getStorageId() {
return storageId;
}
@@ -61,4 +64,12 @@ public int getPort() {
public void setPort(int port) {
this.port = port;
}

public int getUser() {
return user;
}

public void setUser(int user) {
this.user = user;
}
}

0 comments on commit 17be4b3

Please sign in to comment.