Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
Merge branch 'development' for 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWall89 committed Nov 30, 2020
2 parents 8520416 + a7f5c4b commit 7570b13
Show file tree
Hide file tree
Showing 49 changed files with 1,302 additions and 429 deletions.
16 changes: 15 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
FROM azul/zulu-openjdk-alpine:8-jre
FROM openjdk:8

ARG BUILD_DATE
ARG BUILD_VERSION

LABEL maintainer="[email protected]"
LABEL org.label-schema.schema-version="1.0"
LABEL org.label-schema.build-date=$BUILD_DATE
LABEL org.label-schema.name="5GEVE/-exp-nsd-composer"
LABEL org.label-schema.description="A REST API module to compose experiment NSDs. It can also validate blueprints and generate NSDs from them."
LABEL org.label-schema.vcs-url="https://github.com/5GEVE/-exp-nsd-composer"
LABEL org.label-schema.version=$BUILD_VERSION
LABEL org.label-schema.docker.cmd="docker run -p 8086:8086 mpergolesi/exp-nsd-composer"

EXPOSE 8086
COPY ./target/*.jar /app.jar
CMD java -jar app.jar
30 changes: 26 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@ A REST API module to compose experiment NSDs. It can also validate blueprints an

## Install

Docker images are available on [Docker Hub](https://hub.docker.com/r/mpergolesi/exp-nsd-composer).
Run the application with:

```shell script
docker run -p 8086:8086 -d mpergolesi/exp-nsd-composer
```

Wait for the application to start, then test it with:

```shell script
curl http://localhost:8086/vsb/schema
```

## OpenApi

Once running, you can get the OpenAPI specification by visiting (change host if needed):

- http://localhost:8086/swagger-ui.html
- http://localhost:8086/api-docs

## Development

Some dependencies are not available in Maven repository. Check `pom.xml`.

Compile the project with:
Expand All @@ -11,12 +33,12 @@ Compile the project with:
mvn clean package
```

We use Docker Compose for deployment. Run:
Build the Docker image with:

```
docker pull azul/zulu-openjdk-alpine:8-jre
docker-compose build
docker-compose up
docker build --no-cache=true --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \
--build-arg BUILD_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) \
-t <your-repo>:exp-nsd-composer:$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) .
```

## Graph export for visualization
Expand Down
7 changes: 0 additions & 7 deletions docker-compose.yml

This file was deleted.

19 changes: 17 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</parent>
<groupId>it.cnit.blueprint</groupId>
<artifactId>composer</artifactId>
<version>0.1.0</version>
<version>1.0.0</version>
<description>A REST API module to compose experiment NSDs. It can also validate blueprints and
generate NSDs from them.
</description>
Expand Down Expand Up @@ -57,7 +57,7 @@
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.2.30</version>
<version>1.4.8</version>
</dependency>

<!-- Lombok -->
Expand Down Expand Up @@ -135,13 +135,28 @@
</exclusion>
</exclusions>
</dependency>

<!-- https://github.com/nidi3/graphviz-java-->
<dependency>
<groupId>guru.nidi</groupId>
<artifactId>graphviz-java</artifactId>
<version>0.17.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>build-info</id>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/it/cnit/blueprint/composer/CorsConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package it.cnit.blueprint.composer;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class CorsConfiguration implements WebMvcConfigurer {

@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**");
}

}
38 changes: 25 additions & 13 deletions src/main/java/it/cnit/blueprint/composer/OpenApiConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
package it.cnit.blueprint.composer;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.info.License;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import org.springframework.boot.info.BuildProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@OpenAPIDefinition(
info = @Info(
title = "5G EVE Experiment NSD composer",
description =
"A REST API module to compose experiment NSDs. It can also validate blueprints and"
+ " generate NSDs from them.",
version = "v0.1.0",
license = @License(name = "Apache 2.0")
)
)
@Configuration
public class OpenApiConfiguration {

final BuildProperties buildProperties;

public OpenApiConfiguration(BuildProperties buildProperties) {
this.buildProperties = buildProperties;
}

@Bean
public OpenAPI customOpenAPI() {
return new OpenAPI().info(new io.swagger.v3.oas.models.info.Info()
.title("5G EVE Experiment NSD composer")
.description("A REST API module to compose experiment NSDs. "
+ "It can also validate blueprints and generate NSDs from them.")
.version(buildProperties.getVersion())
.license(new io.swagger.v3.oas.models.info.License().name("Apache 2.0"))
.contact(new Contact()
.name("GitHub")
.url("https://github.com/5GEVE/-exp-nsd-composer/")));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package it.cnit.blueprint.composer.commons;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.SerializationFeature;
import it.nextworks.nfvmano.catalogue.blueprint.elements.Blueprint;
import it.nextworks.nfvmano.libs.ifa.descriptors.nsd.Nsd;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Service
@Slf4j
@AllArgsConstructor
public class ObjectMapperService {

private final ObjectMapper objectMapper;

/**
* @return An ObjectMapper with FAIL_ON_UNKNOWN_PROPERTIES=false
*/
public ObjectReader createSafeBlueprintReader() {
return objectMapper.readerFor(Blueprint.class)
.without(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
}

/**
* @return An ObjectMapper with INDENT_OUTPUT=true
*/
public ObjectWriter createIndentNsdWriter() {
return objectMapper.writerFor(Nsd.class).with(SerializationFeature.INDENT_OUTPUT);
}

}
54 changes: 54 additions & 0 deletions src/main/java/it/cnit/blueprint/composer/commons/ZipService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package it.cnit.blueprint.composer.commons;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

@Service
@Slf4j
@AllArgsConstructor
public class ZipService {

@SuppressWarnings("ResultOfMethodCallIgnored")
public ResponseEntity<InputStreamResource> getZipResponse(List<File> files, boolean cleanUp)
throws IOException {
File zipFile = Files.createTempFile("enc-output-", ".zip").toFile();
ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile));
for (File f : files) {
zipOut.putNextEntry(new ZipEntry(f.getName()));
FileInputStream fis = new FileInputStream(f);
byte[] bytes = new byte[1024];
int length;
while ((length = fis.read(bytes)) >= 0) {
zipOut.write(bytes, 0, length);
}
fis.close();
}
zipOut.close();
ResponseEntity<InputStreamResource> response = ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=" + zipFile.getName())
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.contentLength(zipFile.length())
.body(new InputStreamResource(new FileInputStream(zipFile)));
if (cleanUp){
for (File f : files) {
f.delete();
}
zipFile.delete();
}
return response;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ public Nsd generate(Blueprint b) throws NsdGenerationException {
addressData.setAddressType(AddressType.IP_ADDRESS);
addressData.setiPAddressType(IpVersion.IPv4);
addressData.setiPAddressAssignment(false);
addressData.setFloatingIpActivated(true);
addressData.setFloatingIpActivated(false);
addressData.setNumberOfIpAddress(1);
if (e.isManagement()) {
addressData.setManagement(true);
}
sapd.setAddressData(Collections.singletonList(addressData));

sapdList.add(sapd);
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 7570b13

Please sign in to comment.