Skip to content
Snippets Groups Projects
Commit 82e8acef authored by Martin Weise's avatar Martin Weise
Browse files

Merge branch 'master' into dev

Former-commit-id: 2b40e18e
parents 646c4c58 7c493f9c
No related branches found
No related tags found
1 merge request!23Sprint results
Showing
with 351 additions and 132 deletions
...@@ -3,7 +3,7 @@ CREATE SEQUENCE seq_user; ...@@ -3,7 +3,7 @@ CREATE SEQUENCE seq_user;
CREATE TYPE gender AS ENUM ('F', 'M', 'T'); CREATE TYPE gender AS ENUM ('F', 'M', 'T');
CREATE TYPE accesstype AS ENUM ('R', 'W'); CREATE TYPE accesstype AS ENUM ('R', 'W');
CREATE TABLE md_DATA ( CREATE TABLE DATA (
ID INTEGER PRIMARY KEY DEFAULT nextval('seq_data'), ID INTEGER PRIMARY KEY DEFAULT nextval('seq_data'),
PROVENANCE TEXT, PROVENANCE TEXT,
FileEncoding TEXT, FileEncoding TEXT,
...@@ -24,12 +24,12 @@ CREATE TABLE md_USERS ( ...@@ -24,12 +24,12 @@ CREATE TABLE md_USERS (
Main_Email TEXT Main_Email TEXT
); );
CREATE TABLE md_CONTACTPERSON ( CREATE TABLE CONTACTPERSON (
cUserID INTEGER PRIMARY KEY REFERENCES md_USERS(UserID), cUserID INTEGER PRIMARY KEY REFERENCES USERS(UserID),
Email TEXT Email TEXT
); );
CREATE TABLE md_DATABASES ( CREATE TABLE DATABASES (
DBID TEXT PRIMARY KEY, -- (= DockerContainer ID) DBID TEXT PRIMARY KEY, -- (= DockerContainer ID)
Title VARCHAR(50), Title VARCHAR(50),
ResourceType TEXT, ResourceType TEXT,
...@@ -38,11 +38,11 @@ CREATE TABLE md_DATABASES ( ...@@ -38,11 +38,11 @@ CREATE TABLE md_DATABASES (
Publisher VARCHAR(50), Publisher VARCHAR(50),
Year DATE DEFAULT CURRENT_DATE, Year DATE DEFAULT CURRENT_DATE,
Open BOOLEAN DEFAULT TRUE, Open BOOLEAN DEFAULT TRUE,
Contact INTEGER REFERENCES md_CONTACTPERSON(cUserID) Contact INTEGER REFERENCES CONTACTPERSON(cUserID)
); );
CREATE TABLE md_TABLES ( CREATE TABLE TABLES (
tDBID TEXT REFERENCES md_DATABASES(DBID), tDBID TEXT REFERENCES DATABASES(DBID),
tName VARCHAR(50), tName VARCHAR(50),
NumCols INTEGER, NumCols INTEGER,
NumRows INTEGER, NumRows INTEGER,
...@@ -50,7 +50,7 @@ CREATE TABLE md_TABLES ( ...@@ -50,7 +50,7 @@ CREATE TABLE md_TABLES (
PRIMARY KEY(tDBID,tName) PRIMARY KEY(tDBID,tName)
); );
CREATE TABLE md_COLUMNS ( CREATE TABLE COLUMNS (
cDBID TEXT NOT NULL, cDBID TEXT NOT NULL,
tName VARCHAR(50) NOT NULL, tName VARCHAR(50) NOT NULL,
cName VARCHAR(50), cName VARCHAR(50),
...@@ -105,24 +105,24 @@ CREATE TABLE md_VIEW ( ...@@ -105,24 +105,24 @@ CREATE TABLE md_VIEW (
PRIMARY KEY (vDBID,vName) PRIMARY KEY (vDBID,vName)
); );
CREATE TABLE md_feed ( CREATE TABLE feed (
fDBID TEXT, fDBID TEXT,
fName VARCHAR(50), fName VARCHAR(50),
fUserId INTEGER REFERENCES md_USERS(UserID), fUserId INTEGER REFERENCES USERS(UserID),
fDataID INTEGER REFERENCES md_DATA(ID), fDataID INTEGER REFERENCES DATA(ID),
FOREIGN KEY (fDBID,fName) REFERENCES md_TABLES(tDBID,tNAME), FOREIGN KEY (fDBID,fName) REFERENCES TABLES(tDBID,tNAME),
PRIMARY KEY (fDBID,fName,fUserId, fDataID) PRIMARY KEY (fDBID,fName,fUserId, fDataID)
); );
CREATE TABLE md_update ( CREATE TABLE update (
uUserID INTEGER REFERENCES md_USERS(UserID), uUserID INTEGER REFERENCES USERS(UserID),
uDBID TEXT REFERENCES md_DATABASES(DBID), uDBID TEXT REFERENCES Databases(DBID),
PRIMARY KEY (uUserID,uDBID) PRIMARY KEY (uUserID,uDBID)
); );
CREATE TABLE md_access ( CREATE TABLE access (
aUserID INTEGER REFERENCES md_USERS(UserID), aUserID INTEGER REFERENCES USERS(UserID),
aDBID TEXT REFERENCES md_DATABASES(DBID), aDBID TEXT REFERENCES Databases(DBID),
attime TIMESTAMP, attime TIMESTAMP,
download BOOLEAN, download BOOLEAN,
PRIMARY KEY (aUserID, aDBID) PRIMARY KEY (aUserID, aDBID)
......
...@@ -6,7 +6,7 @@ spring: ...@@ -6,7 +6,7 @@ spring:
username: postgres username: postgres
password: postgres password: postgres
jpa: jpa:
show-sql: true show-sql: false
database-platform: org.hibernate.dialect.PostgreSQLDialect database-platform: org.hibernate.dialect.PostgreSQLDialect
hibernate: hibernate:
ddl-auto: update ddl-auto: update
...@@ -15,7 +15,7 @@ spring: ...@@ -15,7 +15,7 @@ spring:
name: fda-container-service name: fda-container-service
cloud: cloud:
loadbalancer.ribbon.enabled: false loadbalancer.ribbon.enabled: false
server.port: 9091 server.port: 9093
logging: logging:
pattern.console: "%d %highlight(%-5level) %msg%n" pattern.console: "%d %highlight(%-5level) %msg%n"
level: level:
......
# https://github.com/Netflix/Hystrix/issues/275
\ No newline at end of file
package at.tuwien;
import at.tuwien.entities.container.Container;
import at.tuwien.entities.container.image.ContainerImage;
import at.tuwien.entities.container.image.ContainerImageEnvironmentItem;
import org.springframework.test.context.TestPropertySource;
import java.time.Instant;
import java.util.List;
import static java.time.temporal.ChronoUnit.DAYS;
import static java.time.temporal.ChronoUnit.HOURS;
@TestPropertySource(locations = "classpath:application.properties")
public abstract class BaseIntegrationTest {
public final String IMAGE_1_REPOSITORY = "postgres";
public final String IMAGE_1_TAG = "13-alpine";
public final String IMAGE_1_HASH = "83b40f2726e5";
public final Integer IMAGE_1_PORT = 5432;
public final Instant IMAGE_1_BUILT = Instant.now().minus(40, HOURS);
public final List<ContainerImageEnvironmentItem> IMAGE_1_ENV = List.of(ContainerImageEnvironmentItem.builder()
.key("POSTGRES_USER")
.value("postgres")
.build(),
ContainerImageEnvironmentItem.builder()
.key("POSTGRES_PASSWORD")
.value("postgres")
.build());
public final String IMAGE_2_REPOSITORY = "redis";
public final String IMAGE_2_TAG = "latest";
public final String IMAGE_2_HASH = "f877e80bb9ef";
public final Integer IMAGE_2_PORT = 6379;
public final Instant IMAGE_2_BUILT = Instant.now().minus(9, DAYS);
public final List<ContainerImageEnvironmentItem> IMAGE_2_ENV = List.of(ContainerImageEnvironmentItem.builder()
.key("POSTGRES_USER")
.value("postgres")
.build(),
ContainerImageEnvironmentItem.builder()
.key("POSTGRES_PASSWORD")
.value("postgres")
.build());
public final ContainerImage IMAGE_1 = ContainerImage.builder()
.repository(IMAGE_1_REPOSITORY)
.tag(IMAGE_1_TAG)
.hash(IMAGE_1_HASH)
.compiled(IMAGE_1_BUILT)
.environment(IMAGE_1_ENV)
.defaultPort(IMAGE_1_PORT)
.build();
public final ContainerImage IMAGE_2 = ContainerImage.builder()
.repository(IMAGE_2_REPOSITORY)
.tag(IMAGE_2_TAG)
.hash(IMAGE_2_HASH)
.compiled(IMAGE_2_BUILT)
.environment(IMAGE_2_ENV)
.defaultPort(IMAGE_2_PORT)
.build();
public final Long CONTAINER_1_ID = 1L;
public final String CONTAINER_1_HASH = "deadbeef";
public final ContainerImage CONTAINER_1_IMAGE = IMAGE_1;
public final String CONTAINER_1_NAME = "u01";
public final String CONTAINER_1_DATABASE = "univie";
public final String CONTAINER_1_IP = "231.145.98.83";
public final Instant CONTAINER_1_CREATED = Instant.now().minus(1, HOURS);
public final Long CONTAINER_2_ID = 2L;
public final String CONTAINER_2_HASH = "0ff1ce";
public final ContainerImage CONTAINER_2_IMAGE = IMAGE_2;
public final String CONTAINER_2_NAME = "t01";
public final String CONTAINER_2_DATABASE = "tuw";
public final String CONTAINER_2_IP = "233.145.99.83";
public final Instant CONTAINER_2_CREATED = Instant.now().minus(1, HOURS);
public final Container CONTAINER_1 = Container.builder()
.id(CONTAINER_1_ID)
.name(CONTAINER_1_NAME)
.image(CONTAINER_1_IMAGE)
.hash(CONTAINER_1_HASH)
.containerCreated(CONTAINER_1_CREATED)
.build();
public final Container CONTAINER_2 = Container.builder()
.id(CONTAINER_2_ID)
.name(CONTAINER_2_NAME)
.image(CONTAINER_2_IMAGE)
.hash(CONTAINER_2_HASH)
.containerCreated(CONTAINER_2_CREATED)
.build();
}
...@@ -63,7 +63,7 @@ public class ImageEndpointUnitTest extends BaseUnitTest { ...@@ -63,7 +63,7 @@ public class ImageEndpointUnitTest extends BaseUnitTest {
} }
@Test @Test
public void create_succeeds() { public void create_succeeds() throws ImageNotFoundException {
final ImageCreateDto request = ImageCreateDto.builder() final ImageCreateDto request = ImageCreateDto.builder()
.repository(IMAGE_1_REPOSITORY) .repository(IMAGE_1_REPOSITORY)
.tag(IMAGE_1_TAG) .tag(IMAGE_1_TAG)
...@@ -81,7 +81,7 @@ public class ImageEndpointUnitTest extends BaseUnitTest { ...@@ -81,7 +81,7 @@ public class ImageEndpointUnitTest extends BaseUnitTest {
} }
@Test @Test
public void create_duplicate_fails() { public void create_duplicate_fails() throws ImageNotFoundException {
final ImageCreateDto request = ImageCreateDto.builder() final ImageCreateDto request = ImageCreateDto.builder()
.repository(IMAGE_1_REPOSITORY) .repository(IMAGE_1_REPOSITORY)
.tag(IMAGE_1_TAG) .tag(IMAGE_1_TAG)
...@@ -100,7 +100,7 @@ public class ImageEndpointUnitTest extends BaseUnitTest { ...@@ -100,7 +100,7 @@ public class ImageEndpointUnitTest extends BaseUnitTest {
} }
@Test @Test
public void create_notExists_fails() { public void create_notExists_fails() throws ImageNotFoundException {
final ImageCreateDto request = ImageCreateDto.builder() final ImageCreateDto request = ImageCreateDto.builder()
.repository(IMAGE_1_REPOSITORY) .repository(IMAGE_1_REPOSITORY)
.tag(IMAGE_1_TAG) .tag(IMAGE_1_TAG)
...@@ -119,7 +119,7 @@ public class ImageEndpointUnitTest extends BaseUnitTest { ...@@ -119,7 +119,7 @@ public class ImageEndpointUnitTest extends BaseUnitTest {
} }
@Test @Test
public void findById_succeeds() { public void findById_succeeds() throws ImageNotFoundException {
when(imageService.getById(IMAGE_1_ID)) when(imageService.getById(IMAGE_1_ID))
.thenReturn(CONTAINER_1_IMAGE); .thenReturn(CONTAINER_1_IMAGE);
...@@ -130,7 +130,7 @@ public class ImageEndpointUnitTest extends BaseUnitTest { ...@@ -130,7 +130,7 @@ public class ImageEndpointUnitTest extends BaseUnitTest {
} }
@Test @Test
public void findById_notFound_fails() { public void findById_notFound_fails() throws ImageNotFoundException {
given(imageService.getById(IMAGE_1_ID)) given(imageService.getById(IMAGE_1_ID))
.willAnswer(invocation -> { .willAnswer(invocation -> {
throw new ImageNotFoundException("not existing in docker hub"); throw new ImageNotFoundException("not existing in docker hub");
...@@ -143,7 +143,7 @@ public class ImageEndpointUnitTest extends BaseUnitTest { ...@@ -143,7 +143,7 @@ public class ImageEndpointUnitTest extends BaseUnitTest {
} }
@Test @Test
public void delete_fails() { public void delete_fails() throws ImageNotFoundException {
doThrow(new ImageNotFoundException("not found")) doThrow(new ImageNotFoundException("not found"))
.when(imageService) .when(imageService)
.delete(IMAGE_1_ID); .delete(IMAGE_1_ID);
...@@ -155,7 +155,7 @@ public class ImageEndpointUnitTest extends BaseUnitTest { ...@@ -155,7 +155,7 @@ public class ImageEndpointUnitTest extends BaseUnitTest {
} }
@Test @Test
public void update_succeeds() { public void update_succeeds() throws ImageNotFoundException {
final ImageChangeDto request = ImageChangeDto.builder() final ImageChangeDto request = ImageChangeDto.builder()
.defaultPort(1111) .defaultPort(1111)
.build(); .build();
...@@ -166,7 +166,7 @@ public class ImageEndpointUnitTest extends BaseUnitTest { ...@@ -166,7 +166,7 @@ public class ImageEndpointUnitTest extends BaseUnitTest {
} }
@Test @Test
public void update_notFound_fails() { public void update_notFound_fails() throws ImageNotFoundException {
final ImageChangeDto request = ImageChangeDto.builder() final ImageChangeDto request = ImageChangeDto.builder()
.defaultPort(1111) .defaultPort(1111)
.environment(IMAGE_1_ENV_DTO) .environment(IMAGE_1_ENV_DTO)
......
package at.tuwien.mapper;
import com.github.dockerjava.api.command.InspectContainerResponse;
import com.github.dockerjava.api.model.ContainerNetwork;
import com.github.dockerjava.api.model.NetworkSettings;
import lombok.SneakyThrows;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import java.lang.reflect.Field;
import java.util.Map;
public abstract class BaseMappingTest {
@Configuration
@ComponentScan(basePackages = {"at.tuwien"})
public static class BaseMappingContext {
}
final String CONTAINER_ID = "deadbeef";
final String CONTAINER_NETWORK_IP = "154.234.88.15";
@SneakyThrows
final InspectContainerResponse mockInspectResponse() {
final InspectContainerResponse responseC = new InspectContainerResponse();
final Object response = responseC.getClass().getConstructor().newInstance();
final Field idField = responseC.getClass().getDeclaredField("id");
idField.setAccessible(true);
idField.set(response, CONTAINER_ID);
final Field networkSettingsField = responseC.getClass().getDeclaredField("networkSettings");
networkSettingsField.setAccessible(true);
// define the network and address
final ContainerNetwork networkC = new ContainerNetwork();
final Object network = networkC.getClass().getConstructor().newInstance();
final Field ipField = networkC.getClass().getDeclaredField("ipAddress");
ipField.setAccessible(true);
ipField.set(network, CONTAINER_NETWORK_IP);
final Map<String, ContainerNetwork> map = Map.of("fda-userdb", (ContainerNetwork) network);
// add to network settings
final NetworkSettings settingsC = new NetworkSettings();
final Object settings = settingsC.getClass().getConstructor().newInstance();
final Field networksField = settingsC.getClass().getDeclaredField("networks");
networksField.setAccessible(true);
networksField.set(settings, map);
networkSettingsField.set(response, settings);
return (InspectContainerResponse) response;
}
}
package at.tuwien.mapper;
import com.github.dockerjava.api.command.InspectContainerResponse;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@ExtendWith(SpringExtension.class)
@SpringBootTest
public class ContainerMappingTest extends BaseMappingTest {
@Test
public void inspectContainerResponseToDatabaseContainerMappingTest_succeeds() {
final InspectContainerResponse response = mockInspectResponse();
assertNotNull(response, "response must not be null");
assertEquals(CONTAINER_ID, response.getId());
assertNotNull(response.getNetworkSettings(), "networkSettings must not be null");
assertNotNull(response.getNetworkSettings().getNetworks(), "networkSettings.networks must not be null");
assertNotNull(response.getNetworkSettings().getNetworks().get("fda-userdb"), "networkSettings.networks['fda-userdb'] must not be null");
assertNotNull(response.getNetworkSettings().getNetworks().get("fda-userdb").getIpAddress(), "networkSettings.networks['fda-userdb'].ipAddress must not be null");
assertEquals(CONTAINER_NETWORK_IP, response.getNetworkSettings().getNetworks().get("fda-userdb").getIpAddress());
}
}
...@@ -4,10 +4,7 @@ import at.tuwien.BaseUnitTest; ...@@ -4,10 +4,7 @@ import at.tuwien.BaseUnitTest;
import at.tuwien.api.container.ContainerCreateRequestDto; import at.tuwien.api.container.ContainerCreateRequestDto;
import at.tuwien.api.container.ContainerStateDto; import at.tuwien.api.container.ContainerStateDto;
import at.tuwien.entities.container.Container; import at.tuwien.entities.container.Container;
import at.tuwien.exception.ContainerNotFoundException; import at.tuwien.exception.*;
import at.tuwien.exception.ContainerNotRunningException;
import at.tuwien.exception.ContainerStillRunningException;
import at.tuwien.exception.DockerClientException;
import at.tuwien.repository.ContainerRepository; import at.tuwien.repository.ContainerRepository;
import at.tuwien.repository.ImageRepository; import at.tuwien.repository.ImageRepository;
import com.github.dockerjava.api.DockerClient; import com.github.dockerjava.api.DockerClient;
...@@ -143,7 +140,7 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest { ...@@ -143,7 +140,7 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
} }
@Test @Test
public void getContainerState_succeeds() { public void getContainerState_succeeds() throws DockerClientException {
/* test */ /* test */
final ContainerStateDto response = containerService.getContainerState(CONTAINER_1_HASH); final ContainerStateDto response = containerService.getContainerState(CONTAINER_1_HASH);
...@@ -162,7 +159,7 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest { ...@@ -162,7 +159,7 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
} }
@Test @Test
public void create_succeeds() { public void create_succeeds() throws DockerClientException, ImageNotFoundException {
final ContainerCreateRequestDto request = ContainerCreateRequestDto.builder() final ContainerCreateRequestDto request = ContainerCreateRequestDto.builder()
.repository(IMAGE_1_REPOSITORY) .repository(IMAGE_1_REPOSITORY)
.tag(IMAGE_1_TAG) .tag(IMAGE_1_TAG)
...@@ -185,7 +182,7 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest { ...@@ -185,7 +182,7 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
} }
@Test @Test
public void change_start_succeeds() { public void change_start_succeeds() throws DockerClientException {
dockerClient.stopContainerCmd(CONTAINER_1_HASH).exec(); dockerClient.stopContainerCmd(CONTAINER_1_HASH).exec();
/* test */ /* test */
...@@ -193,7 +190,7 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest { ...@@ -193,7 +190,7 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
} }
@Test @Test
public void change_stop_succeeds() { public void change_stop_succeeds() throws DockerClientException {
/* test */ /* test */
containerService.stop(CONTAINER_1_ID); containerService.stop(CONTAINER_1_ID);
...@@ -209,7 +206,7 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest { ...@@ -209,7 +206,7 @@ public class ContainerServiceIntegrationTest extends BaseUnitTest {
} }
@Test @Test
public void remove_succeeds() { public void remove_succeeds() throws DockerClientException {
dockerClient.stopContainerCmd(CONTAINER_1_HASH).exec(); dockerClient.stopContainerCmd(CONTAINER_1_HASH).exec();
/* test */ /* test */
......
...@@ -55,7 +55,7 @@ public class ImageServiceUnitTest extends BaseUnitTest { ...@@ -55,7 +55,7 @@ public class ImageServiceUnitTest extends BaseUnitTest {
} }
@Test @Test
public void getById_succeeds() { public void getById_succeeds() throws ImageNotFoundException {
when(imageRepository.findById(IMAGE_1_ID)) when(imageRepository.findById(IMAGE_1_ID))
.thenReturn(Optional.of(IMAGE_1)); .thenReturn(Optional.of(IMAGE_1));
...@@ -77,7 +77,7 @@ public class ImageServiceUnitTest extends BaseUnitTest { ...@@ -77,7 +77,7 @@ public class ImageServiceUnitTest extends BaseUnitTest {
} }
@Test @Test
public void create_notFound_fails() { public void create_notFound_fails() throws ImageNotFoundException {
final ImageCreateDto request = ImageCreateDto.builder() final ImageCreateDto request = ImageCreateDto.builder()
.repository(IMAGE_1_REPOSITORY) .repository(IMAGE_1_REPOSITORY)
.tag(IMAGE_1_TAG) .tag(IMAGE_1_TAG)
...@@ -94,7 +94,7 @@ public class ImageServiceUnitTest extends BaseUnitTest { ...@@ -94,7 +94,7 @@ public class ImageServiceUnitTest extends BaseUnitTest {
} }
@Test @Test
public void create_duplicate_fails() { public void create_duplicate_fails() throws ImageNotFoundException {
final ImageCreateDto request = ImageCreateDto.builder() final ImageCreateDto request = ImageCreateDto.builder()
.repository(IMAGE_1_REPOSITORY) .repository(IMAGE_1_REPOSITORY)
.tag(IMAGE_1_TAG) .tag(IMAGE_1_TAG)
...@@ -111,7 +111,7 @@ public class ImageServiceUnitTest extends BaseUnitTest { ...@@ -111,7 +111,7 @@ public class ImageServiceUnitTest extends BaseUnitTest {
} }
@Test @Test
public void update_succeeds() { public void update_succeeds() throws ImageNotFoundException {
final ImageChangeDto request = ImageChangeDto.builder() final ImageChangeDto request = ImageChangeDto.builder()
.environment(IMAGE_1_ENV_DTO) .environment(IMAGE_1_ENV_DTO)
.defaultPort(IMAGE_1_PORT) .defaultPort(IMAGE_1_PORT)
...@@ -143,7 +143,7 @@ public class ImageServiceUnitTest extends BaseUnitTest { ...@@ -143,7 +143,7 @@ public class ImageServiceUnitTest extends BaseUnitTest {
} }
@Test @Test
public void delete_succeeds() { public void delete_succeeds() throws ImageNotFoundException {
doNothing() doNothing()
.when(imageRepository) .when(imageRepository)
.deleteById(IMAGE_1_ID); .deleteById(IMAGE_1_ID);
......
...@@ -2,17 +2,20 @@ package at.tuwien.exception; ...@@ -2,17 +2,20 @@ package at.tuwien.exception;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.server.ResponseStatusException;
@ResponseStatus(code = HttpStatus.BAD_REQUEST, reason = "Docker failed") @ResponseStatus(code = HttpStatus.BAD_REQUEST, reason = "Docker failed")
public class DockerClientException extends ResponseStatusException { public class DockerClientException extends Exception {
public DockerClientException(String message) { public DockerClientException(String message) {
super(HttpStatus.BAD_REQUEST, message); super(message);
} }
public DockerClientException(String message, Throwable thr) { public DockerClientException(String message, Throwable thr) {
super(HttpStatus.BAD_REQUEST, message, thr); super(message, thr);
}
public DockerClientException(Throwable thr) {
super(thr);
} }
} }
...@@ -2,17 +2,20 @@ package at.tuwien.exception; ...@@ -2,17 +2,20 @@ package at.tuwien.exception;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.server.ResponseStatusException;
@ResponseStatus(code = HttpStatus.NOT_FOUND, reason = "Image not found") @ResponseStatus(code = HttpStatus.NOT_FOUND, reason = "Image not found")
public class ImageNotFoundException extends ResponseStatusException { public class ImageNotFoundException extends Exception {
public ImageNotFoundException(String message) { public ImageNotFoundException(String message) {
super(HttpStatus.NOT_FOUND, message); super(message);
} }
public ImageNotFoundException(String message, Throwable thr) { public ImageNotFoundException(String message, Throwable thr) {
super(HttpStatus.NOT_FOUND, message, thr); super(message, thr);
}
public ImageNotFoundException(Throwable thr) {
super(thr);
} }
} }
/*
* Copyright 2007-present the original author or authors.
*
* 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.
*/
import java.net.*;
import java.io.*;
import java.nio.channels.*;
import java.util.Properties;
public class MavenWrapperDownloader {
private static final String WRAPPER_VERSION = "0.5.6";
/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";
/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";
/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if (mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if (mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: " + url);
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if (!outputFile.getParentFile().exists()) {
if (!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
String username = System.getenv("MVNW_USERNAME");
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
}
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}
}
File added
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.6/maven-wrapper-0.5.6.jar
...@@ -12,7 +12,6 @@ RUN mvn -fn -B dependency:go-offline > /dev/null ...@@ -12,7 +12,6 @@ RUN mvn -fn -B dependency:go-offline > /dev/null
COPY --from=dependency /root/.m2/repository/at/tuwien /root/.m2/repository/at/tuwien COPY --from=dependency /root/.m2/repository/at/tuwien /root/.m2/repository/at/tuwien
COPY ./rest-service ./rest-service COPY ./rest-service ./rest-service
COPY ./gateway ./gateway
COPY ./services ./services COPY ./services ./services
COPY ./report ./report COPY ./report ./report
......
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>fda-database-service</artifactId>
<groupId>at.tuwien</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>gateway</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>fda-database-service-gateway</name>
<dependencies />
</project>
\ No newline at end of file
package at.tuwien.config;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
@Component
public class RestClient extends RestTemplate {
}
package at.tuwien.endpoint;
import at.tuwien.api.container.ContainerDto;
import at.tuwien.config.RestClient;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
@Log4j2
@Service
public class ContainerGateway {
/** @apiNote this url is already in Eureka and NOT docker */
private static final String URL = "http://fda-container-service/api/container/";
private final RestClient restClient;
@Autowired
public ContainerGateway(RestClient restClient) {
this.restClient = restClient;
}
// public ContainerDto inspect(Long id) {
// final ResponseEntity<ContainerDto> response;
// response = restClient.exchange(URL + id, HttpMethod.GET, null, new ParameterizedTypeReference<>() {
// });
// return response.getBody();
// }
}
package at.tuwien.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(code = HttpStatus.NOT_ACCEPTABLE, reason = "external service failed")
public class ExternalComponentException extends Exception {
public ExternalComponentException(String message) {
super(message);
}
public ExternalComponentException(String message, Throwable thr) {
super(message, thr);
}
public ExternalComponentException(Throwable thr) {
super(thr);
}
}
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
<packaging>pom</packaging> <packaging>pom</packaging>
<modules> <modules>
<module>gateway</module>
<module>rest-service</module> <module>rest-service</module>
<module>services</module> <module>services</module>
<module>report</module> <module>report</module>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment