Commit 07d0accc authored by Spiros Koulouzis's avatar Spiros Koulouzis

Delete master to mergte with package

parent f72e0b43
tosca_definitions_version: tosca_simple_yaml_1_0
description: example file for infrastructure planner
repositories:
MOG_docker_hub:
description: MOG project’s code repository in GitHub
url: https://github.com/switch-project/mog
credential:
protocol: xauth
token_type: X-Auth-Token
# token encoded in Base64
token: 604bbe45ac7143a79e14f3158df67091
artifact_types:
tosca.artifacts.Deployment.Image.Container.Docker:
derived_from: tosca.artifacts.Deployment.Image
data_types:
Switch.datatypes.QoS.AppComponent:
derived_from: tosca.datatypes.Root
properties:
response_time:
type: string
Switch.datatypes.Application.Connection.EndPoint:
derived_from: tosca.datatypes.Root
properties:
address:
type: string
component_name:
type: string
netmask:
type: string
port_name:
type: string
Switch.datatypes.Application.Connection.Multicast:
derived_from: tosca.datatypes.Root
properties:
multicastAddrIP:
type: string
multicastAddrPort:
type: integer
Switch.datatypes.Network.EndPoint:
derived_from: tosca.datatypes.Root
properties:
address:
type: string
host_name:
type: string
netmask:
type: string
port_name:
type: string
Switch.datatypes.Network.Multicast:
derived_from: tosca.datatypes.Root
properties:
multicastAddrIP:
type: string
multicastAddrPort:
type: integer
node_types:
Switch.nodes.Application.Container.Docker:
derived_from: tosca.nodes.Container.Application
properties:
QoS:
type: Switch.datatypes.QoS.AppComponent
artifacts:
docker_image:
type: tosca.artifacts.Deployment.Image.Container.Docker
interfaces:
Standard:
create:
inputs:
command:
type: string
exported_ports:
type: list
entry_schema:
type: string
port_bindings:
type: list
entry_schema:
type: string
Switch.nodes.Application.Container.Docker.MOG.InputDistributor:
derived_from: Switch.nodes.Application.Container.Docker
artifacts:
docker_image:
type: tosca.artifacts.Deployment.Image.Container.Docker
file: "mogswitch/InputDistributor:1.0"
repository: MOG_docker_hub
properties:
inPort:
type: integer
waitingTime:
type: integer
multicastAddrIP:
type: string
multicastAddrPort:
type: integer
videoWidth:
type: integer
videoHeight:
type: integer
Switch.nodes.Application.Container.Docker.MOG.ProxyTranscoder:
derived_from: Switch.nodes.Application.Container.Docker
artifacts:
docker_image:
type: tosca.artifacts.Deployment.Image.Container.Docker
file: "mogswitch/ProxyTranscoder:1.0"
repository: MOG_docker_hub
properties:
multicastAddrIP:
type: string
multicastAddrPort:
type: integer
videoWidth:
type: integer
videoHeight:
type: integer
Switch.nodes.Application.Connection:
derived_from: tosca.nodes.Root
properties:
source:
type: Switch.datatypes.Application.Connection.EndPoint
target:
type: Switch.datatypes.Application.Connection.EndPoint
bandwidth:
type: string
latency:
type: string
jitter:
type: string
multicast:
type: Switch.datatypes.Application.Connection.Multicast
Switch.nodes.Compute:
derived_from: tosca.nodes.Compute
properties:
OStype:
type: string
nodetype:
type: string
domain:
type: string
public_address:
type: string
ethernet_port:
type: list
entry_schema:
type: tosca.datatypes.network.NetworkInfo
script:
type: string
installation:
type: string
ssh_credential:
type: tosca.datatypes.Credential
Switch.nodes.Network:
derived_from: tosca.nodes.network.Network
properties:
bandwidth:
type: string
latency:
type: string
jitter:
type: string
source:
type: Switch.datatypes.Network.EndPoint
target:
type: Switch.datatypes.Network.EndPoint
multicast:
type: Switch.datatypes.Network.Multicast
topology_template:
node_templates:
2d13d708e3a9441ab8336ce874e08dd1:
type: Switch.nodes.Application.Container.Docker.MOG.InputDistributor
artifacts:
docker_image:
file: "mogswitch/InputDistributor:1.0"
type: tosca.artifacts.Deployment.Image.Container.Docker
repository: MOG_docker_hub
properties:
QoS:
response_time: 30ms
inPort: 2000
waitingTime: 5
multicastAddrIP: 255.2.2.0
multicastAddrPort: 3000
videoWidth: 176
videoHeight: 100
interfaces:
Standard:
create:
implementation: docker_image
inputs:
command: InputDistributor
exported_ports:
- 2000
port_bindings:
- "2000:2000"
- "3000:3000"
8fcc1788d9ee462c826572c79fdb2a6a:
type: Switch.nodes.Application.Container.Docker.MOG.ProxyTranscoder
artifacts:
docker_image:
file: "mogswitch/ProxyTranscoder:1.0"
type: tosca.artifacts.Deployment.Image.Container.Docker
repository: MOG_docker_hub
properties:
QoS:
response_time: 30ms
multicastAddrIP: 255.2.2.0
multicastAddrPort: 3000
videoWidth: 176
videoHeight: 100
interfaces:
Standard:
create:
implementation: docker_image
inputs:
command: ProxyTranscoder
exported_ports:
- 80
port_bindings:
- "8080:80"
5e0add703c8a43938a39301f572e46c0:
type: Switch.nodes.Application.Connection
properties:
source:
address: 192.168.21.11
component_name: 2d13d708e3a9441ab8336ce874e08dd1
netmask: 255.255.255.0
port_name: "inputDistributor_out"
target:
address: 192.168.21.12
component_name: 8fcc1788d9ee462c826572c79fdb2a6a
netmask: 255.255.255.0
port_name: "proxyTranscoder_in"
latency: 30ms
bandwidth: 130MB/s
jitter: 500ms
multicast:
multicastAddrIP: 255.2.2.0
multicastAddrPort: 3000
/*
* Copyright 2017 S. Koulouzis.
*
* 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.
*/
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>1.6-web</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_j2eeVersion>
<org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>Tomcat</org-netbeans-modules-maven-j2ee.netbeans_2e_hint_2e_deploy_2e_server>
<netbeans.hint.licensePath>${project.basedir}/licenseheader.txt</netbeans.hint.licensePath>
<org-netbeans-modules-css-prep.less_2e_mappings>/less:/css</org-netbeans-modules-css-prep.less_2e_mappings>
<org-netbeans-modules-css-prep.less_2e_enabled>false</org-netbeans-modules-css-prep.less_2e_enabled>
<org-netbeans-modules-css-prep.sass_2e_enabled>false</org-netbeans-modules-css-prep.sass_2e_enabled>
<org-netbeans-modules-css-prep.sass_2e_compiler_2e_options/>
<org-netbeans-modules-css-prep.less_2e_compiler_2e_options/>
<org-netbeans-modules-css-prep.sass_2e_mappings>/scss:/css</org-netbeans-modules-css-prep.sass_2e_mappings>
<org-netbeans-modules-whitelist.whitelist-oracle>false</org-netbeans-modules-whitelist.whitelist-oracle>
<org-netbeans-modules-web-clientproject-api.js_2e_libs_2e_folder>js/libs</org-netbeans-modules-web-clientproject-api.js_2e_libs_2e_folder>
</properties>
<libraries xmlns="http://www.netbeans.org/ns/cdnjs-libraries/1"/>
</project-shared-configuration>
<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>
<groupId>nl.uva.sne.drip</groupId>
<artifactId>drip-api</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>drip-api</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<skipTests>true</skipTests>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.4.3.RELEASE</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.6</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.5.RELEASE</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>4.0.2</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.8.0.RELEASE</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.2</version>
<scope>test</scope>
<type>jar</type>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>6.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
/*
* Copyright 2016 S. Koulouzis
*
* 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 nl.uva.sne.drip.conf;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@Configuration
@ComponentScan("nl.uva.sne.drip")
//@PropertySource("classpath:drip.properties")
@PropertySources({
@PropertySource(value = "classpath:drip.properties", ignoreResourceNotFound = true),
@PropertySource(value = "file:etc/drip.properties", ignoreResourceNotFound = true)
})
@EnableWebMvc
public class AppConfig {
@Bean(name = "multipartResolver")
public CommonsMultipartResolver createMultipartResolver() {
CommonsMultipartResolver resolver = new CommonsMultipartResolver();
resolver.setDefaultEncoding("utf-8");
// resolver.setMaxInMemorySize(0);
//resolver.setMaxUploadSize(0);
//resolver.setMaxUploadSizePerFile(0);
return resolver;
}
}
/*
* Copyright 2016 S. Koulouzis
*
* 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 nl.uva.sne.drip.conf;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
public class WebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(AppConfig.class);
ctx.setServletContext(servletContext);
Dynamic dynamic = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
dynamic.addMapping("/");
dynamic.setLoadOnStartup(1);
}
}
/*
* Copyright 2017 S. Koulouzis.
*
* 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 nl.uva.sne.drip.data;
import java.util.Date;
/**
*
* @author S. Koulouzis
*/
public interface IRequest {
public enum Status {
/**
* A task is created.
*/
PENDING,
/**
* The scheduler has picked the task up.
*/
SCHEDULED,
/**
* The task is being executed.
*/
RUNNING,
/**
* The task end of life if the task is failed.
*/
FAILED,
/**
* The task end of life if the task is successful.
*/
SUCCESS;
}
public void setID(String id);
public String getID();
public Date getCreationDate();
public Status getStatus();
public void setStatus(Status status);
}
/*
* Copyright 2017 S. Koulouzis.
*
* 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 nl.uva.sne.drip.data;
import java.util.Date;
/**
*
* @author S. Koulouzis.
*/
public class Request implements IRequest {
private String id;
private Date creationDate;
private Status status;
@Override
public void setID(String id) {
this.id = id;
}
@Override
public String getID() {
return this.id;
}
@Override
public Date getCreationDate() {
return this.creationDate;
}
@Override
public Status getStatus() {
return this.status;
}
@Override
public void setStatus(Status status) {
status = this.status;
}
}
/*
* Copyright 2017 S. Koulouzis.
*
* 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 nl.uva.sne.drip.rest;
import nl.uva.sne.drip.rpc.Planner;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
/**
*
* @author S. Koulouzis
*/
@RestController
@RequestMapping("/rest")
@Component
public class UploadToscaController {
@Value("${input.tosca.folder.path}")
private String inputToscaFolderPath;
@Value("${message.broker.host}")
private String messageBrokerHost;
// curl -X POST -F "file=@DRIP/input.yaml" localhost:8080/drip-api/rest/upload
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public @ResponseBody
String toscaUpload(@RequestParam("file") MultipartFile file) {
if (!file.isEmpty()) {
try {
String originalFileName = file.getOriginalFilename();
String name = originalFileName + System.currentTimeMillis();
File targetToscaFile = new File(inputToscaFolderPath + File.separator + name);
file.transferTo(targetToscaFile);
Planner planner = new Planner(messageBrokerHost);
String returned = planner.plan(targetToscaFile);
System.err.println(returned);
planner.close();
return "You successfully uploaded " + name + " into " + name + "-uploaded !";
} catch (IOException | IllegalStateException | TimeoutException | InterruptedException ex) {
Logger.getLogger(UploadToscaController.class.getName()).log(Level.SEVERE, null, ex);
}
}
return "Upload failed. 'file' was empty.";
}
}
/*
* Copyright 2017 S. Koulouzis.
*
* 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 nl.uva.sne.drip.rpc;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
/**
*
* @author S. Koulouzis.
*/
class DRIPComponent {
private Connection connection;
private Channel channel;
private void connect(String messageBrokerHost) throws IOException, TimeoutException {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost(messageBrokerHost);
connection = factory.newConnection();
channel = connection.createChannel();
}
public void close() throws IOException {
connection.close();
}
/**
* @return the channel
*/
public Channel getChannel(String messageBrokerHost) throws IOException, TimeoutException {
if (channel == null) {
connect(messageBrokerHost);
}
return channel;
}
}
/*
* Copyright 2017 S. Koulouzis.
*
* 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 nl.uva.sne.drip.rpc;
import java.io.File;
import java.io.IOException;
import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;
import com.rabbitmq.client.RpcClient;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeoutException;
/**
*
* @author S. Koulouzis.
*/
public class Planner {
private static final String REQUEST_QUEUE_NAME = "planner_queue";
private final Connection connection;
private final Channel channel;
private final String replyQueueName;
public Planner(String messageBrokerHost) throws IOException, TimeoutException {
ConnectionFactory factory = new ConnectionFactory();
factory.setHost(messageBrokerHost);
factory.setHost(messageBrokerHost);
factory.setPort(AMQP.PROTOCOL.PORT);
//factory.setUsername("guest");
//factory.setPassword("pass");
connection = factory.newConnection();
channel = connection.createChannel();
// create a single callback queue per client not per requests.
replyQueueName = channel.queueDeclare().getQueue();
}
public String plan(File inputToscaFile) throws IOException, TimeoutException, InterruptedException {
//Build a correlation ID to distinguish responds
final String corrId = UUID.randomUUID().toString();
AMQP.BasicProperties props = new AMQP.BasicProperties.Builder()
.correlationId(corrId)
.replyTo(replyQueueName)
.build();
byte[] fileContentsBytes = Files.readAllBytes(Paths.get(inputToscaFile.getAbsolutePath()));
channel.basicPublish("", REQUEST_QUEUE_NAME, props, fileContentsBytes);
final BlockingQueue<String> response = new ArrayBlockingQueue(1);
channel.basicConsume(replyQueueName, true, new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
if (properties.getCorrelationId().equals(corrId)) {
response.offer(new String(body, "UTF-8"));
}
}
});
// channel.close();
// connection.close();
return response.take();
}
public void close() throws IOException, TimeoutException {
if (channel != null && channel.isOpen()) {
channel.close();
}
if (connection != null && connection.isOpen()) {
connection.close();
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/data/mongo
http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<import resource="classpath:/drip-context-rest.xml" />
<context:component-scan base-package="nl.uva.sne.drip" />
</beans>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
</beans>
\ No newline at end of file
input.tosca.folder.path=/tmp/
message.broker.host=172.17.0.2
# Internal log4j configuration. This is not packaged and distributed. The using
# party is in control of its own log4j.properties.
# Root logger option
log4j.rootLogger=INFO, stdout
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
log4j.appender.authorizationLog=org.apache.log4j.RollingFileAppender
log4j.appender.authorizationLog.File=logs/authorization.log
log4j.appender.authorizationLog.MaxFileSize=20MB
log4j.appender.authorizationLog.MaxBackupIndex=10
log4j.appender.authorizationLog.layout=org.apache.log4j.PatternLayout
log4j.appender.authorizationLog.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p - %m%n
log4j.appender.authenticationLog=org.apache.log4j.RollingFileAppender
log4j.appender.authenticationLog.File=logs/authentication.log
log4j.appender.authenticationLog.MaxFileSize=20MB
log4j.appender.authenticationLog.MaxBackupIndex=10
log4j.appender.authenticationLog.layout=org.apache.log4j.PatternLayout
log4j.appender.authenticationLog.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p - %m%n
log4j.category.authorizationLogger=TRACE, authorizationLog
#log4j.additivity.authorizationLogger=false
log4j.category.authenticationLogger=DEBUG, authenticationLog
#log4j.additivity.authenticationLogger=false
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/drip-api"/>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Welcom to the DRIP API</h1>
</body>
</html>
/*
* Copyright 2017 S. Koulouzis.
*
* 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 nl.uva.sne.drip.rest;
import java.io.File;
import java.io.IOException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.HttpClientBuilder;
import org.junit.Assert;
import static org.junit.Assert.assertEquals;
/**
*
* @author S. Koulouzis
*/
public class RESTTest {
private static URI url;
private static File toscaFile;
public RESTTest() {
}
@BeforeClass
public static void setUpClass() throws URISyntaxException {
url = new URI("http://localhost:8080/drip-api/rest/upload");
toscaFile = new File("./etc/input.yaml");
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
@Test
public void testUpload() throws IOException {
HttpClient client = HttpClientBuilder.create().build();
HttpPost post = new HttpPost(url);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
FileBody fileBody = new FileBody(toscaFile);
builder.addPart("file", fileBody);
HttpEntity entity = builder.build();
post.setEntity(entity);
HttpResponse status = client.execute(post);
System.err.println(status.getStatusLine());
assertEquals(200, status.getStatusLine().getStatusCode());
//
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment