Commit 7710e143 authored by Alicja Reniewicz's avatar Alicja Reniewicz
Browse files

Merge branch 'rc3.1' into 'master'

Rc3.1

See merge request melodic/melodic-upperware!14
parents 6b78216f ba1fa74e
Pipeline #19882 passed with stages
in 22 minutes and 19 seconds
package eu.melodic.upperware.guibackend.exception.controller;
import eu.melodic.upperware.guibackend.exception.CamundaErrorVariableException;
import eu.melodic.upperware.guibackend.exception.SecureVariableNotFoundException;
import eu.passage.upperware.commons.exception.SecureVariableNotFoundException;
import eu.melodic.upperware.guibackend.exception.response.CamundaVariableErrorResponse;
import eu.melodic.upperware.guibackend.exception.response.MissingSecureVariableErrorResponse;
import org.springframework.http.HttpStatus;
......
......@@ -43,6 +43,10 @@ public class GuiBackendProperties {
@NotNull
private ExternalService metaSolver;
@Valid
@NotNull
private ExternalService functionizerTestingTool;
@Getter
@Setter
public static class Mule extends ExternalService {
......
package eu.melodic.upperware.guibackend.service.byon;
import eu.melodic.upperware.guibackend.model.byon.ByonDefinition;
import eu.melodic.upperware.guibackend.model.byon.IpAddress;
import eu.passage.upperware.commons.model.byon.ByonDefinition;
import eu.passage.upperware.commons.model.byon.IpAddress;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......
package eu.melodic.upperware.guibackend.service.byon;
import eu.melodic.upperware.guibackend.model.byon.ByonDefinition;
import eu.passage.upperware.commons.model.byon.ByonDefinition;
import io.github.cloudiator.rest.model.IpAddress;
import io.github.cloudiator.rest.model.NewNode;
import io.github.cloudiator.rest.model.NodeProperties;
......@@ -20,7 +20,7 @@ public class ByonMapper {
return newNode;
}
private NodeProperties mapGuiNodePropertiesToCloudiatorNodeProperties(eu.melodic.upperware.guibackend.model.byon.NodeProperties guiNodeProperties) {
private NodeProperties mapGuiNodePropertiesToCloudiatorNodeProperties(eu.passage.upperware.commons.model.byon.NodeProperties guiNodeProperties) {
NodeProperties resultNodeProperties = new NodeProperties();
resultNodeProperties.setProviderId(guiNodeProperties.getProviderId());
resultNodeProperties.setNumberOfCores(guiNodeProperties.getNumberOfCores());
......@@ -31,7 +31,7 @@ public class ByonMapper {
return resultNodeProperties;
}
private List<IpAddress> mapGuiIpAddressesToCloudiatorIpAddresses(List<eu.melodic.upperware.guibackend.model.byon.IpAddress> ipAddresses) {
private List<IpAddress> mapGuiIpAddressesToCloudiatorIpAddresses(List<eu.passage.upperware.commons.model.byon.IpAddress> ipAddresses) {
return ipAddresses.stream()
.map(ipAddress -> (IpAddress) ipAddress)
.collect(Collectors.toList());
......
package eu.melodic.upperware.guibackend.service.byon;
import eu.melodic.upperware.guibackend.communication.cloudiator.CloudiatorApi;
import eu.passage.upperware.commons.cloudiator.CloudiatorApi;
import eu.melodic.upperware.guibackend.exception.ByonDefinitionNotFoundException;
import eu.melodic.upperware.guibackend.model.byon.ByonDefinition;
import eu.melodic.upperware.guibackend.model.byon.ByonEnums;
import eu.melodic.upperware.guibackend.model.byon.LoginCredential;
import eu.melodic.upperware.guibackend.service.secure.store.SecureStoreService;
import eu.melodic.upperware.guibackend.service.yaml.YamlDataService;
import eu.passage.upperware.commons.model.byon.ByonDefinition;
import eu.passage.upperware.commons.model.byon.ByonEnums;
import eu.passage.upperware.commons.model.byon.LoginCredential;
import eu.passage.upperware.commons.service.store.SecureStoreService;
import eu.passage.upperware.commons.service.yaml.YamlDataService;
import io.github.cloudiator.rest.model.*;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
......
......@@ -2,6 +2,7 @@ package eu.melodic.upperware.guibackend.service.cdo;
import camel.core.CamelModel;
import camel.core.NamedElement;
import camel.deployment.impl.DeploymentTypeModelImpl;
import camel.requirement.OptimisationRequirement;
import camel.requirement.RequirementModel;
import camel.requirement.impl.OptimisationRequirementImpl;
......@@ -32,7 +33,9 @@ import org.springframework.web.server.ResponseStatusException;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@Service
......@@ -43,7 +46,7 @@ public class CdoService {
private CpModelMapper cpModelMapper;
private GuiBackendProperties guiBackendProperties;
public boolean storeFileInCdo(String cdoName, File file) {
public boolean storeFileInCdo(String cdoName, File file) throws Exception {
log.info("Storing Model {} into CDO with validationEnabled = {}", cdoName, guiBackendProperties.getCdoUploader().isValidationEnabled());
EObject model = null;
......@@ -55,12 +58,47 @@ public class CdoService {
return false;
}
log.info("Checking model's software components name uniqueness");
String duplicateName = validateServerlessComponentNameUniqueness(model);
if (duplicateName != null) {
client.closeSession();
log.error("Software component's name '{}' " +
"is used in more than one component.",
duplicateName
);
throw new Exception(
String.format(
"Software component's name '%s' is used in more than one component." +
" Modify the file to have unique software component names and try again.",
duplicateName
)
);
}
log.info("Validation passed");
boolean successfullyStored = client.storeModel(model, cdoName, guiBackendProperties.getCdoUploader().isValidationEnabled());
log.info("Successfully stored of model {} in CDO = {}", cdoName, successfullyStored);
client.closeSession();
return successfullyStored;
}
private String validateServerlessComponentNameUniqueness(EObject model) {
CamelModel camelModel = (CamelModel) model;
DeploymentTypeModelImpl depModel = (DeploymentTypeModelImpl) camelModel.getDeploymentModels().get(0);
List<String> names = depModel.getSoftwareComponents()
.stream()
.map(NamedElement::getName)
.collect(Collectors.toList());
Set<String> uniqueNames = new HashSet<>();
for (String name : names) {
if (!uniqueNames.add(name)) {
return name;
}
}
return null;
}
public boolean deleteXmi(String cdoName) {
log.info("Deleting model {} from CDO", cdoName);
CDOClient client = getCdoClient();
......
......@@ -8,7 +8,7 @@ import eu.melodic.upperware.guibackend.communication.mule.deployment.CloudConfig
import eu.melodic.upperware.guibackend.communication.mule.deployment.CloudDefinitionRequest;
import eu.melodic.upperware.guibackend.communication.mule.deployment.CredentialRequest;
import eu.melodic.upperware.guibackend.controller.deployment.request.DeploymentRequest;
import eu.melodic.upperware.guibackend.model.provider.*;
import eu.passage.upperware.commons.model.provider.*;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
......
......@@ -4,14 +4,14 @@ import eu.melodic.models.commons.Watermark;
import eu.melodic.models.commons.WatermarkImpl;
import eu.melodic.models.services.frontend.DeploymentProcessRequest;
import eu.melodic.upperware.guibackend.communication.mule.MuleApi;
import eu.melodic.upperware.guibackend.controller.deployment.common.SecureVariable;
import eu.passage.upperware.commons.model.SecureVariable;
import eu.melodic.upperware.guibackend.controller.deployment.request.DeploymentRequest;
import eu.melodic.upperware.guibackend.controller.deployment.response.DeploymentResponse;
import eu.melodic.upperware.guibackend.controller.deployment.response.UploadXmiResponse;
import eu.melodic.upperware.guibackend.service.cdo.CdoService;
import eu.melodic.upperware.guibackend.service.cdo.ModelNameGenerator;
import eu.melodic.upperware.guibackend.service.provider.ProviderService;
import eu.melodic.upperware.guibackend.service.secure.store.SecureStoreService;
import eu.passage.upperware.commons.service.provider.ProviderService;
import eu.passage.upperware.commons.service.store.SecureStoreService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.net4j.connector.ConnectorException;
......@@ -91,6 +91,8 @@ public class DeploymentService {
} catch (IllegalStateException e) {
log.error("Error by uploading xmi file:", e);
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, String.format("Problem by uploading your %s file. CDO repository is in pending state. Please try again.", uploadXmiRequest.getResource().getFilename()));
} catch (Exception e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
}
}
......
package eu.melodic.upperware.guibackend.service.testing;
import eu.melodic.upperware.guibackend.controller.testing.response.TestConfigurationResponse;
import eu.passage.upperware.commons.MelodicConstants;
import eu.passage.upperware.commons.model.testing.FunctionTestConfiguration;
import eu.passage.upperware.commons.model.testing.TestConfiguration;
import eu.passage.upperware.commons.service.testing.TestConfigurationValidationService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.server.ResponseStatusException;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
import org.yaml.snakeyaml.constructor.ConstructorException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.IOException;
import static eu.passage.upperware.commons.service.testing.TestConfigurationValidationService.checkFunctionNamesUniqueness;
import static eu.passage.upperware.commons.service.testing.TestConfigurationValidationService.checkTestCasesUniqueness;
@Service
@Slf4j
@AllArgsConstructor(onConstructor = @__(@Autowired))
public class TestingService {
private final static String CONFIG_FILE_PATH = MelodicConstants.TEST_CONFIG_FILE_DIR + "/tests.yml";
public TestConfigurationResponse uploadTestConfig(MultipartFile uploadFileRequest) {
try {
if (uploadFileRequest.getOriginalFilename() == null) {
throw new ResponseStatusException(
HttpStatus.BAD_REQUEST,
String.format("Problem by uploading your %s file. Please try again.",
uploadFileRequest.getResource().getFilename()
));
}
File newFile = new File(CONFIG_FILE_PATH);
if (!newFile.exists()) {
newFile.getParentFile().mkdirs();
}
TestConfiguration configuration = loadAndValidateTestConfiguration(
uploadFileRequest.getInputStream()
);
uploadFileRequest.transferTo(newFile);
log.info(
"File {} successfully stored under path: {}",
uploadFileRequest.getResource().getFilename(),
CONFIG_FILE_PATH
);
return createTestConfigResponse(configuration);
} catch (IOException | IllegalStateException e) {
log.error("Error by uploading test configuration file:", e);
throw new ResponseStatusException(
HttpStatus.BAD_REQUEST,
String.format("Problem by uploading your %s file. Please try again.",
uploadFileRequest.getResource().getFilename()
));
}
}
public TestConfigurationResponse getTestConfiguration() {
File configFile = new File(CONFIG_FILE_PATH);
InputStream ymlFileInputStream;
try {
ymlFileInputStream = new FileInputStream(configFile);
} catch (FileNotFoundException e) {
throw new ResponseStatusException(
HttpStatus.NOT_FOUND,
"Test configuration file not found on server."
);
}
TestConfiguration testConfiguration = loadTestConfiguration(ymlFileInputStream);
return createTestConfigResponse(testConfiguration);
}
public void removeTestConfigFile() {
File configFile = new File(CONFIG_FILE_PATH);
if (!configFile.exists()) {
log.info("No file to delete. Ending");
return;
}
if (configFile.delete()) {
log.info("Successfully removed file {}", configFile.getName());
} else {
log.error("Error while deleting test configuration file.");
throw new ResponseStatusException(
HttpStatus.BAD_REQUEST,
String.format("Could not remove file %s.", configFile.getName())
);
}
}
private TestConfigurationResponse createTestConfigResponse(TestConfiguration configuration) {
return new TestConfigurationResponse(CONFIG_FILE_PATH, configuration);
}
private TestConfiguration loadTestConfiguration(InputStream ymlFileInputStream) {
Yaml yaml = new Yaml(new Constructor(TestConfiguration.class));
try {
return yaml.load(ymlFileInputStream);
} catch (ConstructorException e) {
String errorMessage = "The file has a bad structure and could not be parsed.";
log.error(errorMessage);
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, errorMessage);
}
}
private TestConfiguration loadAndValidateTestConfiguration(
InputStream ymlFileInputStream
) throws ResponseStatusException {
TestConfiguration configuration;
try {
configuration = loadTestConfiguration(ymlFileInputStream);
log.info("Checking uniqueness of function names");
checkFunctionNamesUniqueness(configuration.getTests());
log.info("Checking uniqueness of test cases");
for (FunctionTestConfiguration functionTestConfiguration : configuration.getTests()) {
checkTestCasesUniqueness(
functionTestConfiguration.getTestCases(),
functionTestConfiguration.getFunctionName()
);
}
} catch (ConstructorException e) {
String errorMessage = "The file has a bad structure and could not be parsed.";
log.error(errorMessage);
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, errorMessage);
} catch (
TestConfigurationValidationService.NotUniqueFunctionNameException
| TestConfigurationValidationService.NotUniqueTestCaseException e
) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
}
return configuration;
}
}
......@@ -7,7 +7,7 @@
<parent>
<groupId>org.ow2.paasage</groupId>
<artifactId>upperware</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</parent>
<artifactId>jwt-commons</artifactId>
......@@ -51,4 +51,4 @@
<artifactId>interfaces</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
</project>
......@@ -7,7 +7,7 @@
<parent>
<groupId>org.ow2.paasage</groupId>
<artifactId>upperware</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</parent>
<artifactId>jwt-server</artifactId>
......@@ -127,4 +127,4 @@
</plugins>
</build>
</project>
\ No newline at end of file
</project>
......@@ -12,7 +12,7 @@
<parent>
<groupId>org.ow2.paasage</groupId>
<artifactId>upperware</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</parent>
<artifactId>la-converter</artifactId>
......@@ -137,4 +137,4 @@
</build>
</profile>
</profiles>
</project>
\ No newline at end of file
</project>
......@@ -7,7 +7,7 @@
<parent>
<groupId>org.ow2.paasage</groupId>
<artifactId>upperware</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</parent>
<artifactId>melodic-cache</artifactId>
......@@ -66,4 +66,4 @@
</dependencies>
</project>
\ No newline at end of file
</project>
......@@ -7,11 +7,11 @@
<parent>
<groupId>org.ow2.paasage</groupId>
<artifactId>upperware</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
</parent>
<artifactId>melodic-commons</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<name>Upperware - Melodic commons</name>
......@@ -33,12 +33,24 @@
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.21</version>
</dependency>
<dependency>
<groupId>eu.melodic.cdo</groupId>
<artifactId>client</artifactId>
<classifier>repackaged</classifier>
</dependency>
<dependency>
<groupId>io.github.cloudiator.client</groupId>
<artifactId>java-rest</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
......@@ -59,6 +71,24 @@
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-engine</artifactId>
</dependency>
</dependencies>
......
......@@ -14,6 +14,7 @@ public class MelodicConstants {
public static final String TOMCAT_TEM_DIR= ".."+File.separator+"temp"+File.separator;
public static final String TOMCAT_GENERATION_DIR= TOMCAT_TEM_DIR+"paasage"+File.separator+"configurations"+File.separator;
public static final String TOMCAT_ALT_GENERATION_TEMP_DIR= TOMCAT_ALT_TEM_DIR+"paasage"+File.separator+"configurations"+File.separator;
public static final String TEST_CONFIG_FILE_DIR = System.getenv("MELODIC_CONFIG_DIR") + File.separator + "tests";
private MelodicConstants() {}
}
package eu.melodic.upperware.guibackend.communication.cloudiator;
package eu.passage.upperware.commons.cloudiator;
import io.github.cloudiator.rest.model.*;
......
package eu.melodic.upperware.guibackend.communication.cloudiator;
package eu.passage.upperware.commons.cloudiator;
import eu.melodic.upperware.guibackend.exception.SecureVariableNotFoundException;
import eu.passage.upperware.commons.exception.SecureVariableNotFoundException;
import io.github.cloudiator.rest.ApiException;
import io.github.cloudiator.rest.api.*;
import io.github.cloudiator.rest.model.*;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.ListUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.server.ResponseStatusException;
import javax.ws.rs.NotFoundException;
......@@ -17,8 +15,7 @@ import java.util.List;
import java.util.stream.Collectors;
@Slf4j
@Service
@AllArgsConstructor(onConstructor = @__({@Autowired}))
@AllArgsConstructor
public class CloudiatorClientApi implements CloudiatorApi {
private CloudApi cloudApi;
......
package eu.melodic.upperware.guibackend.communication.cloudiator;
package eu.passage.upperware.commons.cloudiator;
import eu.passage.upperware.commons.cloudiator.CloudiatorProperties;
import io.github.cloudiator.rest.ApiException;
import io.github.cloudiator.rest.api.QueueApi;
import io.github.cloudiator.rest.model.Queue;
import io.github.cloudiator.rest.model.QueueStatus;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.server.ResponseStatusException;
@Slf4j
@Service
@AllArgsConstructor(onConstructor = @__({@Autowired}))
@AllArgsConstructor
public class QueueInspector {
private QueueApi queueApi;
......
package eu.melodic.upperware.guibackend.exception;
package eu.passage.upperware.commons.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
......
Supports Markdown
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