From 68603e0cae4d85bff634eaa42c204fc3d16c9525 Mon Sep 17 00:00:00 2001 From: Alexandre Lagane Date: Tue, 2 Oct 2018 11:19:02 +0200 Subject: [PATCH 01/21] Starting model --- .gitignore | 87 +++++++++++++++++++ pom.xml | 20 +++++ .../petals/deploymentmodel/busmodel/Bus.java | 49 +++++++++++ .../deploymentmodel/busmodel/BusModel.java | 58 +++++++++++++ .../busmodel/ComponentInstance.java | 66 ++++++++++++++ .../busmodel/ContainerInstance.java | 79 +++++++++++++++++ .../busmodel/HazelcastRegistryInstance.java | 67 ++++++++++++++ .../HazelcastRegistryMemberInstance.java | 51 +++++++++++ .../deploymentmodel/busmodel/Machine.java | 21 +++++ .../busmodel/ProvisionedMachine.java | 21 +++++ .../busmodel/RegistryInstance.java | 9 ++ .../busmodel/ServiceUnitInstance.java | 38 ++++++++ .../busmodel/StandaloneRegistryInstance.java | 20 +++++ .../busmodel/TopologyInstance.java | 65 ++++++++++++++ .../componentrepository/Component.java | 67 ++++++++++++++ .../ComponentRepository.java | 39 +++++++++ .../componentrepository/SharedLibrary.java | 51 +++++++++++ .../serviceunitmodel/ServiceUnit.java | 67 ++++++++++++++ .../serviceunitmodel/ServiceUnitModel.java | 25 ++++++ .../topologymodel/Container.java | 61 +++++++++++++ .../topologymodel/HazelcastRegistry.java | 51 +++++++++++ .../HazelcastRegistryMember.java | 35 ++++++++ .../topologymodel/Registry.java | 21 +++++ .../topologymodel/StandaloneRegistry.java | 9 ++ .../topologymodel/Topology.java | 60 +++++++++++++ .../topologymodel/TopologyModel.java | 25 ++++++ 26 files changed, 1162 insertions(+) create mode 100644 .gitignore create mode 100644 pom.xml create mode 100644 src/main/java/org/ow2/petals/deploymentmodel/busmodel/Bus.java create mode 100644 src/main/java/org/ow2/petals/deploymentmodel/busmodel/BusModel.java create mode 100644 src/main/java/org/ow2/petals/deploymentmodel/busmodel/ComponentInstance.java create mode 100644 src/main/java/org/ow2/petals/deploymentmodel/busmodel/ContainerInstance.java create mode 100644 src/main/java/org/ow2/petals/deploymentmodel/busmodel/HazelcastRegistryInstance.java create mode 100644 src/main/java/org/ow2/petals/deploymentmodel/busmodel/HazelcastRegistryMemberInstance.java create mode 100644 src/main/java/org/ow2/petals/deploymentmodel/busmodel/Machine.java create mode 100644 src/main/java/org/ow2/petals/deploymentmodel/busmodel/ProvisionedMachine.java create mode 100644 src/main/java/org/ow2/petals/deploymentmodel/busmodel/RegistryInstance.java create mode 100644 src/main/java/org/ow2/petals/deploymentmodel/busmodel/ServiceUnitInstance.java create mode 100644 src/main/java/org/ow2/petals/deploymentmodel/busmodel/StandaloneRegistryInstance.java create mode 100644 src/main/java/org/ow2/petals/deploymentmodel/busmodel/TopologyInstance.java create mode 100644 src/main/java/org/ow2/petals/deploymentmodel/componentrepository/Component.java create mode 100644 src/main/java/org/ow2/petals/deploymentmodel/componentrepository/ComponentRepository.java create mode 100644 src/main/java/org/ow2/petals/deploymentmodel/componentrepository/SharedLibrary.java create mode 100644 src/main/java/org/ow2/petals/deploymentmodel/serviceunitmodel/ServiceUnit.java create mode 100644 src/main/java/org/ow2/petals/deploymentmodel/serviceunitmodel/ServiceUnitModel.java create mode 100644 src/main/java/org/ow2/petals/deploymentmodel/topologymodel/Container.java create mode 100644 src/main/java/org/ow2/petals/deploymentmodel/topologymodel/HazelcastRegistry.java create mode 100644 src/main/java/org/ow2/petals/deploymentmodel/topologymodel/HazelcastRegistryMember.java create mode 100644 src/main/java/org/ow2/petals/deploymentmodel/topologymodel/Registry.java create mode 100644 src/main/java/org/ow2/petals/deploymentmodel/topologymodel/StandaloneRegistry.java create mode 100644 src/main/java/org/ow2/petals/deploymentmodel/topologymodel/Topology.java create mode 100644 src/main/java/org/ow2/petals/deploymentmodel/topologymodel/TopologyModel.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b8d1c59 --- /dev/null +++ b/.gitignore @@ -0,0 +1,87 @@ + +# Created by https://www.gitignore.io/api/maven,eclipse + +### Eclipse ### + +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +.recommenders + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# PyDev specific (Python IDE for Eclipse) +*.pydevproject + +# CDT-specific (C/C++ Development Tooling) +.cproject + +# CDT- autotools +.autotools + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target + +# Tern plugin +.tern-project + +# TeXlipse plugin +.texlipse + +# STS (Spring Tool Suite) +.springBeans + +# Code Recommenders +.recommenders/ + +# Annotation Processing +.apt_generated/ + +# Scala IDE specific (Scala & Java development for Eclipse) +.cache-main +.scala_dependencies +.worksheet + +### Eclipse Patch ### +# Eclipse Core +.project + +# JDT-specific (Eclipse Java Development Tools) +.classpath + +# Annotation Processing +.apt_generated + +.sts4-cache/ + +### Maven ### +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties +.mvn/wrapper/maven-wrapper.jar + + +# End of https://www.gitignore.io/api/maven,eclipse diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..5f3ca7a --- /dev/null +++ b/pom.xml @@ -0,0 +1,20 @@ + + 4.0.0 + + org.ow2.petals + petals-esb-deployer + 0.0.1-SNAPSHOT + jar + + petals-esb-deployer + https://doc.petalslink.com/display/petalscomponents/Petals+ESB+Deployer+1.0.0 + + + UTF-8 + + + + + diff --git a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/Bus.java b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/Bus.java new file mode 100644 index 0000000..0ba5f4a --- /dev/null +++ b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/Bus.java @@ -0,0 +1,49 @@ +package org.ow2.petals.deploymentmodel.busmodel; + +import java.util.List; + +/** + * Class for Petals ESB bus to deploy + * + * @author alagane + */ +public class Bus { + /** + * The service unit instances to deploy + */ + private List serviceUnitInstances; + + /** + * The component instances required by a service unit + */ + private List componentInstances; + + /** + * The topology instance associated to a topology defined in {@link org.ow2.petals.deploymentmodel.topologymodel.TopologyModel}. + */ + private TopologyInstance topologyInstance; + + public List getServiceUnitInstances() { + return serviceUnitInstances; + } + + public void setServiceUnitInstances(final List serviceUnitInstances) { + this.serviceUnitInstances = serviceUnitInstances; + } + + public List getComponentInstances() { + return componentInstances; + } + + public void setComponentInstances(final List componentInstances) { + this.componentInstances = componentInstances; + } + + public TopologyInstance getTopologyInstance() { + return topologyInstance; + } + + public void setTopologyInstance(final TopologyInstance topologyInstance) { + this.topologyInstance = topologyInstance; + } +} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/BusModel.java b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/BusModel.java new file mode 100644 index 0000000..5fc91ce --- /dev/null +++ b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/BusModel.java @@ -0,0 +1,58 @@ +package org.ow2.petals.deploymentmodel.busmodel; + +import java.util.List; +import java.util.Map; + +/** + * This model defines your Petals ESB bus placing Petals ESB components on their containers: + *
    + *
  • service-unit on its Petals ESB container
  • + *
  • Petals ESB container on its machine
  • + *
  • Petals ESB Hazelcast Registry member on its machine.
  • + *
+ * This model will be mainly written by the Petals ESB bus architect in agreement with operators. + * + * @author alagane + */ +public class BusModel { + /** + * The list of Petals ESB busses to deploy. + */ + private List buses; + + /** + * The map of placeholder values required by all of the service units. The key of the map is the key of the + * placeholder, and the value of the map is the value of the placeholder. Only keys declared in service unit models + * can be used, and every key declared without a default value must have a value assigned in this map. + */ + private Map placeholderValues; + + /** + * The machines on which parts of a Petals ESB bus will be running. + */ + private List machines; + + public List getBuses() { + return buses; + } + + public void setBuses(final List buses) { + this.buses = buses; + } + + public Map getPlaceholderValues() { + return placeholderValues; + } + + public void setPlaceholderValues(final Map placeholderValues) { + this.placeholderValues = placeholderValues; + } + + public List getMachines() { + return machines; + } + + public void setMachines(final List machines) { + this.machines = machines; + } +} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/ComponentInstance.java b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/ComponentInstance.java new file mode 100644 index 0000000..448bcae --- /dev/null +++ b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/ComponentInstance.java @@ -0,0 +1,66 @@ +package org.ow2.petals.deploymentmodel.busmodel; + +import java.util.List; +import java.util.Map; + +import org.ow2.petals.deploymentmodel.componentrepository.Component; +import org.ow2.petals.deploymentmodel.componentrepository.SharedLibrary; + +/** + * Class describing an instance of a component defined in + * {@link org.ow2.petals.deploymentmodel.componentrepository.ComponentRepository}. + * + * @author alagane + */ +public class ComponentInstance { + private String id; + + /** + * Reference to a component from {@link org.ow2.petals.deploymentmodel.componentrepository.ComponentRepository}. + */ + private Component reference; + + /** + * The map of parameter values required by all of the service units. The key of the map is the name of the + * parameter, and the value of the map is the value of the parameter. Only names declared in reference component can + * be used, and every name declared without a default value must have a value assigned in this map. + */ + private Map placeholderValues; + + /** + * List of shared libraries in addition to these of the referenced component. + */ + private List sharedLibraryReferences; + + public String getId() { + return id; + } + + public void setId(final String id) { + this.id = id; + } + + public Component getReference() { + return reference; + } + + public void setReference(final Component reference) { + this.reference = reference; + } + + public Map getPlaceholderValues() { + return placeholderValues; + } + + public void setPlaceholderValues(final Map placeholderValues) { + this.placeholderValues = placeholderValues; + } + + public List getSharedLibraryReferences() { + return sharedLibraryReferences; + } + + public void setSharedLibraryReferences(final List sharedLibraryReferences) { + this.sharedLibraryReferences = sharedLibraryReferences; + } +} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/ContainerInstance.java b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/ContainerInstance.java new file mode 100644 index 0000000..e5fbfc7 --- /dev/null +++ b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/ContainerInstance.java @@ -0,0 +1,79 @@ +package org.ow2.petals.deploymentmodel.busmodel; + +import org.ow2.petals.deploymentmodel.topologymodel.Container; + +/** + * Class describing an instance of a container defined in + * {@link org.ow2.petals.deploymentmodel.topologymodel.TopologyModel}. + * + * @author alagane + */ +public class ContainerInstance { + /** + * Reference to a container from {@link org.ow2.petals.deploymentmodel.topologymodel.TopologyModel}. + */ + private Container reference; + + /** + * JMX port of the current Petals ESB container. A deployment property can be used. Each container (from topology + * model) without a default JMX port must have one defined in this model. + */ + private int jmxPort; + + /** + * JMX username of the current Petals ESB container. A deployment property can be used. Each container (from + * topology model) without a default JMX username must have one defined in this model. + */ + private String jmxUser; + + /** + * JMX password of the current Petals ESB container. A deployment property can be used. Each container (from + * topology model) without a default JMX password must have one defined in this model. + */ + private String jmxPassword; + + /** + * The reference of the machine on which the container is running. + */ + private Machine machineReference; + + public Container getReference() { + return reference; + } + + public void setReference(final Container reference) { + this.reference = reference; + } + + public int getJmxPort() { + return jmxPort; + } + + public void setJmxPort(final int jmxPort) { + this.jmxPort = jmxPort; + } + + public String getJmxUser() { + return jmxUser; + } + + public void setJmxUser(final String jmxUser) { + this.jmxUser = jmxUser; + } + + public String getJmxPassword() { + return jmxPassword; + } + + public void setJmxPassword(final String jmxPassword) { + this.jmxPassword = jmxPassword; + } + + public Machine getMachineReference() { + return machineReference; + } + + public void setMachineReference(final Machine machineReference) { + this.machineReference = machineReference; + } +} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/HazelcastRegistryInstance.java b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/HazelcastRegistryInstance.java new file mode 100644 index 0000000..76b361f --- /dev/null +++ b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/HazelcastRegistryInstance.java @@ -0,0 +1,67 @@ +package org.ow2.petals.deploymentmodel.busmodel; + +import java.util.List; + +import org.ow2.petals.deploymentmodel.topologymodel.HazelcastRegistry; + +/** + * Class describing an Hazelcast Registry instance of a Petals ESB bus. + * + * @author alagane + */ +public class HazelcastRegistryInstance extends RegistryInstance { + /** + * The reference of the Petals ESB Hazelcast Registry in + * {@link org.ow2.petals.deploymentmodel.topologymodel.TopologyModel}. + */ + private HazelcastRegistry reference; + + /** + * Name identifying the Petals ESB Hazelcast Registry instance inside the Hazelcast cluster. A deployment property + * can be used. Optional, if not set, the value defined by the referenced HazelcastRegistry will be used. + */ + private String groupName; + + /** + * Password identifying the Petals ESB Hazelcast Registry instance inside the Hazelcast cluster. A deployment + * property can be used. Optional, if not set, the value defined by the referenced HazelcastRegistry will be used. + */ + private String groupPassword; + + /** + * List of member instances composing the current Petals ESB Hazelcast Registry instance. + */ + private List memberInstances; + + public HazelcastRegistry getReference() { + return reference; + } + + public void setReference(final HazelcastRegistry reference) { + this.reference = reference; + } + + public String getGroupName() { + return groupName; + } + + public void setGroupName(final String groupName) { + this.groupName = groupName; + } + + public String getGroupPassword() { + return groupPassword; + } + + public void setGroupPassword(final String groupPassword) { + this.groupPassword = groupPassword; + } + + public List getMemberInstances() { + return memberInstances; + } + + public void setMemberInstances(final List memberInstances) { + this.memberInstances = memberInstances; + } +} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/HazelcastRegistryMemberInstance.java b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/HazelcastRegistryMemberInstance.java new file mode 100644 index 0000000..2363343 --- /dev/null +++ b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/HazelcastRegistryMemberInstance.java @@ -0,0 +1,51 @@ +package org.ow2.petals.deploymentmodel.busmodel; + +import org.ow2.petals.deploymentmodel.topologymodel.HazelcastRegistryMember; + +/** + * Class describing a member of a Petals ESB Hazelcast Registry instance. + * + * @author alagane + */ +public class HazelcastRegistryMemberInstance { + /** + * The reference of the member of the Petals ESB Hazelcast Registry in + * {@link org.ow2.petals.deploymentmodel.topologymodel.TopologyModel}. + */ + private HazelcastRegistryMember reference; + + /** + * The communication port of the member instance. A deployment property can be used. Optional, if not set, the value + * defined by the referenced {@link HazelcastRegistryMember} will be used. + */ + private String port; + + /** + * The reference of the machine on which the current Petals ESB Hazelcast Registry is running. + */ + private Machine machineReference; + + public HazelcastRegistryMember getReference() { + return reference; + } + + public void setReference(final HazelcastRegistryMember reference) { + this.reference = reference; + } + + public String getPort() { + return port; + } + + public void setPort(final String port) { + this.port = port; + } + + public Machine getMachineReference() { + return machineReference; + } + + public void setMachineReference(final Machine machineReference) { + this.machineReference = machineReference; + } +} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/Machine.java b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/Machine.java new file mode 100644 index 0000000..9e1dd6b --- /dev/null +++ b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/Machine.java @@ -0,0 +1,21 @@ +package org.ow2.petals.deploymentmodel.busmodel; + +/** + * Superclass for different types of machines on which Petals ESB buses or Hazelcast registry members will be running. + * + * @author alagane + */ +public abstract class Machine { + /** + * Identifier of the machine. + */ + private String id; + + public String getId() { + return id; + } + + public void setId(final String id) { + this.id = id; + } +} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/ProvisionedMachine.java b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/ProvisionedMachine.java new file mode 100644 index 0000000..847cd17 --- /dev/null +++ b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/ProvisionedMachine.java @@ -0,0 +1,21 @@ +package org.ow2.petals.deploymentmodel.busmodel; + +/** + * Class describing physical or virtual machine. + * + * @author alagane + */ +public class ProvisionedMachine extends Machine { + /** + * Hostname, IP address or deployment property name of the provisioned machine. + */ + private String hostname; + + public String getHostname() { + return hostname; + } + + public void setHostname(final String hostname) { + this.hostname = hostname; + } +} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/RegistryInstance.java b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/RegistryInstance.java new file mode 100644 index 0000000..12c173c --- /dev/null +++ b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/RegistryInstance.java @@ -0,0 +1,9 @@ +package org.ow2.petals.deploymentmodel.busmodel; + +/** + * Superclass for different types of registry instances. + * + * @author alagane + */ +public abstract class RegistryInstance { +} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/ServiceUnitInstance.java b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/ServiceUnitInstance.java new file mode 100644 index 0000000..4ea8932 --- /dev/null +++ b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/ServiceUnitInstance.java @@ -0,0 +1,38 @@ +package org.ow2.petals.deploymentmodel.busmodel; + +import java.awt.Container; + +import org.ow2.petals.deploymentmodel.serviceunitmodel.ServiceUnit; + +/** + * Class for instance of a service unit running on a Petals ESB container + * + * @author alagane + */ +public class ServiceUnitInstance { + /** + * Reference to a service-unit of the service-units object model + */ + private ServiceUnit reference; + + /** + * Reference to a container of the topology object model + */ + private Container containerReference; + + public ServiceUnit getReference() { + return reference; + } + + public void setReference(final ServiceUnit reference) { + this.reference = reference; + } + + public Container getContainerReference() { + return containerReference; + } + + public void setContainerReference(final Container containerReference) { + this.containerReference = containerReference; + } +} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/StandaloneRegistryInstance.java b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/StandaloneRegistryInstance.java new file mode 100644 index 0000000..0df120d --- /dev/null +++ b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/StandaloneRegistryInstance.java @@ -0,0 +1,20 @@ +package org.ow2.petals.deploymentmodel.busmodel; + +import org.ow2.petals.deploymentmodel.topologymodel.StandaloneRegistry; + +/** + * Instance of {@link org.ow2.petals.deploymentmodel.topologymodel.StandaloneRegistry}. + * + * @author alagane + */ +public class StandaloneRegistryInstance extends RegistryInstance { + private StandaloneRegistry reference; + + public StandaloneRegistry getReference() { + return reference; + } + + public void setReference(final StandaloneRegistry reference) { + this.reference = reference; + } +} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/TopologyInstance.java b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/TopologyInstance.java new file mode 100644 index 0000000..e166fa3 --- /dev/null +++ b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/TopologyInstance.java @@ -0,0 +1,65 @@ +package org.ow2.petals.deploymentmodel.busmodel; + +import java.util.List; + +import org.ow2.petals.deploymentmodel.topologymodel.Topology; + +/** + * Class describing an instance of a topology in {@link org.ow2.petals.deploymentmodel.busmodel.BusModel}. + * + * @author alagane + */ +public class TopologyInstance { + /** + * The reference topology from {@link org.ow2.petals.deploymentmodel.topologymodel.TopologyModel}. + */ + private Topology reference; + + /** + * Domain name of the Petals ESB bus. A deployment property can be used. It must be set if no default value is set + * in its reference topology. + */ + private String domainName; + + /** + * The instances of registry to use in Topology. + */ + private RegistryInstance registryInstance; + + /** + * The instances of Petals ESB containers forming the Petals ESB bus. + */ + private List containerInstances; + + public Topology getReference() { + return reference; + } + + public void setReference(final Topology reference) { + this.reference = reference; + } + + public String getDomainName() { + return domainName; + } + + public void setDomainName(final String domainName) { + this.domainName = domainName; + } + + public RegistryInstance getRegistryInstance() { + return registryInstance; + } + + public void setRegistryInstance(final RegistryInstance registryInstance) { + this.registryInstance = registryInstance; + } + + public List getContainerInstances() { + return containerInstances; + } + + public void setContainerInstances(final List containerInstances) { + this.containerInstances = containerInstances; + } +} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/componentrepository/Component.java b/src/main/java/org/ow2/petals/deploymentmodel/componentrepository/Component.java new file mode 100644 index 0000000..31981e2 --- /dev/null +++ b/src/main/java/org/ow2/petals/deploymentmodel/componentrepository/Component.java @@ -0,0 +1,67 @@ +package org.ow2.petals.deploymentmodel.componentrepository; + +import java.net.URI; +import java.util.List; +import java.util.Map; + +/** + * Class describing a component artifact. + * + * @author alagane + */ +public class Component { + /** + * The identifier of this component in the model. Must be the same than the one defined in the JBI descriptor of the + * component. + */ + private String id; + + /** + * The URL of the associated archive. + */ + private URI url; + + /** + * The map of parameters required by the component. The key of the map is the name of the parameter, and the value + * of the map is the default value of the parameter. If there is no default value, the value must be null. + */ + private Map parameters; + + /** + * A set of shared library references that the component requires. They reference shared libraries defined in the + * model by their id. Optional. + */ + private List sharedLibraryReferences; + + public String getId() { + return id; + } + + public void setId(final String id) { + this.id = id; + } + + public URI getUrl() { + return url; + } + + public void setUrl(final URI url) { + this.url = url; + } + + public Map getParameters() { + return parameters; + } + + public void setParameters(final Map parameters) { + this.parameters = parameters; + } + + public List getSharedLibraryReferences() { + return sharedLibraryReferences; + } + + public void setSharedLibraryReferences(final List sharedLibraryReferences) { + this.sharedLibraryReferences = sharedLibraryReferences; + } +} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/componentrepository/ComponentRepository.java b/src/main/java/org/ow2/petals/deploymentmodel/componentrepository/ComponentRepository.java new file mode 100644 index 0000000..eefa775 --- /dev/null +++ b/src/main/java/org/ow2/petals/deploymentmodel/componentrepository/ComponentRepository.java @@ -0,0 +1,39 @@ +package org.ow2.petals.deploymentmodel.componentrepository; + +import java.util.List; + +/** + * This model defines a set of binding components, service engines and shared libraries that can be used to perform the + * deployment of a Petals ESB bus. Such models are included in Petals ESB distribution packs, and you can write your + * own. + * + * @author alagane + */ +public class ComponentRepository { + /** + * The list of components objects of this repository. Their id must be unique for all component repository models. + */ + private List components; + + /** + * The list of shared libraries of this repository. Optional. Their couple of id and version must be unique in the + * model. + */ + private List sharedLibraries; + + public List getComponents() { + return components; + } + + public void setComponents(final List components) { + this.components = components; + } + + public List getSharedLibraries() { + return sharedLibraries; + } + + public void setSharedLibraries(final List sharedLibraries) { + this.sharedLibraries = sharedLibraries; + } +} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/componentrepository/SharedLibrary.java b/src/main/java/org/ow2/petals/deploymentmodel/componentrepository/SharedLibrary.java new file mode 100644 index 0000000..c508d18 --- /dev/null +++ b/src/main/java/org/ow2/petals/deploymentmodel/componentrepository/SharedLibrary.java @@ -0,0 +1,51 @@ +package org.ow2.petals.deploymentmodel.componentrepository; + +import java.net.URI; + +/** + * Class describing a shared library of this repository. + * + * @author alagane + */ +public class SharedLibrary { + /** + * The identifier of this shared library in the model. Must be the same than the one defined in the JBI descriptor + * of the shared library. + */ + private String id; + + /** + * The version of this shared library in the model. Must be the same than the one defined in the JBI descriptor of + * the shared library. + */ + private String version; + + /** + * The URL of the associated archive. + */ + private URI url; + + public String getId() { + return id; + } + + public void setId(final String id) { + this.id = id; + } + + public String getVersion() { + return version; + } + + public void setVersion(final String version) { + this.version = version; + } + + public URI getUrl() { + return url; + } + + public void setUrl(final URI url) { + this.url = url; + } +} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/serviceunitmodel/ServiceUnit.java b/src/main/java/org/ow2/petals/deploymentmodel/serviceunitmodel/ServiceUnit.java new file mode 100644 index 0000000..99c1d1a --- /dev/null +++ b/src/main/java/org/ow2/petals/deploymentmodel/serviceunitmodel/ServiceUnit.java @@ -0,0 +1,67 @@ +package org.ow2.petals.deploymentmodel.serviceunitmodel; + +import java.net.URI; +import java.util.Map; + +import org.ow2.petals.deploymentmodel.busmodel.ComponentInstance; + +/** + * Class describing a service unit to deploy. + * + * @author alagane + */ +public class ServiceUnit { + /** + * The unique identifier of this service unit in the model. Can be different from the service unit name. + */ + private String id; + + /** + * The URL of the associated archive that can be a service assembly or a deployable service unit. + */ + private URI url; + + /** + * The map of placeholder required by the service unit. The key of the map is the key of the placeholder, and the + * value of the map is the default value of the placeholder. If there is no default value, the value must be null. + */ + private Map placeholders; + + /** + * The identifier of the component instance on which this service unit must be deployed. Optional for deployable + * service unit and service unit embedded in a service assembly, required for other service units. + */ + private ComponentInstance componentInstanceId; + + public String getId() { + return id; + } + + public void setId(final String id) { + this.id = id; + } + + public URI getUrl() { + return url; + } + + public void setUrl(final URI url) { + this.url = url; + } + + public ComponentInstance getComponentInstanceId() { + return componentInstanceId; + } + + public void setComponentInstanceId(final ComponentInstance componentInstanceId) { + this.componentInstanceId = componentInstanceId; + } + + public Map getPlaceholders() { + return placeholders; + } + + public void setPlaceholders(final Map placeholders) { + this.placeholders = placeholders; + } +} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/serviceunitmodel/ServiceUnitModel.java b/src/main/java/org/ow2/petals/deploymentmodel/serviceunitmodel/ServiceUnitModel.java new file mode 100644 index 0000000..3a3238c --- /dev/null +++ b/src/main/java/org/ow2/petals/deploymentmodel/serviceunitmodel/ServiceUnitModel.java @@ -0,0 +1,25 @@ +package org.ow2.petals.deploymentmodel.serviceunitmodel; + +import java.util.List; + +/** + * This model defines a set of service units to deploy on your Petals ESB bus. This model will be mainly written by + * development teams because they have the knowledge of service units to deploy. + * + * @author alagane + */ +public class ServiceUnitModel { + /** + * The list of service units to deploy. Their id must be unique in the model. There must be at least one service + * unit in the model. + */ + private List serviceUnits; + + public List getServiceUnits() { + return serviceUnits; + } + + public void setServiceUnits(final List serviceUnits) { + this.serviceUnits = serviceUnits; + } +} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/Container.java b/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/Container.java new file mode 100644 index 0000000..2f4da29 --- /dev/null +++ b/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/Container.java @@ -0,0 +1,61 @@ +package org.ow2.petals.deploymentmodel.topologymodel; + +/** + * Class for Petals ESB containers members of a topology. + */ +public class Container { + /** + * Identifier of the Petals ESB container as used as name in the file topology.xml. + */ + private String id; + + /** + * Default JMX port value. A deployment property can be used. Optional, if not set, the internal default value 7700 + * will be used. + */ + private int defaultJmxPort; + + /** + * Default JMX username value. A deployment property can be used. Optional, if not set, the internal default value + * 'petals' will be used. + */ + private String defaultJmxUser; + + /** + * Default JMX password value. A deployment property can be used. Optional, if not set, the internal default value + * 'petals' will be used. + */ + private String defaultJmxPassword; + + public String getId() { + return id; + } + + public void setId(final String id) { + this.id = id; + } + + public int getDefaultJmxPort() { + return defaultJmxPort; + } + + public void setDefaultJmxPort(final int defaultJmxPort) { + this.defaultJmxPort = defaultJmxPort; + } + + public String getDefaultJmxUser() { + return defaultJmxUser; + } + + public void setDefaultJmxUser(final String defaultJmxUser) { + this.defaultJmxUser = defaultJmxUser; + } + + public String getDefaultJmxPassword() { + return defaultJmxPassword; + } + + public void setDefaultJmxPassword(final String defaultJmxPassword) { + this.defaultJmxPassword = defaultJmxPassword; + } +} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/HazelcastRegistry.java b/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/HazelcastRegistry.java new file mode 100644 index 0000000..358aa66 --- /dev/null +++ b/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/HazelcastRegistry.java @@ -0,0 +1,51 @@ +package org.ow2.petals.deploymentmodel.topologymodel; + +import java.util.List; + +/** + * Default implementation for a distributed topology. + * + * @author alagane + */ +public class HazelcastRegistry extends Registry { + /** + * Default group name value. A deployment property can be used. Optional, if not set, the internal default value + * 'default-sample' will be used. + */ + private String defaultGroupName; + + /** + * Default password value. A deployment property can be used. Optional, if not set, the internal default value + * 's3cr3t' will be used. + */ + private String defaultGroupPassword; + + /** + * The members of the Hazelcast registry. + */ + private List members; + + public String getDefaultGroupName() { + return defaultGroupName; + } + + public void setDefaultGroupName(final String defaultGroupName) { + this.defaultGroupName = defaultGroupName; + } + + public String getDefaultGroupPassword() { + return defaultGroupPassword; + } + + public void setDefaultGroupPassword(final String defaultGroupPassword) { + this.defaultGroupPassword = defaultGroupPassword; + } + + public List getMembers() { + return members; + } + + public void setMembers(final List members) { + this.members = members; + } +} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/HazelcastRegistryMember.java b/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/HazelcastRegistryMember.java new file mode 100644 index 0000000..d9b671b --- /dev/null +++ b/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/HazelcastRegistryMember.java @@ -0,0 +1,35 @@ +package org.ow2.petals.deploymentmodel.topologymodel; + +/** + * Class describing members of the Petals ESB Hazelcast Registry. + * + * @author alagane + */ +public class HazelcastRegistryMember { + /** + * Identifier used as name in the file cluster.xml. + */ + private String id; + + /** + * Default communication port value. A deployment property can be used. Optional, if not set, the internal default + * value '7900' will be used. + */ + private String defaultPort; + + public String getId() { + return id; + } + + public void setId(final String id) { + this.id = id; + } + + public String getDefaultPort() { + return defaultPort; + } + + public void setDefaultPort(final String defaultPort) { + this.defaultPort = defaultPort; + } +} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/Registry.java b/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/Registry.java new file mode 100644 index 0000000..34fc2aa --- /dev/null +++ b/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/Registry.java @@ -0,0 +1,21 @@ +package org.ow2.petals.deploymentmodel.topologymodel; + +/** + * Superclass for registry types. + * + * @author alagane + */ +public abstract class Registry { + /** + * Used to identify the registry across the model. It must be unique in the model. + */ + private String id; + + public String getId() { + return id; + } + + public void setId(final String id) { + this.id = id; + } +} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/StandaloneRegistry.java b/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/StandaloneRegistry.java new file mode 100644 index 0000000..f508e74 --- /dev/null +++ b/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/StandaloneRegistry.java @@ -0,0 +1,9 @@ +package org.ow2.petals.deploymentmodel.topologymodel; + +/** + * Default implementation for a standalone topology. Cannot be used for a distributed topology. + * + * @author alagane + */ +public class StandaloneRegistry extends Registry { +} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/Topology.java b/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/Topology.java new file mode 100644 index 0000000..3db3d4e --- /dev/null +++ b/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/Topology.java @@ -0,0 +1,60 @@ +package org.ow2.petals.deploymentmodel.topologymodel; + +import java.util.List; + +/** + * Class describing a topology of a Petals ESB bus. + * + * @author alagane + */ +public class Topology { + private String id; + + /** + * Default domain name of the topology. Optional. + */ + private String defaultDomainName; + + /** + * Petals ESB containers of the topology. Their id must be unique in the topology. There must be at least one + * container in the topology. + */ + private List containers; + + /** + * The registry used in the topology. Optional. + */ + private Registry registry; + + public String getId() { + return id; + } + + public void setId(final String id) { + this.id = id; + } + + public String getDefaultDomainName() { + return defaultDomainName; + } + + public void setDefaultDomainName(final String defaultDomainName) { + this.defaultDomainName = defaultDomainName; + } + + public List getContainers() { + return containers; + } + + public void setContainers(final List containers) { + this.containers = containers; + } + + public Registry getRegistry() { + return registry; + } + + public void setRegistry(final Registry registry) { + this.registry = registry; + } +} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/TopologyModel.java b/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/TopologyModel.java new file mode 100644 index 0000000..d9707ba --- /dev/null +++ b/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/TopologyModel.java @@ -0,0 +1,25 @@ +package org.ow2.petals.deploymentmodel.topologymodel; + +import java.util.List; + +/** + * This model defines a set of topologies, used by Petals ESB buses. This model will be mainly written by the Petals ESB + * bus architect. + * + * @author alagane + */ +public class TopologyModel { + /** + * The list of topologies in the model. Their id must be unique in the model. There must be at least one topology in + * the model. + */ + private List topologies; + + public List getTopologies() { + return topologies; + } + + public void setTopologies(final List topologies) { + this.topologies = topologies; + } +} From 86f002e207b7f87125429b6fdf747eaebb044a54 Mon Sep 17 00:00:00 2001 From: Alexandre Lagane Date: Thu, 15 Nov 2018 09:54:47 +0100 Subject: [PATCH 02/21] Poc deployer with some tests --- .gitignore | 1 + COPYRIGHT | 17 + LICENSE | 657 +++++++++++++----- pom.xml | 132 +++- .../runtimemodel/RuntimeComponent.java | 62 ++ .../runtimemodel/RuntimeContainer.java | 117 ++++ .../deployer/runtimemodel/RuntimeModel.java | 50 ++ .../runtimemodel/RuntimeServiceUnit.java | 63 ++ .../petals/deployer/utils/ModelConverter.java | 99 +++ .../utils/ModelValidationException.java | 27 + .../petals/deployer/utils/ModelValidator.java | 51 ++ .../utils/RuntimeModelComparator.java | 233 +++++++ .../deployer/utils/RuntimeModelDeployer.java | 171 +++++ .../utils/RuntimeModelDeployerException.java | 28 + .../deployer/utils/RuntimeModelExporter.java | 95 +++ .../petals/deploymentmodel/busmodel/Bus.java | 49 -- .../deploymentmodel/busmodel/BusModel.java | 58 -- .../busmodel/ComponentInstance.java | 66 -- .../busmodel/ContainerInstance.java | 79 --- .../busmodel/HazelcastRegistryInstance.java | 67 -- .../HazelcastRegistryMemberInstance.java | 51 -- .../deploymentmodel/busmodel/Machine.java | 21 - .../busmodel/ProvisionedMachine.java | 21 - .../busmodel/RegistryInstance.java | 9 - .../busmodel/ServiceUnitInstance.java | 38 - .../busmodel/StandaloneRegistryInstance.java | 20 - .../busmodel/TopologyInstance.java | 65 -- .../componentrepository/Component.java | 67 -- .../ComponentRepository.java | 39 -- .../componentrepository/SharedLibrary.java | 51 -- .../serviceunitmodel/ServiceUnit.java | 67 -- .../serviceunitmodel/ServiceUnitModel.java | 25 - .../topologymodel/Container.java | 61 -- .../topologymodel/HazelcastRegistry.java | 51 -- .../HazelcastRegistryMember.java | 35 - .../topologymodel/Registry.java | 21 - .../topologymodel/StandaloneRegistry.java | 9 - .../topologymodel/Topology.java | 60 -- .../topologymodel/TopologyModel.java | 25 - src/main/resources/binding.xjb | 26 + src/main/resources/bus-model.xsd | 76 ++ src/main/resources/component-repository.xsd | 35 + src/main/resources/model.xsd | 42 ++ src/main/resources/service-unit-model.xsd | 34 + src/main/resources/topology-model.xsd | 42 ++ .../petals/deployer/utils/ParseModelTest.java | 188 +++++ .../utils/RuntimeModelComparatorTest.java | 638 +++++++++++++++++ .../utils/RuntimeModelDeployerTest.java | 123 ++++ .../ow2/petals/deployer/utils/ZipUtils.java | 71 ++ .../petals-bc-soap-5.0.0/META-INF/jbi.xml | 217 ++++++ .../META-INF/jbi.xml | 40 ++ .../META-INF/jbi.xml | 40 ++ .../META-INF/jbi.xml | 40 ++ 53 files changed, 3240 insertions(+), 1230 deletions(-) create mode 100644 COPYRIGHT create mode 100644 src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java create mode 100644 src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java create mode 100644 src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java create mode 100644 src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java create mode 100644 src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java create mode 100644 src/main/java/org/ow2/petals/deployer/utils/ModelValidationException.java create mode 100644 src/main/java/org/ow2/petals/deployer/utils/ModelValidator.java create mode 100644 src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java create mode 100644 src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java create mode 100644 src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerException.java create mode 100644 src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java delete mode 100644 src/main/java/org/ow2/petals/deploymentmodel/busmodel/Bus.java delete mode 100644 src/main/java/org/ow2/petals/deploymentmodel/busmodel/BusModel.java delete mode 100644 src/main/java/org/ow2/petals/deploymentmodel/busmodel/ComponentInstance.java delete mode 100644 src/main/java/org/ow2/petals/deploymentmodel/busmodel/ContainerInstance.java delete mode 100644 src/main/java/org/ow2/petals/deploymentmodel/busmodel/HazelcastRegistryInstance.java delete mode 100644 src/main/java/org/ow2/petals/deploymentmodel/busmodel/HazelcastRegistryMemberInstance.java delete mode 100644 src/main/java/org/ow2/petals/deploymentmodel/busmodel/Machine.java delete mode 100644 src/main/java/org/ow2/petals/deploymentmodel/busmodel/ProvisionedMachine.java delete mode 100644 src/main/java/org/ow2/petals/deploymentmodel/busmodel/RegistryInstance.java delete mode 100644 src/main/java/org/ow2/petals/deploymentmodel/busmodel/ServiceUnitInstance.java delete mode 100644 src/main/java/org/ow2/petals/deploymentmodel/busmodel/StandaloneRegistryInstance.java delete mode 100644 src/main/java/org/ow2/petals/deploymentmodel/busmodel/TopologyInstance.java delete mode 100644 src/main/java/org/ow2/petals/deploymentmodel/componentrepository/Component.java delete mode 100644 src/main/java/org/ow2/petals/deploymentmodel/componentrepository/ComponentRepository.java delete mode 100644 src/main/java/org/ow2/petals/deploymentmodel/componentrepository/SharedLibrary.java delete mode 100644 src/main/java/org/ow2/petals/deploymentmodel/serviceunitmodel/ServiceUnit.java delete mode 100644 src/main/java/org/ow2/petals/deploymentmodel/serviceunitmodel/ServiceUnitModel.java delete mode 100644 src/main/java/org/ow2/petals/deploymentmodel/topologymodel/Container.java delete mode 100644 src/main/java/org/ow2/petals/deploymentmodel/topologymodel/HazelcastRegistry.java delete mode 100644 src/main/java/org/ow2/petals/deploymentmodel/topologymodel/HazelcastRegistryMember.java delete mode 100644 src/main/java/org/ow2/petals/deploymentmodel/topologymodel/Registry.java delete mode 100644 src/main/java/org/ow2/petals/deploymentmodel/topologymodel/StandaloneRegistry.java delete mode 100644 src/main/java/org/ow2/petals/deploymentmodel/topologymodel/Topology.java delete mode 100644 src/main/java/org/ow2/petals/deploymentmodel/topologymodel/TopologyModel.java create mode 100644 src/main/resources/binding.xjb create mode 100644 src/main/resources/bus-model.xsd create mode 100644 src/main/resources/component-repository.xsd create mode 100644 src/main/resources/model.xsd create mode 100644 src/main/resources/service-unit-model.xsd create mode 100644 src/main/resources/topology-model.xsd create mode 100644 src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java create mode 100644 src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java create mode 100644 src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java create mode 100644 src/test/java/org/ow2/petals/deployer/utils/ZipUtils.java create mode 100644 src/test/resources/artifacts/petals-bc-soap-5.0.0/META-INF/jbi.xml create mode 100644 src/test/resources/artifacts/sa-SOAP-Hello_PortType-consume/META-INF/jbi.xml create mode 100644 src/test/resources/artifacts/sa-SOAP-Hello_Service1-provide/META-INF/jbi.xml create mode 100644 src/test/resources/artifacts/sa-SOAP-Hello_Service2-provide/META-INF/jbi.xml diff --git a/.gitignore b/.gitignore index b8d1c59..8c7c6b8 100644 --- a/.gitignore +++ b/.gitignore @@ -73,6 +73,7 @@ local.properties ### Maven ### target/ +report/ pom.xml.tag pom.xml.releaseBackup pom.xml.versionsBackup diff --git a/COPYRIGHT b/COPYRIGHT new file mode 100644 index 0000000..d7eb3f1 --- /dev/null +++ b/COPYRIGHT @@ -0,0 +1,17 @@ + + Copyright (c) 2018-2019 Linagora + + This program/library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 2.1 of the License, or (at your + option) any later version. + + This program/library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program/library; If not, see http://www.gnu.org/licenses/ + for the GNU Lesser General Public License version 2.1. + \ No newline at end of file diff --git a/LICENSE b/LICENSE index 0a04128..60d7ac2 100644 --- a/LICENSE +++ b/LICENSE @@ -1,165 +1,502 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! \ No newline at end of file diff --git a/pom.xml b/pom.xml index 5f3ca7a..9d9a99f 100644 --- a/pom.xml +++ b/pom.xml @@ -1,20 +1,122 @@ - - 4.0.0 + + + + 4.0.0 - org.ow2.petals - petals-esb-deployer - 0.0.1-SNAPSHOT - jar + + org.ow2.petals + petals-client-tools-parent + 1.1.1-SNAPSHOT + - petals-esb-deployer - https://doc.petalslink.com/display/petalscomponents/Petals+ESB+Deployer+1.0.0 + org.ow2.petals + petals-esb-deployer + 0.0.1-SNAPSHOT + jar - - UTF-8 - + petals-esb-deployer + https://doc.petalslink.com/display/petalscomponents/Petals+ESB+Deployer+1.0.0 - - + + + org.ow2.petals + petals-admin-api + 2.1.1-SNAPSHOT + + + + junit + junit + test + + + + org.ow2.petals + petals-admin-mock + 2.1.1-SNAPSHOT + test + + + + org.ow2.petals + petals-jbi-descriptor + 2.4.0 + + + + + + + + + + commons-io + commons-io + 2.6 + + + + + + org.jvnet.jaxb2_commons + jaxb2-basics-runtime + 0.11.1 + + + + + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + + ${basedir}/src/main/resources/ + + topology-model.xsd + component-repository.xsd + service-unit-model.xsd + bus-model.xsd + model.xsd + + + binding.xjb + + + + + diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java new file mode 100644 index 0000000..c8fc2a5 --- /dev/null +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java @@ -0,0 +1,62 @@ +/** + * Copyright (c) 2018-2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.runtimemodel; + +import java.net.URL; + +public class RuntimeComponent { + private final String id; + + private URL url; + + public RuntimeComponent(final String id) { + this.id = id; + } + + public RuntimeComponent(final String id, final URL url) { + this(id); + this.url = url; + } + + public String getId() { + return id; + } + + public URL getUrl() { + return url; + } + + public void setUrl(final URL url) { + this.url = url; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof RuntimeComponent)) { + return false; + } + + return id.equals(((RuntimeComponent) obj).id); + } + + @Override + public int hashCode() { + return id.hashCode(); + } +} diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java new file mode 100644 index 0000000..4d10778 --- /dev/null +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java @@ -0,0 +1,117 @@ +/** + * Copyright (c) 2018-2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.runtimemodel; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.ow2.petals.deployer.runtimemodel.RuntimeModel.RuntimeModelException; + +public class RuntimeContainer { + + private final String id; + + private int port; + + private String user; + + private String password; + + private String hostname; + + private Map serviceUnits = new HashMap(); + + private Map components = new HashMap(); + + public RuntimeContainer(final String id, final int port, final String user, final String password, + final String hostname) { + this.id = id; + this.port = port; + this.user = user; + this.password = password; + this.hostname = hostname; + } + + public String getId() { + return id; + } + + public int getPort() { + return port; + } + + public String getUser() { + return user; + } + + public String getPassword() { + return password; + } + + public String getHostname() { + return hostname; + } + + public void setHostname(final String hostname) { + this.hostname = hostname; + } + + public RuntimeServiceUnit getServiceUnit(final String id) { + return serviceUnits.get(id); + } + + public void addServiceUnit(final RuntimeServiceUnit serviceUnit) throws RuntimeModelException { + if (serviceUnits.put(serviceUnit.getId(), serviceUnit) != null) { + throw new RuntimeModelException("Service unit " + serviceUnit.getId() + " is already in the list"); + } + } + + public Collection getServiceUnits() { + return serviceUnits.values(); + } + + public void addComponent(final RuntimeComponent component) throws RuntimeModelException { + if (components.put(component.getId(), component) != null) { + throw new RuntimeModelException("Component " + component.getId() + " is already in the list"); + } + } + + public RuntimeComponent getComponent(final String id) { + return components.get(id); + } + + public Collection getComponents() { + return components.values(); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof RuntimeContainer)) { + return false; + } + + return id.equals(((RuntimeContainer) obj).id); + } + + @Override + public int hashCode() { + return id.hashCode(); + } +} diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java new file mode 100644 index 0000000..da9c02e --- /dev/null +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2018-2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.runtimemodel; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +public class RuntimeModel { + + private Map containers = new HashMap(); + + public void addContainer(final RuntimeContainer container) throws RuntimeModelException { + if (containers.put(container.getId(), container) != null) { + throw new RuntimeModelException("Container " + container.getId() + " is already in the list"); + } + } + + public RuntimeContainer getContainer(final String id) { + return containers.get(id); + } + + public Collection getContainers() { + return containers.values(); + } + + public static class RuntimeModelException extends Exception { + private static final long serialVersionUID = -4775138643228668670L; + + public RuntimeModelException(String message) { + super(message); + } + } +} diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java new file mode 100644 index 0000000..1723ea2 --- /dev/null +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java @@ -0,0 +1,63 @@ +/** + * Copyright (c) 2018-2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.runtimemodel; + +import java.net.URL; + +public class RuntimeServiceUnit { + + private final String id; + + private URL url; + + public RuntimeServiceUnit(final String id) { + this.id = id; + } + + public RuntimeServiceUnit(final String id, final URL url) { + this(id); + this.url = url; + } + + public String getId() { + return id; + } + + public URL getUrl() { + return url; + } + + public void setUrl(final URL url) { + this.url = url; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof RuntimeServiceUnit)) { + return false; + } + + return id.equals(((RuntimeServiceUnit) obj).id); + } + + @Override + public int hashCode() { + return id.hashCode(); + } +} diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java b/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java new file mode 100644 index 0000000..ef8ea47 --- /dev/null +++ b/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java @@ -0,0 +1,99 @@ +/** + * Copyright (c) 2018-2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.utils; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +import org.ow2.petals.deployer.model.bus.xml._1.BusModel; +import org.ow2.petals.deployer.model.bus.xml._1.ComponentInstance; +import org.ow2.petals.deployer.model.bus.xml._1.ContainerInstance; +import org.ow2.petals.deployer.model.bus.xml._1.ProvisionedMachine; +import org.ow2.petals.deployer.model.bus.xml._1.ServiceUnitInstance; +import org.ow2.petals.deployer.model.component_repository.xml._1.Component; +import org.ow2.petals.deployer.model.component_repository.xml._1.ComponentRepository; +import org.ow2.petals.deployer.model.service_unit.xml._1.ServiceUnit; +import org.ow2.petals.deployer.model.service_unit.xml._1.ServiceUnitModel; +import org.ow2.petals.deployer.model.topology.xml._1.Container; +import org.ow2.petals.deployer.model.topology.xml._1.TopologyModel; +import org.ow2.petals.deployer.model.xml._1.Model; +import org.ow2.petals.deployer.runtimemodel.RuntimeComponent; +import org.ow2.petals.deployer.runtimemodel.RuntimeContainer; +import org.ow2.petals.deployer.runtimemodel.RuntimeModel; +import org.ow2.petals.deployer.runtimemodel.RuntimeModel.RuntimeModelException; +import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit; + +public class ModelConverter { + public RuntimeModel convertModelToRuntimeModel(Model model) throws MalformedURLException, RuntimeModelException { + RuntimeModel runtimeModel = new RuntimeModel(); + + TopologyModel topoModel = model.getTopologyModel(); + + Container cont = topoModel.getTopology().get(0).getContainer().get(0); + + BusModel busModel = model.getBusModel(); + + ContainerInstance contInst = busModel.getBus().get(0).getContainerInstance().get(0); + + String contId = cont.getId(); + String hostname = ((ProvisionedMachine) busModel.getMachine().get(0)).getHostname(); + Integer contPort = contInst.getJmxPort(); + if (contPort == null) { + contPort = cont.getDefaultJmxPort(); + } + String contUser = contInst.getJmxUser(); + if (contUser == null) { + contUser = cont.getDefaultJmxUser(); + } + String contPassword = contInst.getJmxPassword(); + if (contPassword == null) { + contPassword = cont.getDefaultJmxPassword(); + } + + RuntimeContainer runtimeCont = new RuntimeContainer(contId, contPort, contUser, contPassword, hostname); + runtimeModel.addContainer(runtimeCont); + + ComponentRepository compRepo = model.getComponentRepository(); + Map compById = new HashMap(); + for (Component comp : compRepo.getComponent()) { + compById.put(comp.getId(), comp); + } + for (ComponentInstance compInst : contInst.getComponentInstance()) { + String compId = compInst.getRef(); + Component compRef = compById.get(compId); + runtimeCont.addComponent(new RuntimeComponent(compId, new URL(compRef.getUrl()))); + } + + ServiceUnitModel suModel = model.getServiceUnitModel(); + + Map suById = new HashMap(); + for (ServiceUnit su : suModel.getServiceUnit()) { + suById.put(su.getId(), su); + } + for (ServiceUnitInstance suInst : contInst.getServiceUnitInstance()) { + String suId = suInst.getRef(); + ServiceUnit suRef = suById.get(suId); + runtimeCont.addServiceUnit(new RuntimeServiceUnit(suId, new URL(suRef.getUrl()))); + } + + return runtimeModel; + } +} diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelValidationException.java b/src/main/java/org/ow2/petals/deployer/utils/ModelValidationException.java new file mode 100644 index 0000000..f9b4ccf --- /dev/null +++ b/src/main/java/org/ow2/petals/deployer/utils/ModelValidationException.java @@ -0,0 +1,27 @@ +/** + * Copyright (c) 2018-2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.utils; + +public class ModelValidationException extends Exception { + private static final long serialVersionUID = 5871650877543503924L; + + public ModelValidationException(String message) { + super(message); + } +} diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelValidator.java b/src/main/java/org/ow2/petals/deployer/utils/ModelValidator.java new file mode 100644 index 0000000..1fde404 --- /dev/null +++ b/src/main/java/org/ow2/petals/deployer/utils/ModelValidator.java @@ -0,0 +1,51 @@ +/** + * Copyright (c) 2018-2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.utils; + +public class ModelValidator { + + // public void validateServiceUnitModel(ServiceUnitModel model) throws ModelValidationException { + // + // List sus = model.getServiceUnits(); + // if (sus.size() < 1) { + // throw new ModelValidationException("ServiceUnitModel must have 1 ServiceUnit minimum"); + // } + // + // HashSet suIds = new HashSet(); + // Map placeholders = new HashMap(); + // for (ServiceUnit su : sus) { + // for (Map.Entry suPh : su.getPlaceholders().entrySet()) { + // if (placeholders.containsKey(suPh.getKey())) { + // String phDefaultValue = placeholders.get(suPh.getKey()); + // if (suPh.getValue() == null && phDefaultValue != null + // || suPh.getValue() != null && !suPh.getValue().equals(phDefaultValue)) { + // throw new ModelValidationException("Placeholder with key " + suPh.getKey() + // + " is used on different ServiceUnit but its defaultValue differs."); + // } + // } else { + // placeholders.put(suPh.getKey(), suPh.getValue()); + // } + // + // } + // if (!suIds.add(su.getId())) { + // throw new ModelValidationException("ServiceUnit id " + su.getId() + " is not unique"); + // } + // } + // } +} diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java new file mode 100644 index 0000000..ddee0eb --- /dev/null +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java @@ -0,0 +1,233 @@ +/** + * Copyright (c) 2018-2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.utils; + +import java.util.Collection; + +import org.ow2.petals.deployer.runtimemodel.RuntimeComponent; +import org.ow2.petals.deployer.runtimemodel.RuntimeContainer; +import org.ow2.petals.deployer.runtimemodel.RuntimeModel; +import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit; + +public class RuntimeModelComparator { + public boolean compareRuntimeModels(final RuntimeModel m1, final RuntimeModel m2) { + return compareRuntimeContainerMaps(m1, m2); + } + + private boolean compareRuntimeComponentMaps(RuntimeContainer cont1, RuntimeContainer cont2) { + Collection compList1 = cont1.getComponents(); + Collection compList2 = cont2.getComponents(); + + for (RuntimeComponent comp1 : compList1) { + RuntimeComponent comp2 = cont1.getComponent(comp1.getId()); + if (comp2 == null || !compareRuntimeComponents(comp1, comp2)) { + return false; + } + } + + for (RuntimeComponent comp2 : compList2) { + if (cont2.getComponent(comp2.getId()) == null) { + return false; + } + } + + return true; + } + + private boolean compareRuntimeContainerMaps(RuntimeModel m1, RuntimeModel m2) { + Collection contList1 = m1.getContainers(); + Collection contList2 = m2.getContainers(); + + for (RuntimeContainer cont1 : contList1) { + RuntimeContainer cont2 = m1.getContainer(cont1.getId()); + if (cont2 == null || !compareRuntimeContainers(cont1, cont2)) { + return false; + } + } + + for (RuntimeContainer cont2 : contList2) { + if (m2.getContainer(cont2.getId()) == null) { + return false; + } + } + + return true; + } + + private boolean compareRuntimeContainers(RuntimeContainer cont1, RuntimeContainer cont2) { + return cont1.getId().equals(cont2.getId()) && cont1.getPort() == cont2.getPort() + && cont1.getUser().equals(cont2.getUser()) && cont1.getPassword().equals(cont2.getPassword()) + && cont1.getHostname().equals(cont2.getHostname()) && compareRuntimeServiceUnitMaps(cont1, cont2) + && compareRuntimeComponentMaps(cont1, cont2); + } + + private boolean compareRuntimeServiceUnitMaps(RuntimeContainer cont1, RuntimeContainer cont2) { + Collection suList1 = cont1.getServiceUnits(); + Collection suList2 = cont2.getServiceUnits(); + + for (RuntimeServiceUnit su1 : suList1) { + RuntimeServiceUnit su2 = cont1.getServiceUnit(su1.getId()); + if (su2 == null || !compareRuntimeServiceUnits(su1, su2)) { + return false; + } + } + + for (RuntimeServiceUnit su2 : suList2) { + if (cont2.getServiceUnit(su2.getId()) == null) { + return false; + } + } + + return true; + } + + private boolean compareRuntimeServiceUnits(RuntimeServiceUnit su1, RuntimeServiceUnit su2) { + return su1.getId().equals(su2.getId()); + } + + private boolean compareRuntimeComponents(RuntimeComponent comp1, RuntimeComponent comp2) { + return comp1.getId().equals(comp2.getId()); + } + +// public boolean compareModels(final Model m1, final Model m2) { +// Bus bus1 = m1.getBusModel().getBuses().get(0); +// Bus bus2 = m2.getBusModel().getBuses().get(0); +// ContainerInstance contInst1 = bus1.getTopologyInstance().getContainerInstances().get(0); +// ContainerInstance contInst2 = bus2.getTopologyInstance().getContainerInstances().get(0); +// +// if (!compareContainerInstances(contInst1, contInst2)) { +// return false; +// } +// +// return true; +// } +// +// public boolean compareServiceUnitInstanceLists(final List suInstances1, +// final List suInstances2) { +// +// if (suInstances1.size() != suInstances2.size()) { +// return false; +// } +// +// // Check unicity and build map of suInstances1 +// Map suInstById1 = new HashMap(); +// for (ServiceUnitInstance suInst : suInstances1) { +// String suId = suInst.getReference(); +// if (suInstById1.containsKey(suId)) { +// return false; +// } +// suInstById1.put(suId, suInst); +// } +// +// // Check unicity of suInstances2 and compare its elements with suInstances1 +// Set suInstIds = new HashSet(); +// for (ServiceUnitInstance suInst : suInstances2) { +// String suId = suInst.getReference(); +// if (!suInstIds.add(suId) || !compareServiceUnitInstances(suInst, suInstById1.get(suId))) { +// return false; +// } +// } +// +// return true; +// } +// +// public boolean compareComponentInstanceLists(final List compInstances1, +// final List compInstances2) { +// +// if (compInstances1.size() != compInstances2.size()) { +// return false; +// } +// +// // Check unicity and build map of compInstances1 +// Map compInstById1 = new HashMap(); +// for (ComponentInstance compInst : compInstances1) { +// String compInstId = compInst.getReference(); +// if (compInstById1.containsKey(compInstId)) { +// return false; +// } +// compInstById1.put(compInstId, compInst); +// } +// +// // Check unicity of compInstances2 and compare its elements with compInstances1 +// Set compInstIds = new HashSet(); +// for (ComponentInstance compInst : compInstances2) { +// String compInstId = compInst.getReference(); +// if (!compInstIds.add(compInstId) || !compareComponentsInstances(compInst, compInstById1.get(compInstId))) { +// return false; +// } +// } +// +// return true; +// } +// +// /** +// * m1 and m2 must be both instances of {@link ProvisionedMachine} +// * +// * @param m1 +// * @param m2 +// * @return false if m1 and m2 are different +// */ +// public boolean compareMachines(Machine m1, Machine m2) { +// return m1 instanceof ProvisionedMachine && m2 instanceof ProvisionedMachine +// && ((ProvisionedMachine) m1).getHostname().equals(((ProvisionedMachine) m2).getHostname()); +// } +// +// /** +// * We only compare container instances, their getters will fetch data from their reference {@link Container}. +// * +// * @param ci1 +// * @param ci2 +// * @return false if ci1 and ci2 are different +// */ +// public boolean compareContainerInstances(final ContainerInstance ci1, final ContainerInstance ci2) { +// return ci1.getReference().equals(ci2.getReference()) && ci1.getJmxUser().equals(ci2.getJmxUser()) +// && ci1.getJmxPort().equals(ci2.getJmxPort()) && ci1.getJmxPassword().equals(ci2.getJmxPassword()) +// && compareServiceUnitInstanceLists(ci1.getServiceUnitInstances(), ci2.getServiceUnitInstances()) +// && compareComponentInstanceLists(ci1.getComponentInstances(), ci2.getComponentInstances()); +// } +// +// public boolean compareServiceUnitInstances(final ServiceUnitInstance sui1, final ServiceUnitInstance sui2) { +// return sui1.getContainerInstanceReference().equals(sui2.getContainerInstanceReference()) +// && sui1.getReference().equals(sui2.getReference()); +// } +// +// /** +// * @param su1 +// * @param su2 +// * @return false if su1 and su2 are different +// */ +// public boolean compareServiceUnits(final ServiceUnit su1, final ServiceUnit su2) { +// return su1.getId().equals(su2.getId()) && su1.getTargetComponent().equals(su2.getTargetComponent()); +// } +// +// public boolean compareComponentsInstances(final ComponentInstance ci1, final ComponentInstance ci2) { +// return ci1.getReference().equals(ci2.getReference()) && ci1.getReference().equals(ci2.getReference()); +// } +// +// /** +// * The urls are not compared, because we cannot set them when exporting model from a running Petals. +// * +// * @param c1 +// * @param c2 +// * @return false if c1 and c2 are different +// */ +// public boolean compareComponents(final Component c1, final Component c2) { +// return c1.getId().equals(c2.getId()); +// } +} diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java new file mode 100644 index 0000000..f981819 --- /dev/null +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java @@ -0,0 +1,171 @@ +/** + * Copyright (c) 2018-2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.utils; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.Collection; +import java.util.HashSet; +import java.util.logging.Logger; + +import org.apache.commons.io.FileUtils; +import org.ow2.petals.admin.api.PetalsAdministration; +import org.ow2.petals.admin.api.PetalsAdministrationFactory; +import org.ow2.petals.admin.api.artifact.Component.ComponentType; +import org.ow2.petals.admin.api.artifact.lifecycle.ArtifactLifecycleFactory; +import org.ow2.petals.admin.api.artifact.lifecycle.ComponentLifecycle; +import org.ow2.petals.admin.api.artifact.lifecycle.ServiceAssemblyLifecycle; +import org.ow2.petals.admin.api.exception.ArtifactAdministrationException; +import org.ow2.petals.admin.api.exception.ArtifactDeployedException; +import org.ow2.petals.admin.api.exception.ArtifactNotDeployedException; +import org.ow2.petals.admin.api.exception.ArtifactNotFoundException; +import org.ow2.petals.admin.api.exception.ArtifactStartedException; +import org.ow2.petals.admin.api.exception.ConnectionFailedException; +import org.ow2.petals.admin.api.exception.ContainerAdministrationException; +import org.ow2.petals.admin.api.exception.DuplicatedServiceException; +import org.ow2.petals.admin.api.exception.MissingServiceException; +import org.ow2.petals.deployer.runtimemodel.RuntimeComponent; +import org.ow2.petals.deployer.runtimemodel.RuntimeContainer; +import org.ow2.petals.deployer.runtimemodel.RuntimeModel; +import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit; +import org.ow2.petals.jbi.descriptor.JBIDescriptorException; +import org.ow2.petals.jbi.descriptor.original.JBIDescriptorBuilder; +import org.ow2.petals.jbi.descriptor.original.generated.Jbi; +import org.ow2.petals.jbi.descriptor.original.generated.ServiceAssembly; + +public class RuntimeModelDeployer { + + private static final Logger LOG = Logger.getLogger(RuntimeModelDeployer.class.getName()); + + private PetalsAdministration petalsAdmin; + + private ArtifactLifecycleFactory artifactLifecycleFactory; + + private JBIDescriptorBuilder jdb; + + private HashSet deployedComponents = new HashSet(); + + private HashSet deployedServiceUnits = new HashSet(); + + public RuntimeModelDeployer() throws DuplicatedServiceException, MissingServiceException, JBIDescriptorException { + this(PetalsAdministrationFactory.getInstance().newPetalsAdministrationAPI(), null, + JBIDescriptorBuilder.getInstance()); + + } + + public RuntimeModelDeployer(PetalsAdministration petalsAdmin, ArtifactLifecycleFactory artifactLifecycleFactory, + JBIDescriptorBuilder jdb) { + this.petalsAdmin = petalsAdmin; + this.artifactLifecycleFactory = artifactLifecycleFactory != null ? artifactLifecycleFactory + : petalsAdmin.newArtifactLifecycleFactory(); + this.jdb = jdb; + } + + public void deployRuntimeModel(RuntimeModel model) + throws ConnectionFailedException, ContainerAdministrationException, ArtifactStartedException, + ArtifactNotDeployedException, ArtifactNotFoundException, IOException, JBIDescriptorException, + ArtifactAdministrationException, RuntimeModelDeployerException { + RuntimeContainer container = model.getContainers().iterator().next(); + Collection serviceUnits = container.getServiceUnits(); + + LOG.fine("Deploying model (" + serviceUnits.size() + " service units)"); + + String hostname = container.getHostname(); + int port = container.getPort(); + String user = container.getUser(); + String password = container.getPassword(); + + petalsAdmin.connect(hostname, port, user, password); + + for (RuntimeServiceUnit serviceUnit : serviceUnits) { + deployRuntimeServiceUnit(serviceUnit, model); + } + + LOG.fine("Model deployed"); + } + + private void deployRuntimeServiceUnit(RuntimeServiceUnit serviceUnit, RuntimeModel model) + throws IOException, JBIDescriptorException, ArtifactStartedException, ArtifactNotDeployedException, + ArtifactNotFoundException, ArtifactAdministrationException, RuntimeModelDeployerException { + String suId = serviceUnit.getId(); + File suFile = Files.createTempFile(suId, ".zip").toFile(); + FileUtils.copyURLToFile(serviceUnit.getUrl(), suFile); + Jbi jbi = jdb.buildJavaJBIDescriptorFromArchive(suFile); + ServiceAssembly jbiSa = jbi.getServiceAssembly(); + + if (!deployedServiceUnits.contains(suId)) { + LOG.fine("Deploying service assembly"); + for (org.ow2.petals.jbi.descriptor.original.generated.ServiceUnit jbiSu : jbiSa.getServiceUnit()) { + String compName = jbiSu.getTarget().getComponentName(); + if (!deployedComponents.contains(compName)) { + RuntimeComponent component = model.getContainers().iterator().next().getComponent(compName); + if (component == null) { + throw new RuntimeModelDeployerException("Component " + compName + " (needed by service unit " + + jbiSu.getIdentification().getName() + ") not found"); + } + deployRuntimeComponent(component); + deployedComponents.add(compName); + } + } + ServiceAssemblyLifecycle saLifecycle = artifactLifecycleFactory.createServiceAssemblyLifecycle( + new org.ow2.petals.admin.api.artifact.ServiceAssembly(jbiSa.getIdentification().getName())); + saLifecycle.deploy(suFile.toURI().toURL()); + saLifecycle.start(); + for (org.ow2.petals.jbi.descriptor.original.generated.ServiceUnit jbiSu : jbiSa.getServiceUnit()) { + String suName = jbiSu.getIdentification().getName(); + if (!deployedServiceUnits.contains(suName)) { + deployedServiceUnits.add(suName); + LOG.fine("Service unit " + suName + " deployed and started"); + } else { + throw new RuntimeModelDeployerException("Service unit " + suName + " already deployed"); + } + } + } + } + + private void deployRuntimeComponent(RuntimeComponent component) + throws IOException, JBIDescriptorException, ArtifactDeployedException, ArtifactAdministrationException { + String compId = component.getId(); + File compFile = Files.createTempFile(compId, "zip").toFile(); + FileUtils.copyURLToFile(component.getUrl(), compFile); + Jbi jbi = jdb.buildJavaJBIDescriptorFromArchive(compFile); + + LOG.fine("Deploying component " + component.getId()); + ComponentLifecycle compLifecycle = artifactLifecycleFactory + .createComponentLifecycle(new org.ow2.petals.admin.api.artifact.Component(compId, + convertComponentType(jbi.getComponent().getType()))); + + compLifecycle.deploy(compFile.toURI().toURL()); + compLifecycle.start(); + LOG.fine("Component " + compId + " deployed and started"); + } + + public ComponentType convertComponentType( + final org.ow2.petals.jbi.descriptor.original.generated.ComponentType jbiType) { + switch (jbiType) { + case BINDING_COMPONENT: + return ComponentType.BC; + case SERVICE_ENGINE: + return ComponentType.SE; + default: + return null; + } + } +} diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerException.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerException.java new file mode 100644 index 0000000..25621fc --- /dev/null +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerException.java @@ -0,0 +1,28 @@ +/** + * Copyright (c) 2018-2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.utils; + +public class RuntimeModelDeployerException extends Exception { + + private static final long serialVersionUID = -3352449083809006549L; + + public RuntimeModelDeployerException(String message) { + super(message); + } +} diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java new file mode 100644 index 0000000..833db98 --- /dev/null +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java @@ -0,0 +1,95 @@ +/** + * Copyright (c) 2018-2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.utils; + +import java.util.logging.Logger; + +import org.ow2.petals.admin.api.ArtifactAdministration; +import org.ow2.petals.admin.api.ContainerAdministration; +import org.ow2.petals.admin.api.PetalsAdministration; +import org.ow2.petals.admin.api.PetalsAdministrationFactory; +import org.ow2.petals.admin.api.artifact.Artifact; +import org.ow2.petals.admin.api.exception.ArtifactAdministrationException; +import org.ow2.petals.admin.api.exception.ContainerAdministrationException; +import org.ow2.petals.admin.api.exception.DuplicatedServiceException; +import org.ow2.petals.admin.api.exception.MissingServiceException; +import org.ow2.petals.deployer.runtimemodel.RuntimeComponent; +import org.ow2.petals.deployer.runtimemodel.RuntimeContainer; +import org.ow2.petals.deployer.runtimemodel.RuntimeModel; +import org.ow2.petals.deployer.runtimemodel.RuntimeModel.RuntimeModelException; +import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit; +import org.ow2.petals.jbi.descriptor.JBIDescriptorException; + +public class RuntimeModelExporter { + + private static final Logger LOG = Logger.getLogger(RuntimeModelExporter.class.getName()); + + private PetalsAdministration petalsAdmin; + + private ContainerAdministration containerAdmin; + + private ArtifactAdministration artifactAdmin; + + public RuntimeModelExporter() throws DuplicatedServiceException, MissingServiceException, JBIDescriptorException { + this(PetalsAdministrationFactory.getInstance().newPetalsAdministrationAPI()); + } + + public RuntimeModelExporter(PetalsAdministration petalsAdmin) { + this.petalsAdmin = petalsAdmin; + containerAdmin = petalsAdmin.newContainerAdministration(); + artifactAdmin = petalsAdmin.newArtifactAdministration(); + } + + public RuntimeModel exportRuntimeModel(final String hostname, final int port, final String user, + final String password) + throws RuntimeModelException, ArtifactAdministrationException, ContainerAdministrationException { + petalsAdmin.connect(hostname, port, user, password); + + RuntimeModel model = new RuntimeModel(); + + RuntimeContainer cont = new RuntimeContainer(petalsAdmin.newContainerAdministration().getTopology(null, false) + .getContainers().get(0).getContainerName(), port, user, password, hostname); + model.addContainer(cont); + + for (Artifact artifact : artifactAdmin.listArtifacts()) { + switch (artifact.getType()) { + case "BC": + case "SE": + cont.addComponent( + new RuntimeComponent(((org.ow2.petals.admin.api.artifact.Component) artifact).getName())); + break; + case "SU": + cont.addServiceUnit(new RuntimeServiceUnit( + ((org.ow2.petals.admin.api.artifact.ServiceUnit) artifact).getName())); + // TODO what about targetComponent + break; + case "SA": + // already get service units in "SU" case + break; + case "SL": + throw new UnsupportedOperationException( + "Export model with shared libraries is not implemented yet"); + default: + LOG.warning("Unknown artifact type " + artifact.getType()); + } + } + + return model; + } +} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/Bus.java b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/Bus.java deleted file mode 100644 index 0ba5f4a..0000000 --- a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/Bus.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.ow2.petals.deploymentmodel.busmodel; - -import java.util.List; - -/** - * Class for Petals ESB bus to deploy - * - * @author alagane - */ -public class Bus { - /** - * The service unit instances to deploy - */ - private List serviceUnitInstances; - - /** - * The component instances required by a service unit - */ - private List componentInstances; - - /** - * The topology instance associated to a topology defined in {@link org.ow2.petals.deploymentmodel.topologymodel.TopologyModel}. - */ - private TopologyInstance topologyInstance; - - public List getServiceUnitInstances() { - return serviceUnitInstances; - } - - public void setServiceUnitInstances(final List serviceUnitInstances) { - this.serviceUnitInstances = serviceUnitInstances; - } - - public List getComponentInstances() { - return componentInstances; - } - - public void setComponentInstances(final List componentInstances) { - this.componentInstances = componentInstances; - } - - public TopologyInstance getTopologyInstance() { - return topologyInstance; - } - - public void setTopologyInstance(final TopologyInstance topologyInstance) { - this.topologyInstance = topologyInstance; - } -} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/BusModel.java b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/BusModel.java deleted file mode 100644 index 5fc91ce..0000000 --- a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/BusModel.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.ow2.petals.deploymentmodel.busmodel; - -import java.util.List; -import java.util.Map; - -/** - * This model defines your Petals ESB bus placing Petals ESB components on their containers: - *
    - *
  • service-unit on its Petals ESB container
  • - *
  • Petals ESB container on its machine
  • - *
  • Petals ESB Hazelcast Registry member on its machine.
  • - *
- * This model will be mainly written by the Petals ESB bus architect in agreement with operators. - * - * @author alagane - */ -public class BusModel { - /** - * The list of Petals ESB busses to deploy. - */ - private List buses; - - /** - * The map of placeholder values required by all of the service units. The key of the map is the key of the - * placeholder, and the value of the map is the value of the placeholder. Only keys declared in service unit models - * can be used, and every key declared without a default value must have a value assigned in this map. - */ - private Map placeholderValues; - - /** - * The machines on which parts of a Petals ESB bus will be running. - */ - private List machines; - - public List getBuses() { - return buses; - } - - public void setBuses(final List buses) { - this.buses = buses; - } - - public Map getPlaceholderValues() { - return placeholderValues; - } - - public void setPlaceholderValues(final Map placeholderValues) { - this.placeholderValues = placeholderValues; - } - - public List getMachines() { - return machines; - } - - public void setMachines(final List machines) { - this.machines = machines; - } -} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/ComponentInstance.java b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/ComponentInstance.java deleted file mode 100644 index 448bcae..0000000 --- a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/ComponentInstance.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.ow2.petals.deploymentmodel.busmodel; - -import java.util.List; -import java.util.Map; - -import org.ow2.petals.deploymentmodel.componentrepository.Component; -import org.ow2.petals.deploymentmodel.componentrepository.SharedLibrary; - -/** - * Class describing an instance of a component defined in - * {@link org.ow2.petals.deploymentmodel.componentrepository.ComponentRepository}. - * - * @author alagane - */ -public class ComponentInstance { - private String id; - - /** - * Reference to a component from {@link org.ow2.petals.deploymentmodel.componentrepository.ComponentRepository}. - */ - private Component reference; - - /** - * The map of parameter values required by all of the service units. The key of the map is the name of the - * parameter, and the value of the map is the value of the parameter. Only names declared in reference component can - * be used, and every name declared without a default value must have a value assigned in this map. - */ - private Map placeholderValues; - - /** - * List of shared libraries in addition to these of the referenced component. - */ - private List sharedLibraryReferences; - - public String getId() { - return id; - } - - public void setId(final String id) { - this.id = id; - } - - public Component getReference() { - return reference; - } - - public void setReference(final Component reference) { - this.reference = reference; - } - - public Map getPlaceholderValues() { - return placeholderValues; - } - - public void setPlaceholderValues(final Map placeholderValues) { - this.placeholderValues = placeholderValues; - } - - public List getSharedLibraryReferences() { - return sharedLibraryReferences; - } - - public void setSharedLibraryReferences(final List sharedLibraryReferences) { - this.sharedLibraryReferences = sharedLibraryReferences; - } -} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/ContainerInstance.java b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/ContainerInstance.java deleted file mode 100644 index e5fbfc7..0000000 --- a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/ContainerInstance.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.ow2.petals.deploymentmodel.busmodel; - -import org.ow2.petals.deploymentmodel.topologymodel.Container; - -/** - * Class describing an instance of a container defined in - * {@link org.ow2.petals.deploymentmodel.topologymodel.TopologyModel}. - * - * @author alagane - */ -public class ContainerInstance { - /** - * Reference to a container from {@link org.ow2.petals.deploymentmodel.topologymodel.TopologyModel}. - */ - private Container reference; - - /** - * JMX port of the current Petals ESB container. A deployment property can be used. Each container (from topology - * model) without a default JMX port must have one defined in this model. - */ - private int jmxPort; - - /** - * JMX username of the current Petals ESB container. A deployment property can be used. Each container (from - * topology model) without a default JMX username must have one defined in this model. - */ - private String jmxUser; - - /** - * JMX password of the current Petals ESB container. A deployment property can be used. Each container (from - * topology model) without a default JMX password must have one defined in this model. - */ - private String jmxPassword; - - /** - * The reference of the machine on which the container is running. - */ - private Machine machineReference; - - public Container getReference() { - return reference; - } - - public void setReference(final Container reference) { - this.reference = reference; - } - - public int getJmxPort() { - return jmxPort; - } - - public void setJmxPort(final int jmxPort) { - this.jmxPort = jmxPort; - } - - public String getJmxUser() { - return jmxUser; - } - - public void setJmxUser(final String jmxUser) { - this.jmxUser = jmxUser; - } - - public String getJmxPassword() { - return jmxPassword; - } - - public void setJmxPassword(final String jmxPassword) { - this.jmxPassword = jmxPassword; - } - - public Machine getMachineReference() { - return machineReference; - } - - public void setMachineReference(final Machine machineReference) { - this.machineReference = machineReference; - } -} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/HazelcastRegistryInstance.java b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/HazelcastRegistryInstance.java deleted file mode 100644 index 76b361f..0000000 --- a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/HazelcastRegistryInstance.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.ow2.petals.deploymentmodel.busmodel; - -import java.util.List; - -import org.ow2.petals.deploymentmodel.topologymodel.HazelcastRegistry; - -/** - * Class describing an Hazelcast Registry instance of a Petals ESB bus. - * - * @author alagane - */ -public class HazelcastRegistryInstance extends RegistryInstance { - /** - * The reference of the Petals ESB Hazelcast Registry in - * {@link org.ow2.petals.deploymentmodel.topologymodel.TopologyModel}. - */ - private HazelcastRegistry reference; - - /** - * Name identifying the Petals ESB Hazelcast Registry instance inside the Hazelcast cluster. A deployment property - * can be used. Optional, if not set, the value defined by the referenced HazelcastRegistry will be used. - */ - private String groupName; - - /** - * Password identifying the Petals ESB Hazelcast Registry instance inside the Hazelcast cluster. A deployment - * property can be used. Optional, if not set, the value defined by the referenced HazelcastRegistry will be used. - */ - private String groupPassword; - - /** - * List of member instances composing the current Petals ESB Hazelcast Registry instance. - */ - private List memberInstances; - - public HazelcastRegistry getReference() { - return reference; - } - - public void setReference(final HazelcastRegistry reference) { - this.reference = reference; - } - - public String getGroupName() { - return groupName; - } - - public void setGroupName(final String groupName) { - this.groupName = groupName; - } - - public String getGroupPassword() { - return groupPassword; - } - - public void setGroupPassword(final String groupPassword) { - this.groupPassword = groupPassword; - } - - public List getMemberInstances() { - return memberInstances; - } - - public void setMemberInstances(final List memberInstances) { - this.memberInstances = memberInstances; - } -} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/HazelcastRegistryMemberInstance.java b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/HazelcastRegistryMemberInstance.java deleted file mode 100644 index 2363343..0000000 --- a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/HazelcastRegistryMemberInstance.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.ow2.petals.deploymentmodel.busmodel; - -import org.ow2.petals.deploymentmodel.topologymodel.HazelcastRegistryMember; - -/** - * Class describing a member of a Petals ESB Hazelcast Registry instance. - * - * @author alagane - */ -public class HazelcastRegistryMemberInstance { - /** - * The reference of the member of the Petals ESB Hazelcast Registry in - * {@link org.ow2.petals.deploymentmodel.topologymodel.TopologyModel}. - */ - private HazelcastRegistryMember reference; - - /** - * The communication port of the member instance. A deployment property can be used. Optional, if not set, the value - * defined by the referenced {@link HazelcastRegistryMember} will be used. - */ - private String port; - - /** - * The reference of the machine on which the current Petals ESB Hazelcast Registry is running. - */ - private Machine machineReference; - - public HazelcastRegistryMember getReference() { - return reference; - } - - public void setReference(final HazelcastRegistryMember reference) { - this.reference = reference; - } - - public String getPort() { - return port; - } - - public void setPort(final String port) { - this.port = port; - } - - public Machine getMachineReference() { - return machineReference; - } - - public void setMachineReference(final Machine machineReference) { - this.machineReference = machineReference; - } -} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/Machine.java b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/Machine.java deleted file mode 100644 index 9e1dd6b..0000000 --- a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/Machine.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.ow2.petals.deploymentmodel.busmodel; - -/** - * Superclass for different types of machines on which Petals ESB buses or Hazelcast registry members will be running. - * - * @author alagane - */ -public abstract class Machine { - /** - * Identifier of the machine. - */ - private String id; - - public String getId() { - return id; - } - - public void setId(final String id) { - this.id = id; - } -} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/ProvisionedMachine.java b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/ProvisionedMachine.java deleted file mode 100644 index 847cd17..0000000 --- a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/ProvisionedMachine.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.ow2.petals.deploymentmodel.busmodel; - -/** - * Class describing physical or virtual machine. - * - * @author alagane - */ -public class ProvisionedMachine extends Machine { - /** - * Hostname, IP address or deployment property name of the provisioned machine. - */ - private String hostname; - - public String getHostname() { - return hostname; - } - - public void setHostname(final String hostname) { - this.hostname = hostname; - } -} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/RegistryInstance.java b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/RegistryInstance.java deleted file mode 100644 index 12c173c..0000000 --- a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/RegistryInstance.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.ow2.petals.deploymentmodel.busmodel; - -/** - * Superclass for different types of registry instances. - * - * @author alagane - */ -public abstract class RegistryInstance { -} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/ServiceUnitInstance.java b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/ServiceUnitInstance.java deleted file mode 100644 index 4ea8932..0000000 --- a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/ServiceUnitInstance.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.ow2.petals.deploymentmodel.busmodel; - -import java.awt.Container; - -import org.ow2.petals.deploymentmodel.serviceunitmodel.ServiceUnit; - -/** - * Class for instance of a service unit running on a Petals ESB container - * - * @author alagane - */ -public class ServiceUnitInstance { - /** - * Reference to a service-unit of the service-units object model - */ - private ServiceUnit reference; - - /** - * Reference to a container of the topology object model - */ - private Container containerReference; - - public ServiceUnit getReference() { - return reference; - } - - public void setReference(final ServiceUnit reference) { - this.reference = reference; - } - - public Container getContainerReference() { - return containerReference; - } - - public void setContainerReference(final Container containerReference) { - this.containerReference = containerReference; - } -} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/StandaloneRegistryInstance.java b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/StandaloneRegistryInstance.java deleted file mode 100644 index 0df120d..0000000 --- a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/StandaloneRegistryInstance.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.ow2.petals.deploymentmodel.busmodel; - -import org.ow2.petals.deploymentmodel.topologymodel.StandaloneRegistry; - -/** - * Instance of {@link org.ow2.petals.deploymentmodel.topologymodel.StandaloneRegistry}. - * - * @author alagane - */ -public class StandaloneRegistryInstance extends RegistryInstance { - private StandaloneRegistry reference; - - public StandaloneRegistry getReference() { - return reference; - } - - public void setReference(final StandaloneRegistry reference) { - this.reference = reference; - } -} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/TopologyInstance.java b/src/main/java/org/ow2/petals/deploymentmodel/busmodel/TopologyInstance.java deleted file mode 100644 index e166fa3..0000000 --- a/src/main/java/org/ow2/petals/deploymentmodel/busmodel/TopologyInstance.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.ow2.petals.deploymentmodel.busmodel; - -import java.util.List; - -import org.ow2.petals.deploymentmodel.topologymodel.Topology; - -/** - * Class describing an instance of a topology in {@link org.ow2.petals.deploymentmodel.busmodel.BusModel}. - * - * @author alagane - */ -public class TopologyInstance { - /** - * The reference topology from {@link org.ow2.petals.deploymentmodel.topologymodel.TopologyModel}. - */ - private Topology reference; - - /** - * Domain name of the Petals ESB bus. A deployment property can be used. It must be set if no default value is set - * in its reference topology. - */ - private String domainName; - - /** - * The instances of registry to use in Topology. - */ - private RegistryInstance registryInstance; - - /** - * The instances of Petals ESB containers forming the Petals ESB bus. - */ - private List containerInstances; - - public Topology getReference() { - return reference; - } - - public void setReference(final Topology reference) { - this.reference = reference; - } - - public String getDomainName() { - return domainName; - } - - public void setDomainName(final String domainName) { - this.domainName = domainName; - } - - public RegistryInstance getRegistryInstance() { - return registryInstance; - } - - public void setRegistryInstance(final RegistryInstance registryInstance) { - this.registryInstance = registryInstance; - } - - public List getContainerInstances() { - return containerInstances; - } - - public void setContainerInstances(final List containerInstances) { - this.containerInstances = containerInstances; - } -} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/componentrepository/Component.java b/src/main/java/org/ow2/petals/deploymentmodel/componentrepository/Component.java deleted file mode 100644 index 31981e2..0000000 --- a/src/main/java/org/ow2/petals/deploymentmodel/componentrepository/Component.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.ow2.petals.deploymentmodel.componentrepository; - -import java.net.URI; -import java.util.List; -import java.util.Map; - -/** - * Class describing a component artifact. - * - * @author alagane - */ -public class Component { - /** - * The identifier of this component in the model. Must be the same than the one defined in the JBI descriptor of the - * component. - */ - private String id; - - /** - * The URL of the associated archive. - */ - private URI url; - - /** - * The map of parameters required by the component. The key of the map is the name of the parameter, and the value - * of the map is the default value of the parameter. If there is no default value, the value must be null. - */ - private Map parameters; - - /** - * A set of shared library references that the component requires. They reference shared libraries defined in the - * model by their id. Optional. - */ - private List sharedLibraryReferences; - - public String getId() { - return id; - } - - public void setId(final String id) { - this.id = id; - } - - public URI getUrl() { - return url; - } - - public void setUrl(final URI url) { - this.url = url; - } - - public Map getParameters() { - return parameters; - } - - public void setParameters(final Map parameters) { - this.parameters = parameters; - } - - public List getSharedLibraryReferences() { - return sharedLibraryReferences; - } - - public void setSharedLibraryReferences(final List sharedLibraryReferences) { - this.sharedLibraryReferences = sharedLibraryReferences; - } -} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/componentrepository/ComponentRepository.java b/src/main/java/org/ow2/petals/deploymentmodel/componentrepository/ComponentRepository.java deleted file mode 100644 index eefa775..0000000 --- a/src/main/java/org/ow2/petals/deploymentmodel/componentrepository/ComponentRepository.java +++ /dev/null @@ -1,39 +0,0 @@ -package org.ow2.petals.deploymentmodel.componentrepository; - -import java.util.List; - -/** - * This model defines a set of binding components, service engines and shared libraries that can be used to perform the - * deployment of a Petals ESB bus. Such models are included in Petals ESB distribution packs, and you can write your - * own. - * - * @author alagane - */ -public class ComponentRepository { - /** - * The list of components objects of this repository. Their id must be unique for all component repository models. - */ - private List components; - - /** - * The list of shared libraries of this repository. Optional. Their couple of id and version must be unique in the - * model. - */ - private List sharedLibraries; - - public List getComponents() { - return components; - } - - public void setComponents(final List components) { - this.components = components; - } - - public List getSharedLibraries() { - return sharedLibraries; - } - - public void setSharedLibraries(final List sharedLibraries) { - this.sharedLibraries = sharedLibraries; - } -} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/componentrepository/SharedLibrary.java b/src/main/java/org/ow2/petals/deploymentmodel/componentrepository/SharedLibrary.java deleted file mode 100644 index c508d18..0000000 --- a/src/main/java/org/ow2/petals/deploymentmodel/componentrepository/SharedLibrary.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.ow2.petals.deploymentmodel.componentrepository; - -import java.net.URI; - -/** - * Class describing a shared library of this repository. - * - * @author alagane - */ -public class SharedLibrary { - /** - * The identifier of this shared library in the model. Must be the same than the one defined in the JBI descriptor - * of the shared library. - */ - private String id; - - /** - * The version of this shared library in the model. Must be the same than the one defined in the JBI descriptor of - * the shared library. - */ - private String version; - - /** - * The URL of the associated archive. - */ - private URI url; - - public String getId() { - return id; - } - - public void setId(final String id) { - this.id = id; - } - - public String getVersion() { - return version; - } - - public void setVersion(final String version) { - this.version = version; - } - - public URI getUrl() { - return url; - } - - public void setUrl(final URI url) { - this.url = url; - } -} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/serviceunitmodel/ServiceUnit.java b/src/main/java/org/ow2/petals/deploymentmodel/serviceunitmodel/ServiceUnit.java deleted file mode 100644 index 99c1d1a..0000000 --- a/src/main/java/org/ow2/petals/deploymentmodel/serviceunitmodel/ServiceUnit.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.ow2.petals.deploymentmodel.serviceunitmodel; - -import java.net.URI; -import java.util.Map; - -import org.ow2.petals.deploymentmodel.busmodel.ComponentInstance; - -/** - * Class describing a service unit to deploy. - * - * @author alagane - */ -public class ServiceUnit { - /** - * The unique identifier of this service unit in the model. Can be different from the service unit name. - */ - private String id; - - /** - * The URL of the associated archive that can be a service assembly or a deployable service unit. - */ - private URI url; - - /** - * The map of placeholder required by the service unit. The key of the map is the key of the placeholder, and the - * value of the map is the default value of the placeholder. If there is no default value, the value must be null. - */ - private Map placeholders; - - /** - * The identifier of the component instance on which this service unit must be deployed. Optional for deployable - * service unit and service unit embedded in a service assembly, required for other service units. - */ - private ComponentInstance componentInstanceId; - - public String getId() { - return id; - } - - public void setId(final String id) { - this.id = id; - } - - public URI getUrl() { - return url; - } - - public void setUrl(final URI url) { - this.url = url; - } - - public ComponentInstance getComponentInstanceId() { - return componentInstanceId; - } - - public void setComponentInstanceId(final ComponentInstance componentInstanceId) { - this.componentInstanceId = componentInstanceId; - } - - public Map getPlaceholders() { - return placeholders; - } - - public void setPlaceholders(final Map placeholders) { - this.placeholders = placeholders; - } -} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/serviceunitmodel/ServiceUnitModel.java b/src/main/java/org/ow2/petals/deploymentmodel/serviceunitmodel/ServiceUnitModel.java deleted file mode 100644 index 3a3238c..0000000 --- a/src/main/java/org/ow2/petals/deploymentmodel/serviceunitmodel/ServiceUnitModel.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.ow2.petals.deploymentmodel.serviceunitmodel; - -import java.util.List; - -/** - * This model defines a set of service units to deploy on your Petals ESB bus. This model will be mainly written by - * development teams because they have the knowledge of service units to deploy. - * - * @author alagane - */ -public class ServiceUnitModel { - /** - * The list of service units to deploy. Their id must be unique in the model. There must be at least one service - * unit in the model. - */ - private List serviceUnits; - - public List getServiceUnits() { - return serviceUnits; - } - - public void setServiceUnits(final List serviceUnits) { - this.serviceUnits = serviceUnits; - } -} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/Container.java b/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/Container.java deleted file mode 100644 index 2f4da29..0000000 --- a/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/Container.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.ow2.petals.deploymentmodel.topologymodel; - -/** - * Class for Petals ESB containers members of a topology. - */ -public class Container { - /** - * Identifier of the Petals ESB container as used as name in the file topology.xml. - */ - private String id; - - /** - * Default JMX port value. A deployment property can be used. Optional, if not set, the internal default value 7700 - * will be used. - */ - private int defaultJmxPort; - - /** - * Default JMX username value. A deployment property can be used. Optional, if not set, the internal default value - * 'petals' will be used. - */ - private String defaultJmxUser; - - /** - * Default JMX password value. A deployment property can be used. Optional, if not set, the internal default value - * 'petals' will be used. - */ - private String defaultJmxPassword; - - public String getId() { - return id; - } - - public void setId(final String id) { - this.id = id; - } - - public int getDefaultJmxPort() { - return defaultJmxPort; - } - - public void setDefaultJmxPort(final int defaultJmxPort) { - this.defaultJmxPort = defaultJmxPort; - } - - public String getDefaultJmxUser() { - return defaultJmxUser; - } - - public void setDefaultJmxUser(final String defaultJmxUser) { - this.defaultJmxUser = defaultJmxUser; - } - - public String getDefaultJmxPassword() { - return defaultJmxPassword; - } - - public void setDefaultJmxPassword(final String defaultJmxPassword) { - this.defaultJmxPassword = defaultJmxPassword; - } -} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/HazelcastRegistry.java b/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/HazelcastRegistry.java deleted file mode 100644 index 358aa66..0000000 --- a/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/HazelcastRegistry.java +++ /dev/null @@ -1,51 +0,0 @@ -package org.ow2.petals.deploymentmodel.topologymodel; - -import java.util.List; - -/** - * Default implementation for a distributed topology. - * - * @author alagane - */ -public class HazelcastRegistry extends Registry { - /** - * Default group name value. A deployment property can be used. Optional, if not set, the internal default value - * 'default-sample' will be used. - */ - private String defaultGroupName; - - /** - * Default password value. A deployment property can be used. Optional, if not set, the internal default value - * 's3cr3t' will be used. - */ - private String defaultGroupPassword; - - /** - * The members of the Hazelcast registry. - */ - private List members; - - public String getDefaultGroupName() { - return defaultGroupName; - } - - public void setDefaultGroupName(final String defaultGroupName) { - this.defaultGroupName = defaultGroupName; - } - - public String getDefaultGroupPassword() { - return defaultGroupPassword; - } - - public void setDefaultGroupPassword(final String defaultGroupPassword) { - this.defaultGroupPassword = defaultGroupPassword; - } - - public List getMembers() { - return members; - } - - public void setMembers(final List members) { - this.members = members; - } -} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/HazelcastRegistryMember.java b/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/HazelcastRegistryMember.java deleted file mode 100644 index d9b671b..0000000 --- a/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/HazelcastRegistryMember.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.ow2.petals.deploymentmodel.topologymodel; - -/** - * Class describing members of the Petals ESB Hazelcast Registry. - * - * @author alagane - */ -public class HazelcastRegistryMember { - /** - * Identifier used as name in the file cluster.xml. - */ - private String id; - - /** - * Default communication port value. A deployment property can be used. Optional, if not set, the internal default - * value '7900' will be used. - */ - private String defaultPort; - - public String getId() { - return id; - } - - public void setId(final String id) { - this.id = id; - } - - public String getDefaultPort() { - return defaultPort; - } - - public void setDefaultPort(final String defaultPort) { - this.defaultPort = defaultPort; - } -} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/Registry.java b/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/Registry.java deleted file mode 100644 index 34fc2aa..0000000 --- a/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/Registry.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.ow2.petals.deploymentmodel.topologymodel; - -/** - * Superclass for registry types. - * - * @author alagane - */ -public abstract class Registry { - /** - * Used to identify the registry across the model. It must be unique in the model. - */ - private String id; - - public String getId() { - return id; - } - - public void setId(final String id) { - this.id = id; - } -} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/StandaloneRegistry.java b/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/StandaloneRegistry.java deleted file mode 100644 index f508e74..0000000 --- a/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/StandaloneRegistry.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.ow2.petals.deploymentmodel.topologymodel; - -/** - * Default implementation for a standalone topology. Cannot be used for a distributed topology. - * - * @author alagane - */ -public class StandaloneRegistry extends Registry { -} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/Topology.java b/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/Topology.java deleted file mode 100644 index 3db3d4e..0000000 --- a/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/Topology.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.ow2.petals.deploymentmodel.topologymodel; - -import java.util.List; - -/** - * Class describing a topology of a Petals ESB bus. - * - * @author alagane - */ -public class Topology { - private String id; - - /** - * Default domain name of the topology. Optional. - */ - private String defaultDomainName; - - /** - * Petals ESB containers of the topology. Their id must be unique in the topology. There must be at least one - * container in the topology. - */ - private List containers; - - /** - * The registry used in the topology. Optional. - */ - private Registry registry; - - public String getId() { - return id; - } - - public void setId(final String id) { - this.id = id; - } - - public String getDefaultDomainName() { - return defaultDomainName; - } - - public void setDefaultDomainName(final String defaultDomainName) { - this.defaultDomainName = defaultDomainName; - } - - public List getContainers() { - return containers; - } - - public void setContainers(final List containers) { - this.containers = containers; - } - - public Registry getRegistry() { - return registry; - } - - public void setRegistry(final Registry registry) { - this.registry = registry; - } -} diff --git a/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/TopologyModel.java b/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/TopologyModel.java deleted file mode 100644 index d9707ba..0000000 --- a/src/main/java/org/ow2/petals/deploymentmodel/topologymodel/TopologyModel.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.ow2.petals.deploymentmodel.topologymodel; - -import java.util.List; - -/** - * This model defines a set of topologies, used by Petals ESB buses. This model will be mainly written by the Petals ESB - * bus architect. - * - * @author alagane - */ -public class TopologyModel { - /** - * The list of topologies in the model. Their id must be unique in the model. There must be at least one topology in - * the model. - */ - private List topologies; - - public List getTopologies() { - return topologies; - } - - public void setTopologies(final List topologies) { - this.topologies = topologies; - } -} diff --git a/src/main/resources/binding.xjb b/src/main/resources/binding.xjb new file mode 100644 index 0000000..3391092 --- /dev/null +++ b/src/main/resources/binding.xjb @@ -0,0 +1,26 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/bus-model.xsd b/src/main/resources/bus-model.xsd new file mode 100644 index 0000000..c96c3ed --- /dev/null +++ b/src/main/resources/bus-model.xsd @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/component-repository.xsd b/src/main/resources/component-repository.xsd new file mode 100644 index 0000000..c920201 --- /dev/null +++ b/src/main/resources/component-repository.xsd @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/model.xsd b/src/main/resources/model.xsd new file mode 100644 index 0000000..fe4424c --- /dev/null +++ b/src/main/resources/model.xsd @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/service-unit-model.xsd b/src/main/resources/service-unit-model.xsd new file mode 100644 index 0000000..419337d --- /dev/null +++ b/src/main/resources/service-unit-model.xsd @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/topology-model.xsd b/src/main/resources/topology-model.xsd new file mode 100644 index 0000000..3dd7d70 --- /dev/null +++ b/src/main/resources/topology-model.xsd @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java b/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java new file mode 100644 index 0000000..157da52 --- /dev/null +++ b/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java @@ -0,0 +1,188 @@ +/** + * Copyright (c) 2018-2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.utils; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.io.StringReader; +import java.io.StringWriter; +import java.net.MalformedURLException; +import java.net.URISyntaxException; +import java.util.List; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import javax.xml.transform.stream.StreamSource; + +import org.junit.Test; +import org.ow2.petals.admin.topology.Container.State; +import org.ow2.petals.deployer.model.bus.xml._1.Bus; +import org.ow2.petals.deployer.model.bus.xml._1.BusModel; +import org.ow2.petals.deployer.model.bus.xml._1.ComponentInstance; +import org.ow2.petals.deployer.model.bus.xml._1.ContainerInstance; +import org.ow2.petals.deployer.model.bus.xml._1.ProvisionedMachine; +import org.ow2.petals.deployer.model.bus.xml._1.ServiceUnitInstance; +import org.ow2.petals.deployer.model.component_repository.xml._1.Component; +import org.ow2.petals.deployer.model.component_repository.xml._1.ComponentRepository; +import org.ow2.petals.deployer.model.service_unit.xml._1.ServiceUnit; +import org.ow2.petals.deployer.model.service_unit.xml._1.ServiceUnitModel; +import org.ow2.petals.deployer.model.topology.xml._1.Container; +import org.ow2.petals.deployer.model.topology.xml._1.Topology; +import org.ow2.petals.deployer.model.topology.xml._1.TopologyModel; +import org.ow2.petals.deployer.model.xml._1.Model; +import org.ow2.petals.deployer.model.xml._1.ObjectFactory; + +public class ParseModelTest { + + final public static String CONTAINER_NAME = "sample-0"; + + final public static String CONTAINER_HOST = "localhost"; + + final public static int CONTAINER_JMX_PORT = 7700; + + final public static String CONTAINER_USER = "petals"; + + final public static String CONTAINER_PWD = "petals"; + + final public static State CONTAINER_STATE = State.REACHABLE; + + @Test + public void read() throws Exception { + ObjectFactory of = new ObjectFactory(); + + Model model = generateTestModel(); + + StringWriter marshalledModelWriter = new StringWriter(); + StringWriter unmarshalledModelWriter = new StringWriter(); + + JAXBContext jaxbContext = JAXBContext.newInstance(Model.class); + + Marshaller marshaller = jaxbContext.createMarshaller(); + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + + marshaller.marshal(of.createModel(model), marshalledModelWriter); + + Model unmarshalledModel = unmarshaller + .unmarshal(new StreamSource(new StringReader(marshalledModelWriter.toString())), Model.class) + .getValue(); + + marshaller.marshal(of.createModel(unmarshalledModel), unmarshalledModelWriter); + + assertEquals(marshalledModelWriter.toString(), unmarshalledModelWriter.toString()); + } + + public static Model generateTestModel() throws MalformedURLException, IOException, URISyntaxException { + Model model = new Model(); + + /* Component Repository */ + + ComponentRepository compRepo = new ComponentRepository(); + model.setComponentRepository(compRepo); + + Component bcSoap = new Component(); + bcSoap.setId("petals-bc-soap"); + bcSoap.setUrl( + ZipUtils.createZipFromResourceDirectory("artifacts/petals-bc-soap-5.0.0").toURI().toURL().toString()); + compRepo.getComponent().add(bcSoap); + + /* Service Unit Model */ + + ServiceUnitModel suModel = new ServiceUnitModel(); + model.setServiceUnitModel(suModel); + + List serviceUnits = suModel.getServiceUnit(); + + ServiceUnit suProv1 = new ServiceUnit(); + suProv1.setId("su-SOAP-Hello_Service1-provide"); + suProv1.setUrl(ZipUtils.createZipFromResourceDirectory("artifacts/sa-SOAP-Hello_Service1-provide").toURI() + .toURL().toString()); + serviceUnits.add(suProv1); + + ServiceUnit suProv2 = new ServiceUnit(); + suProv2.setId("su-SOAP-Hello_Service2-provide"); + suProv2.setUrl(ZipUtils.createZipFromResourceDirectory("artifacts/sa-SOAP-Hello_Service2-provide").toURI() + .toURL().toString()); + serviceUnits.add(suProv2); + + ServiceUnit suCons = new ServiceUnit(); + suCons.setId("su-SOAP-Hello_PortType-consume"); + suCons.setUrl(ZipUtils.createZipFromResourceDirectory("artifacts/sa-SOAP-Hello_PortType-consume").toURI() + .toURL().toString()); + serviceUnits.add(suCons); + + /* Topology Model */ + + TopologyModel topoModel = new TopologyModel(); + model.setTopologyModel(topoModel); + + Topology topo = new Topology(); + topo.setId("topo1"); + topoModel.getTopology().add(topo); + + Container cont = new Container(); + cont.setId(CONTAINER_NAME); + cont.setDefaultJmxPort(CONTAINER_JMX_PORT); + cont.setDefaultJmxUser(CONTAINER_USER); + cont.setDefaultJmxPassword(CONTAINER_PWD); + topo.getContainer().add(cont); + + /* Bus Model */ + + BusModel busModel = new BusModel(); + model.setBusModel(busModel); + + ProvisionedMachine machine = new ProvisionedMachine(); + machine.setId("main"); + machine.setHostname("localhost"); + busModel.getMachine().add(machine); + + Bus bus = new Bus(); + bus.setTopologyRef(topo.getId()); + busModel.getBus().add(bus); + + ContainerInstance contInst = new ContainerInstance(); + contInst.setRef(cont.getId()); + contInst.setMachineRef(machine.getId()); + bus.getContainerInstance().add(contInst); + + ComponentInstance bcSoapInst = new ComponentInstance(); + bcSoapInst.setRef(bcSoap.getId()); + contInst.getComponentInstance().add(bcSoapInst); + + List suInstances = contInst.getServiceUnitInstance(); + + ServiceUnitInstance suInst = new ServiceUnitInstance(); + suInst.setRef(suProv1.getId()); + suInstances.add(suInst); + + suInst = new ServiceUnitInstance(); + suInst.setRef(suProv2.getId()); + suInstances.add(suInst); + + suInst = new ServiceUnitInstance(); + suInst.setRef(suCons.getId()); + suInstances.add(suInst); + + return model; + } +} diff --git a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java new file mode 100644 index 0000000..6c0823b --- /dev/null +++ b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java @@ -0,0 +1,638 @@ +/** + * Copyright (c) 2018-2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.utils; + +import org.junit.Before; + +public class RuntimeModelComparatorTest { + + private RuntimeModelComparator comparator; + + @Before + public void setupModelComparator() { + comparator = new RuntimeModelComparator(); + } + +// @Test +// public void compareComponentsWithDifferentIds() { +// Component c1 = new Component(); +// c1.setId("comp1"); +// +// Component c2 = new Component(); +// c2.setId("comp2"); +// +// assertFalse(comparator.compareComponents(c1, c2)); +// assertFalse(comparator.compareComponents(c1, c2)); +// } +// +// @Test +// public void compareComponents() { +// Component c1 = new Component(); +// c1.setId("comp"); +// +// Component c2 = new Component(); +// c2.setId("comp"); +// +// assertTrue(comparator.compareComponents(c1, c2)); +// } +// +// @Test +// public void compareComponentInstancesWithDifferentComponents() { +// ModelComparator mockedComparator = spy(ModelComparator.class); +// doReturn(false).when(mockedComparator).compareComponents(null, null); +// +// ComponentInstance ci1 = new ComponentInstance(); +// ci1.setReference("comp"); +// +// ComponentInstance ci2 = new ComponentInstance(); +// ci2.setReference("comp"); +// +// assertFalse(mockedComparator.compareComponentsInstances(ci1, ci2)); +// assertFalse(mockedComparator.compareComponentsInstances(ci2, ci1)); +// } +// +// @Test +// public void compareComponentInstancesWithDifferentIds() { +// ModelComparator mockedComparator = spy(ModelComparator.class); +// doReturn(true).when(mockedComparator).compareComponents(null, null); +// +// ComponentInstance ci1 = new ComponentInstance(); +// ci1.setReference("comp1"); +// +// ComponentInstance ci2 = new ComponentInstance(); +// ci2.setReference("comp2"); +// +// assertFalse(mockedComparator.compareComponentsInstances(ci1, ci2)); +// assertFalse(mockedComparator.compareComponentsInstances(ci2, ci1)); +// } +// +// @Test +// public void compareComponentInstances() { +// ModelComparator mockedComparator = spy(ModelComparator.class); +// doReturn(true).when(mockedComparator).compareComponents(null, null); +// +// ComponentInstance ci1 = new ComponentInstance(); +// ci1.setReference("comp"); +// +// ComponentInstance ci2 = new ComponentInstance(); +// ci2.setReference("comp"); +// +// assertTrue(mockedComparator.compareComponentsInstances(ci1, ci2)); +// assertTrue(mockedComparator.compareComponentsInstances(ci2, ci1)); +// } +// +// @Test +// public void compareServiceUnitsWithDifferentIds() { +// ServiceUnit su1 = new ServiceUnit(); +// su1.setId("su1"); +// su1.setTargetComponent("comp"); +// +// ServiceUnit su2 = new ServiceUnit(); +// su2.setId("su2"); +// su2.setTargetComponent("comp"); +// +// assertFalse(comparator.compareServiceUnits(su1, su2)); +// assertFalse(comparator.compareServiceUnits(su2, su1)); +// } +// +// @Test +// public void compareServiceUnitsWithDifferentComponents() { +// +// ServiceUnit su1 = new ServiceUnit(); +// su1.setId("su"); +// su1.setTargetComponent("comp1"); +// +// ServiceUnit su2 = new ServiceUnit(); +// su2.setId("su"); +// su2.setTargetComponent("comp2"); +// +// assertFalse(comparator.compareServiceUnits(su1, su2)); +// assertFalse(comparator.compareServiceUnits(su2, su1)); +// } +// +// @Test +// public void compareServiceUnits() { +// ServiceUnit su1 = new ServiceUnit(); +// su1.setId("su"); +// su1.setTargetComponent("comp"); +// +// ServiceUnit su2 = new ServiceUnit(); +// su2.setId("su"); +// su2.setTargetComponent("comp"); +// +// assertTrue(comparator.compareServiceUnits(su1, su2)); +// assertTrue(comparator.compareServiceUnits(su2, su1)); +// } +// +// @Test +// public void compareServiceUnitInstancesWithDifferentContainerInstances() { +// ModelComparator mockedComparator = spy(ModelComparator.class); +// doReturn(false).when(mockedComparator).compareContainerInstances(null, null); +// doReturn(true).when(mockedComparator).compareServiceUnits(null, null); +// +// ServiceUnitInstance sui1 = new ServiceUnitInstance(); +// +// ServiceUnitInstance sui2 = new ServiceUnitInstance(); +// +// assertFalse(mockedComparator.compareServiceUnitInstances(sui1, sui2)); +// assertFalse(mockedComparator.compareServiceUnitInstances(sui2, sui1)); +// } +// +// @Test +// public void compareServiceUnitInstancesWithDifferentServiceUnits() { +// ModelComparator mockedComparator = spy(ModelComparator.class); +// doReturn(true).when(mockedComparator).compareContainerInstances(null, null); +// doReturn(false).when(mockedComparator).compareServiceUnits(null, null); +// +// ServiceUnitInstance sui1 = new ServiceUnitInstance(); +// +// ServiceUnitInstance sui2 = new ServiceUnitInstance(); +// +// assertFalse(mockedComparator.compareServiceUnitInstances(sui1, sui2)); +// assertFalse(mockedComparator.compareServiceUnitInstances(sui2, sui1)); +// } +// +// @Test +// public void compareMachinesWithDifferentHostnames() { +// ProvisionedMachine m1 = new ProvisionedMachine(); +// m1.setId("machine"); +// m1.setHostname("localhost"); +// +// ProvisionedMachine m2 = new ProvisionedMachine(); +// m2.setId("machine"); +// m2.setHostname("1.2.3.4"); +// +// assertFalse(comparator.compareMachines(m1, m2)); +// assertFalse(comparator.compareMachines(m2, m1)); +// } +// +// @Test +// public void compareMachinesWithDifferentIds() { +// ProvisionedMachine m1 = new ProvisionedMachine(); +// m1.setId("machine1"); +// m1.setHostname("localhost"); +// +// ProvisionedMachine m2 = new ProvisionedMachine(); +// m2.setId("machine2"); +// m2.setHostname("localhost"); +// +// assertTrue(comparator.compareMachines(m1, m2)); +// assertTrue(comparator.compareMachines(m2, m1)); +// } +// +// @Test +// public void compareMachinesNotProvisioned() { +// Machine m1 = new Machine() { +// }; +// +// ProvisionedMachine m2 = new ProvisionedMachine(); +// m2.setId("machine"); +// m2.setHostname("localhost"); +// +// assertFalse(comparator.compareMachines(m1, m2)); +// assertFalse(comparator.compareMachines(m2, m1)); +// } +// +// @Test +// public void compareMachines() { +// ProvisionedMachine m1 = new ProvisionedMachine(); +// m1.setId("machine"); +// m1.setHostname("localhost"); +// +// ProvisionedMachine m2 = new ProvisionedMachine(); +// m2.setId("machine"); +// m2.setHostname("localhost"); +// +// assertTrue(comparator.compareMachines(m1, m2)); +// assertTrue(comparator.compareMachines(m2, m1)); +// } +// +// @Test +// public void compareServiceUnitInstances() { +// ModelComparator mockedComparator = spy(ModelComparator.class); +// doReturn(true).when(mockedComparator).compareContainerInstances(null, null); +// doReturn(true).when(mockedComparator).compareServiceUnits(null, null); +// +// ServiceUnitInstance sui1 = new ServiceUnitInstance(); +// +// ServiceUnitInstance sui2 = new ServiceUnitInstance(); +// +// assertTrue(mockedComparator.compareServiceUnitInstances(sui1, sui2)); +// assertTrue(mockedComparator.compareServiceUnitInstances(sui2, sui1)); +// } +// +// @Test +// public void compareContainerInstancesWithDifferentIds() { +// ModelComparator mockedComparator = spy(ModelComparator.class); +// doReturn(true).when(mockedComparator).compareMachines(null, null); +// +// Container c1 = new Container(); +// c1.setId("cont1"); +// c1.setDefaultJmxUser("petals"); +// c1.setDefaultJmxPort(7700); +// c1.setDefaultJmxPassword("password"); +// +// ContainerInstance ci1 = new ContainerInstance(); +// ci1.setReference(c1.getId()); +// +// Container c2 = new Container(); +// c2.setId("cont2"); +// +// ContainerInstance ci2 = new ContainerInstance(); +// ci2.setReference(c2.getId()); +// ci2.setJmxUser("petals"); +// ci2.setJmxPort(7700); +// ci2.setJmxPassword("password"); +// +// assertFalse(mockedComparator.compareContainerInstances(ci1, ci2)); +// assertFalse(mockedComparator.compareContainerInstances(ci2, ci1)); +// } +// +// @Test +// public void compareContainerInstancesWithDifferentMachines() { +// ModelComparator mockedComparator = spy(ModelComparator.class); +// doReturn(false).when(mockedComparator).compareMachines(null, null); +// +// Container c1 = new Container(); +// c1.setId("cont"); +// c1.setDefaultJmxUser("petals"); +// c1.setDefaultJmxPort(7700); +// c1.setDefaultJmxPassword("password"); +// +// ContainerInstance ci1 = new ContainerInstance(); +// ci1.setReference(c1.getId()); +// +// Container c2 = new Container(); +// c2.setId("cont"); +// +// ContainerInstance ci2 = new ContainerInstance(); +// ci2.setReference(c2.getId()); +// ci2.setJmxUser("petals"); +// ci2.setJmxPort(7700); +// ci2.setJmxPassword("password"); +// +// assertFalse(mockedComparator.compareContainerInstances(ci1, ci2)); +// assertFalse(mockedComparator.compareContainerInstances(ci2, ci1)); +// } +// +// @Test +// public void compareContainerInstancesWithDifferentJmxUsers() { +// ModelComparator mockedComparator = spy(ModelComparator.class); +// doReturn(true).when(mockedComparator).compareMachines(null, null); +// +// Container c1 = new Container(); +// c1.setId("cont"); +// c1.setDefaultJmxUser("petals"); +// c1.setDefaultJmxPort(7700); +// c1.setDefaultJmxPassword("password"); +// +// ContainerInstance ci1 = new ContainerInstance(); +// ci1.setReference(c1.getId()); +// +// Container c2 = new Container(); +// c2.setId("cont"); +// +// ContainerInstance ci2 = new ContainerInstance(); +// ci2.setReference(c2.getId()); +// ci2.setJmxUser("user"); +// ci2.setJmxPort(7700); +// ci2.setJmxPassword("password"); +// +// assertFalse(mockedComparator.compareContainerInstances(ci1, ci2)); +// assertFalse(mockedComparator.compareContainerInstances(ci2, ci1)); +// } +// +// @Test +// public void compareContainerInstancesWithDifferentJmxPorts() { +// ModelComparator mockedComparator = spy(ModelComparator.class); +// doReturn(true).when(mockedComparator).compareMachines(null, null); +// +// Container c1 = new Container(); +// c1.setId("cont"); +// c1.setDefaultJmxUser("petals"); +// c1.setDefaultJmxPort(80); +// c1.setDefaultJmxPassword("password"); +// +// ContainerInstance ci1 = new ContainerInstance(); +// ci1.setReference(c1.getId()); +// +// Container c2 = new Container(); +// c2.setId("cont"); +// +// ContainerInstance ci2 = new ContainerInstance(); +// ci2.setReference(c2.getId()); +// ci2.setJmxUser("petals"); +// ci2.setJmxPort(7700); +// ci2.setJmxPassword("password"); +// +// assertFalse(mockedComparator.compareContainerInstances(ci1, ci2)); +// assertFalse(mockedComparator.compareContainerInstances(ci2, ci1)); +// } +// +// @Test +// public void compareContainerInstancesWithDifferentJmxPasswords() { +// ModelComparator mockedComparator = spy(ModelComparator.class); +// doReturn(true).when(mockedComparator).compareMachines(null, null); +// +// Container c1 = new Container(); +// c1.setId("cont"); +// c1.setDefaultJmxUser("petals"); +// c1.setDefaultJmxPort(7700); +// c1.setDefaultJmxPassword("password"); +// +// ContainerInstance ci1 = new ContainerInstance(); +// ci1.setReference(c1.getId()); +// +// Container c2 = new Container(); +// c2.setId("cont"); +// +// ContainerInstance ci2 = new ContainerInstance(); +// ci2.setReference(c2.getId()); +// ci2.setJmxUser("petals"); +// ci2.setJmxPort(7700); +// ci2.setJmxPassword("azerty123"); +// +// assertFalse(mockedComparator.compareContainerInstances(ci1, ci2)); +// assertFalse(mockedComparator.compareContainerInstances(ci2, ci1)); +// } +// +// @Test +// public void compareContainerInstances() { +// ModelComparator mockedComparator = spy(ModelComparator.class); +// doReturn(true).when(mockedComparator).compareMachines(null, null); +// +// Container c1 = new Container(); +// c1.setId("cont"); +// c1.setDefaultJmxUser("petals"); +// c1.setDefaultJmxPort(7700); +// c1.setDefaultJmxPassword("password"); +// +// ContainerInstance ci1 = new ContainerInstance(); +// ci1.setReference(c1.getId()); +// +// Container c2 = new Container(); +// c2.setId("cont"); +// +// ContainerInstance ci2 = new ContainerInstance(); +// ci2.setReference(c2.getId()); +// ci2.setJmxUser("petals"); +// ci2.setJmxPort(7700); +// ci2.setJmxPassword("password"); +// +// assertTrue(mockedComparator.compareContainerInstances(ci1, ci2)); +// assertTrue(mockedComparator.compareContainerInstances(ci2, ci1)); +// } +// +// @Test +// public void compareComponentInstanceListsWithDifferentSizes() { +// List compInstances1 = new ArrayList<>(); +// compInstances1.add(null); +// +// List compInstances2 = new ArrayList<>(); +// compInstances2.add(null); +// compInstances2.add(null); +// +// assertFalse(comparator.compareComponentInstanceLists(compInstances1, compInstances2)); +// assertFalse(comparator.compareComponentInstanceLists(compInstances2, compInstances1)); +// } +// +// @Test +// public void compareComponentInstanceListsNotUnique() { +// ComponentInstance ci1 = new ComponentInstance(); +// ci1.setReference("comp1"); +// ComponentInstance ci2 = new ComponentInstance(); +// ci2.setReference("comp2"); +// +// ModelComparator mockedComparator = spy(ModelComparator.class); +// doReturn(false).when(mockedComparator).compareComponentsInstances(ci1, ci2); +// doReturn(false).when(mockedComparator).compareComponentsInstances(ci2, ci1); +// doReturn(true).when(mockedComparator).compareComponentsInstances(ci1, ci1); +// doReturn(true).when(mockedComparator).compareComponentsInstances(ci2, ci2); +// +// List compInstances1 = new ArrayList<>(); +// compInstances1.add(ci1); +// compInstances1.add(ci1); +// +// List compInstances2 = new ArrayList<>(); +// compInstances2.add(ci1); +// compInstances2.add(ci2); +// +// assertFalse(mockedComparator.compareComponentInstanceLists(compInstances1, compInstances2)); +// assertFalse(mockedComparator.compareComponentInstanceLists(compInstances2, compInstances1)); +// } +// +// @Test +// public void compareComponentInstanceListsWithDifferentItems() { +// ComponentInstance ci1 = new ComponentInstance(); +// ci1.setReference("comp"); +// +// ModelComparator mockedComparator = spy(ModelComparator.class); +// doReturn(false).when(mockedComparator).compareComponentsInstances(ci1, ci1); +// +// List compInstances1 = new ArrayList<>(); +// compInstances1.add(ci1); +// +// List compInstances2 = new ArrayList<>(); +// compInstances2.add(ci1); +// +// assertFalse(mockedComparator.compareComponentInstanceLists(compInstances1, compInstances2)); +// assertFalse(mockedComparator.compareComponentInstanceLists(compInstances2, compInstances1)); +// } +// +// @Test +// public void compareComponentInstanceLists() { +// ComponentInstance ci1 = new ComponentInstance(); +// ci1.setReference("comp1"); +// ComponentInstance ci2 = new ComponentInstance(); + // ci1.setId("comp2"); +// +// ModelComparator mockedComparator = spy(ModelComparator.class); +// doReturn(true).when(mockedComparator).compareComponentsInstances(ci1, ci1); +// doReturn(true).when(mockedComparator).compareComponentsInstances(ci2, ci2); +// +// List compInstances1 = new ArrayList<>(); +// compInstances1.add(ci1); +// compInstances1.add(ci2); +// +// List compInstances2 = new ArrayList<>(); +// compInstances2.add(ci2); +// compInstances2.add(ci1); +// +// assertTrue(mockedComparator.compareComponentInstanceLists(compInstances1, compInstances2)); +// assertTrue(mockedComparator.compareComponentInstanceLists(compInstances2, compInstances1)); +// } +// +// @Test +// public void compareServiceUnitInstanceListsWithDifferentSizes() { +// List suInstances1 = new ArrayList<>(); +// suInstances1.add(null); +// +// List suInstances2 = new ArrayList<>(); +// suInstances2.add(null); +// suInstances2.add(null); +// +// assertFalse(comparator.compareServiceUnitInstanceLists(suInstances1, suInstances2)); +// assertFalse(comparator.compareServiceUnitInstanceLists(suInstances2, suInstances1)); +// } +// +// @Test +// public void compareServiceUnitInstanceListsNotUnique() { +// ServiceUnit su1 = new ServiceUnit(); +// su1.setId("su1"); +// ServiceUnitInstance sui1 = new ServiceUnitInstance(); +// sui1.setReference(su1.getId()); +// ServiceUnit su2 = new ServiceUnit(); +// su2.setId("su2"); +// ServiceUnitInstance sui2 = new ServiceUnitInstance(); +// sui2.setReference(su2.getId()); +// +// ModelComparator mockedComparator = spy(ModelComparator.class); +// doReturn(false).when(mockedComparator).compareServiceUnitInstances(sui1, sui2); +// doReturn(false).when(mockedComparator).compareServiceUnitInstances(sui2, sui1); +// doReturn(true).when(mockedComparator).compareServiceUnitInstances(sui1, sui1); +// doReturn(true).when(mockedComparator).compareServiceUnitInstances(sui2, sui2); +// +// List suInstances1 = new ArrayList<>(); +// suInstances1.add(sui1); +// suInstances1.add(sui1); +// +// List suInstances2 = new ArrayList<>(); +// suInstances2.add(sui1); +// suInstances2.add(sui2); +// +// assertFalse(mockedComparator.compareServiceUnitInstanceLists(suInstances1, suInstances2)); +// assertFalse(mockedComparator.compareServiceUnitInstanceLists(suInstances2, suInstances1)); +// } +// +// @Test +// public void compareServiceUnitInstanceListsWithDifferentItems() { +// ServiceUnit su1 = new ServiceUnit(); +// su1.setId("su"); +// ServiceUnitInstance sui1 = new ServiceUnitInstance(); +// sui1.setReference(su1.getId()); +// +// ModelComparator mockedComparator = spy(ModelComparator.class); +// doReturn(false).when(mockedComparator).compareServiceUnitInstances(sui1, sui1); +// +// List suInstances1 = new ArrayList<>(); +// suInstances1.add(sui1); +// +// List suInstances2 = new ArrayList<>(); +// suInstances2.add(sui1); +// +// assertFalse(mockedComparator.compareServiceUnitInstanceLists(suInstances1, suInstances2)); +// assertFalse(mockedComparator.compareServiceUnitInstanceLists(suInstances2, suInstances1)); +// } +// +// @Test +// public void compareServiceUnitLists() { +// ServiceUnit su1 = new ServiceUnit(); +// su1.setId("su1"); +// ServiceUnitInstance sui1 = new ServiceUnitInstance(); +// sui1.setReference(su1.getId()); +// ServiceUnit su2 = new ServiceUnit(); +// su2.setId("su2"); +// ServiceUnitInstance sui2 = new ServiceUnitInstance(); +// sui2.setReference(su2.getId()); +// +// ModelComparator mockedComparator = spy(ModelComparator.class); +// doReturn(true).when(mockedComparator).compareServiceUnitInstances(sui1, sui1); +// doReturn(true).when(mockedComparator).compareServiceUnitInstances(sui2, sui2); +// +// List suInstances1 = new ArrayList<>(); +// suInstances1.add(sui1); +// suInstances1.add(sui2); +// +// List suInstances2 = new ArrayList<>(); +// suInstances2.add(sui2); +// suInstances2.add(sui1); +// +// assertTrue(mockedComparator.compareServiceUnitInstanceLists(suInstances1, suInstances2)); +// assertTrue(mockedComparator.compareServiceUnitInstanceLists(suInstances2, suInstances1)); +// } +// +// @Test +// public void compareModelsWithDifferentContainerInstances() { +// List containerInstances = new ArrayList(); +// containerInstances.add(null); +// TopologyInstance topoInst = new TopologyInstance(); +// topoInst.setContainerInstances(containerInstances); +// Bus bus = new Bus(); +// bus.setTopologyInstance(topoInst); +// List buses = new ArrayList(); +// buses.add(bus); +// BusModel busModel = new BusModel(); +// busModel.setBuses(buses); +// Model model = new Model(); +// model.setBusModel(busModel); +// +// ModelComparator mockedComparator = spy(ModelComparator.class); +// doReturn(false).when(mockedComparator).compareContainerInstances(null, null); +// doReturn(true).when(mockedComparator).compareServiceUnitInstanceLists(null, null); +// doReturn(true).when(mockedComparator).compareComponentInstanceLists(null, null); +// +// assertFalse(mockedComparator.compareModels(model, model)); +// } +// +// @Test +// public void compareModelsWithDifferentServiceUnitInstanceLists() { +// List containerInstances = new ArrayList(); +// containerInstances.add(null); +// TopologyInstance topoInst = new TopologyInstance(); +// topoInst.setContainerInstances(containerInstances); +// Bus bus = new Bus(); +// bus.setTopologyInstance(topoInst); +// List buses = new ArrayList(); +// buses.add(bus); +// BusModel busModel = new BusModel(); +// busModel.setBuses(buses); +// Model model = new Model(); +// model.setBusModel(busModel); +// +// ModelComparator mockedComparator = spy(ModelComparator.class); +// doReturn(true).when(mockedComparator).compareContainerInstances(null, null); +// doReturn(false).when(mockedComparator).compareServiceUnitInstanceLists(null, null); +// doReturn(true).when(mockedComparator).compareComponentInstanceLists(null, null); +// +// assertFalse(mockedComparator.compareModels(model, model)); +// } +// +// @Test +// public void compareModelsWithDifferentComponentInstanceLists() { +// List containerInstances = new ArrayList(); +// containerInstances.add(null); +// TopologyInstance topoInst = new TopologyInstance(); +// topoInst.setContainerInstances(containerInstances); +// Bus bus = new Bus(); +// bus.setTopologyInstance(topoInst); +// List buses = new ArrayList(); +// buses.add(bus); +// BusModel busModel = new BusModel(); +// busModel.setBuses(buses); +// Model model = new Model(); +// model.setBusModel(busModel); +// +// ModelComparator mockedComparator = spy(ModelComparator.class); +// doReturn(true).when(mockedComparator).compareContainerInstances(null, null); +// doReturn(true).when(mockedComparator).compareServiceUnitInstanceLists(null, null); +// doReturn(false).when(mockedComparator).compareComponentInstanceLists(null, null); +// +// assertFalse(mockedComparator.compareModels(model, model)); +// } +} diff --git a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java new file mode 100644 index 0000000..9b932fa --- /dev/null +++ b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java @@ -0,0 +1,123 @@ +/** + * Copyright (c) 2018-2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.utils; + +import static org.junit.Assert.assertTrue; + +import java.util.HashMap; +import java.util.Map; +import java.util.logging.ConsoleHandler; +import java.util.logging.Formatter; +import java.util.logging.Handler; +import java.util.logging.Level; +import java.util.logging.LogRecord; +import java.util.logging.Logger; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.ow2.petals.admin.junit.ArtifactLifecycleFactoryMock; +import org.ow2.petals.admin.junit.PetalsAdministrationApi; +import org.ow2.petals.admin.topology.Container.PortType; +import org.ow2.petals.admin.topology.Container.State; +import org.ow2.petals.deployer.runtimemodel.RuntimeComponent; +import org.ow2.petals.deployer.runtimemodel.RuntimeContainer; +import org.ow2.petals.deployer.runtimemodel.RuntimeModel; +import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit; +import org.ow2.petals.jbi.descriptor.original.JBIDescriptorBuilder; + +public class RuntimeModelDeployerTest { + final public static String CONTAINER_NAME = "sample-0"; + + final public static String CONTAINER_HOST = "localhost"; + + final public static int CONTAINER_JMX_PORT = 7700; + + final public static String CONTAINER_USER = "petals"; + + final public static String CONTAINER_PWD = "petals"; + + final public static State CONTAINER_STATE = State.REACHABLE; + + @Rule + public PetalsAdministrationApi petalsAdminApiRule = new PetalsAdministrationApi(); + + @Before + public void setupLogger() throws Exception { + Logger deployerLogger = Logger.getLogger(RuntimeModelDeployer.class.getName()); + deployerLogger.setLevel(Level.FINER); + Logger comparatorLogger = Logger.getLogger(RuntimeModelComparator.class.getName()); + comparatorLogger.setLevel(Level.FINER); + Handler consoleHandler = new ConsoleHandler(); + consoleHandler.setLevel(Level.FINER); + Formatter formatter = new Formatter() { + @Override + public String format(LogRecord record) { + return record.getMessage() + "\n"; + } + }; + consoleHandler.setFormatter(formatter); + deployerLogger.addHandler(consoleHandler); + comparatorLogger.addHandler(consoleHandler); + } + + @Test + public void demoSoap() throws Exception { + RuntimeModel model = new RuntimeModel(); + initializeRuntimeModel(model); + + petalsAdminApiRule.registerDomain(); + org.ow2.petals.admin.topology.Container cont = createContainerSample(); + petalsAdminApiRule.registerContainer(cont); + ArtifactLifecycleFactoryMock artifactLifecycleFactoryMock = new ArtifactLifecycleFactoryMock(cont); + RuntimeModelDeployer modelDeployer = new RuntimeModelDeployer(petalsAdminApiRule.getSingleton(), artifactLifecycleFactoryMock, + JBIDescriptorBuilder.getInstance()); + modelDeployer.deployRuntimeModel(model); + + RuntimeModelExporter modelExporter = new RuntimeModelExporter(); + RuntimeModel exportedModel = modelExporter.exportRuntimeModel(CONTAINER_HOST, CONTAINER_JMX_PORT, + CONTAINER_USER, CONTAINER_PWD); + + RuntimeModelComparator modelComparator = new RuntimeModelComparator(); + assertTrue(modelComparator.compareRuntimeModels(model, exportedModel)); + } + + private org.ow2.petals.admin.topology.Container createContainerSample() { + final Map ports = new HashMap<>(); + ports.put(PortType.JMX, CONTAINER_JMX_PORT); + return new org.ow2.petals.admin.topology.Container(CONTAINER_NAME, CONTAINER_HOST, ports, CONTAINER_USER, + CONTAINER_PWD, CONTAINER_STATE); + } + + private void initializeRuntimeModel(RuntimeModel model) throws Exception { + + RuntimeContainer cont = new RuntimeContainer(CONTAINER_NAME, CONTAINER_JMX_PORT, CONTAINER_USER, CONTAINER_PWD, + "localhost"); + cont.addComponent(new RuntimeComponent("petals-bc-soap", + ZipUtils.createZipFromResourceDirectory("artifacts/petals-bc-soap-5.0.0").toURI().toURL())); + cont.addServiceUnit(new RuntimeServiceUnit("su-SOAP-Hello_Service1-provide", + ZipUtils.createZipFromResourceDirectory("artifacts/sa-SOAP-Hello_Service1-provide").toURI().toURL())); + cont.addServiceUnit(new RuntimeServiceUnit("su-SOAP-Hello_Service2-provide", + ZipUtils.createZipFromResourceDirectory("artifacts/sa-SOAP-Hello_Service2-provide").toURI().toURL())); + cont.addServiceUnit(new RuntimeServiceUnit("su-SOAP-Hello_PortType-consume", + ZipUtils.createZipFromResourceDirectory("artifacts/sa-SOAP-Hello_PortType-consume").toURI().toURL())); + + model.addContainer(cont); + } +} diff --git a/src/test/java/org/ow2/petals/deployer/utils/ZipUtils.java b/src/test/java/org/ow2/petals/deployer/utils/ZipUtils.java new file mode 100644 index 0000000..a1c44cb --- /dev/null +++ b/src/test/java/org/ow2/petals/deployer/utils/ZipUtils.java @@ -0,0 +1,71 @@ +/** + * Copyright (c) 2018-2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + + */ +package org.ow2.petals.deployer.utils; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +public class ZipUtils { + private static final int DEFAULT_BUFFER_SIZE = 1024; + + /** + * Return a zip archive of a directory (the directory is considered the root of the archive). + * + * The created zip archive is a temporary file. + * + * @param resourcePath + * The path to the directory in resources + * @return The zip file created + * @throws IOException + * @throws URISyntaxException + */ + public static File createZipFromResourceDirectory(String resourcePath) throws IOException, URISyntaxException { + File zip = Files.createTempFile(null, null).toFile(); + File resource = new File(Thread.currentThread().getContextClassLoader().getResource(resourcePath).toURI()); + ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zip)); + for (File file : resource.listFiles()) { + addDirectoryToZip("", file, zos); + } + zos.close(); + return zip; + } + + private static void addDirectoryToZip(String prefix, File file, ZipOutputStream zos) throws IOException { + if (file.isDirectory()) { + for (File child : file.listFiles()) { + addDirectoryToZip(prefix + file.getName() + "/", child, zos); + } + } else { + zos.putNextEntry(new ZipEntry(prefix + file.getName())); + FileInputStream fis = new FileInputStream(file); + byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; + while (fis.available() > 0) { + int read = fis.read(buffer, 0, buffer.length); + zos.write(buffer, 0, read); + } + fis.close(); + } + } +} diff --git a/src/test/resources/artifacts/petals-bc-soap-5.0.0/META-INF/jbi.xml b/src/test/resources/artifacts/petals-bc-soap-5.0.0/META-INF/jbi.xml new file mode 100644 index 0000000..3bdaf6a --- /dev/null +++ b/src/test/resources/artifacts/petals-bc-soap-5.0.0/META-INF/jbi.xml @@ -0,0 +1,217 @@ + + + + + + petals-bc-soap + The PEtALS SOAP JBI binding component based on Axis2 and Jetty. + + org.ow2.petals.binding.soap.SoapComponent + + velocity-1.5.jar + axis2-mtompolicy-1.7.7.jar + xml-resolver-1.2.jar + easycommons-stream-1.4.0.jar + serializer-2.7.1.jar + jcip-annotations-1.0.jar + jetty-servlet-9.4.11.v20180605.jar + commons-httpclient-3.1.jar + petals-cdk-steplog-1.1.1.jar + esapi-2.0GA.jar + petals-bc-soap-5.0.0.jar + woodstox-core-asl-4.2.0.jar + httpclient-4.5.2.jar + petals-cdk-api-2.6.1.jar + commons-lang-2.1.jar + rampart-core-1.7.1.jar + xalan-2.7.1.jar + petals-probes-api-1.3.0.jar + wsdl4j-1.6.2.jar + jaxb2-basics-runtime-0.11.1.jar + axis2-transport-jms-1.7.7.jar + easycommons-util-2.5.0.jar + bcprov-jdk15on-1.59.jar + javax.servlet-api-3.1.0.jar + jetty-security-9.4.11.v20180605.jar + mex-1.7.6-impl.jar + wss4j-1.6.16.jar + axiom-impl-1.2.20.jar + geronimo-jms_1.1_spec-1.1.jar + petals-probes-1.3.0.jar + easywsdl-ext-wsdl4complexwsdl-2.7.0.jar + easywsdl-wsdl-2.7.0.jar + jetty-server-9.4.11.v20180605.jar + rampart-trust-1.7.1.jar + petals-cdk-core-5.7.1.jar + jetty-io-9.4.11.v20180605.jar + addressing-1.7.7.mar + commons-codec-1.9.jar + stax2-api-3.1.1.jar + commons-fileupload-1.3.3.jar + xmltooling-1.3.2-1.jar + rampart-1.7.1.mar + petals-cdk-jbidescriptor-2.6.1.jar + axiom-dom-1.2.20.jar + opensaml-2.5.1-1.jar + xmlschema-core-2.2.1.jar + woden-core-1.0M10.jar + commons-collections-3.1.jar + rampart-policy-1.7.1.jar + jaxb-impl-2.2.11.jar + easywsdl-schema-2.7.0.jar + openws-1.4.2-1.jar + petals-cdk-clientserver-api-1.2.1.jar + axiom-api-1.2.20.jar + geronimo-jta_1.1_spec-1.1.jar + petals-bc-soap-clientserver-api-1.2.0.jar + jetty-http-9.4.11.v20180605.jar + axis2-transport-base-1.7.7.jar + petals-jbi-descriptor-2.4.0.jar + axis2-kernel-1.7.7.jar + apache-mime4j-core-0.7.2.jar + neethi-3.0.3.jar + jaxen-1.1.6.jar + petals-basis-api-1.1.0.jar + axis2-transport-http-1.7.7.jar + joda-time-1.6.2.jar + jaxb-core-2.2.11.jar + xmlunit-1.6.jar + jsr311-api-1.1.1.jar + xmlsec-1.5.8.jar + commons-io-2.6.jar + jetty-util-9.4.11.v20180605.jar + javax.mail-1.5.6.jar + commons-httpclient-contrib-3.1.jar + httpcore-4.4.4.jar + + org.ow2.petals.binding.soap.SoapBootstrap + + velocity-1.5.jar + axis2-mtompolicy-1.7.7.jar + xml-resolver-1.2.jar + easycommons-stream-1.4.0.jar + serializer-2.7.1.jar + jcip-annotations-1.0.jar + jetty-servlet-9.4.11.v20180605.jar + commons-httpclient-3.1.jar + petals-cdk-steplog-1.1.1.jar + esapi-2.0GA.jar + petals-bc-soap-5.0.0.jar + woodstox-core-asl-4.2.0.jar + httpclient-4.5.2.jar + petals-cdk-api-2.6.1.jar + commons-lang-2.1.jar + rampart-core-1.7.1.jar + xalan-2.7.1.jar + petals-probes-api-1.3.0.jar + wsdl4j-1.6.2.jar + jaxb2-basics-runtime-0.11.1.jar + axis2-transport-jms-1.7.7.jar + easycommons-util-2.5.0.jar + bcprov-jdk15on-1.59.jar + javax.servlet-api-3.1.0.jar + jetty-security-9.4.11.v20180605.jar + mex-1.7.6-impl.jar + wss4j-1.6.16.jar + axiom-impl-1.2.20.jar + geronimo-jms_1.1_spec-1.1.jar + petals-probes-1.3.0.jar + easywsdl-ext-wsdl4complexwsdl-2.7.0.jar + easywsdl-wsdl-2.7.0.jar + jetty-server-9.4.11.v20180605.jar + rampart-trust-1.7.1.jar + petals-cdk-core-5.7.1.jar + jetty-io-9.4.11.v20180605.jar + addressing-1.7.7.mar + commons-codec-1.9.jar + stax2-api-3.1.1.jar + commons-fileupload-1.3.3.jar + xmltooling-1.3.2-1.jar + rampart-1.7.1.mar + petals-cdk-jbidescriptor-2.6.1.jar + axiom-dom-1.2.20.jar + opensaml-2.5.1-1.jar + xmlschema-core-2.2.1.jar + woden-core-1.0M10.jar + commons-collections-3.1.jar + rampart-policy-1.7.1.jar + jaxb-impl-2.2.11.jar + easywsdl-schema-2.7.0.jar + openws-1.4.2-1.jar + petals-cdk-clientserver-api-1.2.1.jar + axiom-api-1.2.20.jar + geronimo-jta_1.1_spec-1.1.jar + petals-bc-soap-clientserver-api-1.2.0.jar + jetty-http-9.4.11.v20180605.jar + axis2-transport-base-1.7.7.jar + petals-jbi-descriptor-2.4.0.jar + axis2-kernel-1.7.7.jar + apache-mime4j-core-0.7.2.jar + neethi-3.0.3.jar + jaxen-1.1.6.jar + petals-basis-api-1.1.0.jar + axis2-transport-http-1.7.7.jar + joda-time-1.6.2.jar + jaxb-core-2.2.11.jar + xmlunit-1.6.jar + jsr311-api-1.1.1.jar + xmlsec-1.5.8.jar + commons-io-2.6.jar + jetty-util-9.4.11.v20180605.jar + javax.mail-1.5.6.jar + commons-httpclient-contrib-3.1.jar + httpcore-4.4.4.jar + + + + + + + + + + + + + org.ow2.petals.binding.soap.listener.outgoing.JBIListener + 8084 + + true + petals + services + 2 + 50 + 4 + 50 + + false + 8083 + + + + + + + + + 4 + 50 + true + + diff --git a/src/test/resources/artifacts/sa-SOAP-Hello_PortType-consume/META-INF/jbi.xml b/src/test/resources/artifacts/sa-SOAP-Hello_PortType-consume/META-INF/jbi.xml new file mode 100644 index 0000000..32d540d --- /dev/null +++ b/src/test/resources/artifacts/sa-SOAP-Hello_PortType-consume/META-INF/jbi.xml @@ -0,0 +1,40 @@ + + + + + + + sa-SOAP-Hello_PortType-consume + + + + + + + su-SOAP-Hello_PortType-consume + + + + + su-SOAP-Hello_PortType-consume.zip + petals-bc-soap + + + + \ No newline at end of file diff --git a/src/test/resources/artifacts/sa-SOAP-Hello_Service1-provide/META-INF/jbi.xml b/src/test/resources/artifacts/sa-SOAP-Hello_Service1-provide/META-INF/jbi.xml new file mode 100644 index 0000000..61c8e1c --- /dev/null +++ b/src/test/resources/artifacts/sa-SOAP-Hello_Service1-provide/META-INF/jbi.xml @@ -0,0 +1,40 @@ + + + + + + + sa-SOAP-Hello_Service1-provide + + + + + + + su-SOAP-Hello_Service1-provide + + + + + su-SOAP-Hello_Service1-provide.zip + petals-bc-soap + + + + \ No newline at end of file diff --git a/src/test/resources/artifacts/sa-SOAP-Hello_Service2-provide/META-INF/jbi.xml b/src/test/resources/artifacts/sa-SOAP-Hello_Service2-provide/META-INF/jbi.xml new file mode 100644 index 0000000..53ffa5d --- /dev/null +++ b/src/test/resources/artifacts/sa-SOAP-Hello_Service2-provide/META-INF/jbi.xml @@ -0,0 +1,40 @@ + + + + + + + sa-SOAP-Hello_Service2-provide + + + + + + + su-SOAP-Hello_Service2-provide + + + + + su-SOAP-Hello_Service2-provide.zip + petals-bc-soap + + + + \ No newline at end of file From 90dbc177f863d8b960342b8d59b7eb82d1cd96b8 Mon Sep 17 00:00:00 2001 From: Alexandre Lagane Date: Mon, 14 Jan 2019 16:26:22 +0100 Subject: [PATCH 03/21] Happy little path working --- model.xml | 37 ++++++++ .../petals/deployer/utils/ModelDeployer.java | 88 +++++++++++++++++++ .../utils/ModelDeployerException.java | 32 +++++++ .../deployer/utils/RuntimeModelDeployer.java | 6 +- .../petals/deployer/utils/ParseModelTest.java | 2 + 5 files changed, 163 insertions(+), 2 deletions(-) create mode 100644 model.xml create mode 100644 src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java create mode 100644 src/main/java/org/ow2/petals/deployer/utils/ModelDeployerException.java diff --git a/model.xml b/model.xml new file mode 100644 index 0000000..e1d7018 --- /dev/null +++ b/model.xml @@ -0,0 +1,37 @@ + + + + + file:/tmp/1171719596447134413.tmp + + + file:/tmp/6122774382465243477.tmp + + + file:/tmp/9130855944618382075.tmp + + + + + file:/tmp/7682173910493042333.tmp + + + + + + + + + + localhost + + + + + + + + + + + diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java new file mode 100644 index 0000000..415c289 --- /dev/null +++ b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java @@ -0,0 +1,88 @@ +/** + * Copyright (c) 2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.utils; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.nio.file.Files; +import java.util.logging.Logger; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import javax.xml.transform.stream.StreamSource; + +import org.apache.commons.io.FileUtils; +import org.ow2.petals.admin.api.exception.ArtifactAdministrationException; +import org.ow2.petals.admin.api.exception.ContainerAdministrationException; +import org.ow2.petals.admin.api.exception.DuplicatedServiceException; +import org.ow2.petals.admin.api.exception.MissingServiceException; +import org.ow2.petals.deployer.model.xml._1.Model; +import org.ow2.petals.deployer.runtimemodel.RuntimeModel; +import org.ow2.petals.deployer.runtimemodel.RuntimeModel.RuntimeModelException; +import org.ow2.petals.jbi.descriptor.JBIDescriptorException; + +public class ModelDeployer { + + /** + * Connection timeout in milliseconds to get model or artifacts from URL. + */ + public static final int CONNECTION_TIMEOUT = 5000; + + /** + * Read timeout in milliseconds to read model or artifacts from URL. + */ + public static final int READ_TIMEOUT = 5000; + + private static final Logger LOG = Logger.getLogger(ModelDeployer.class.getName()); + + public static void deployModel(URL url) throws ModelDeployerException { + File modelFile; + try { + LOG.fine("Downloadind XML model"); + + modelFile = Files.createTempFile("model", ".xml").toFile(); + FileUtils.copyURLToFile(url, modelFile, CONNECTION_TIMEOUT, READ_TIMEOUT); + + LOG.fine("Parsing XML model"); + + JAXBContext jaxbContext = JAXBContext.newInstance(Model.class); + + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + Model model = unmarshaller.unmarshal(new StreamSource(modelFile), Model.class).getValue(); + + ModelConverter converter = new ModelConverter(); + + RuntimeModel runtimeModel; + runtimeModel = converter.convertModelToRuntimeModel(model); + + RuntimeModelDeployer deployer; + deployer = new RuntimeModelDeployer(); + + deployer.deployRuntimeModel(runtimeModel); + + } catch (JAXBException | IOException | RuntimeModelException | DuplicatedServiceException + | MissingServiceException | JBIDescriptorException | ContainerAdministrationException + | ArtifactAdministrationException | RuntimeModelDeployerException e) { + throw new ModelDeployerException(e); + } + } +} diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployerException.java b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployerException.java new file mode 100644 index 0000000..aef8710 --- /dev/null +++ b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployerException.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.utils; + +public class ModelDeployerException extends Exception { + + private static final long serialVersionUID = 7599724111843987402L; + + public ModelDeployerException(final Throwable cause) { + super(cause); + } + + public ModelDeployerException(final String message) { + super(message); + } +} diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java index f981819..37193c1 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java @@ -106,7 +106,8 @@ private void deployRuntimeServiceUnit(RuntimeServiceUnit serviceUnit, RuntimeMod ArtifactNotFoundException, ArtifactAdministrationException, RuntimeModelDeployerException { String suId = serviceUnit.getId(); File suFile = Files.createTempFile(suId, ".zip").toFile(); - FileUtils.copyURLToFile(serviceUnit.getUrl(), suFile); + FileUtils.copyURLToFile(serviceUnit.getUrl(), suFile, ModelDeployer.CONNECTION_TIMEOUT, + ModelDeployer.READ_TIMEOUT); Jbi jbi = jdb.buildJavaJBIDescriptorFromArchive(suFile); ServiceAssembly jbiSa = jbi.getServiceAssembly(); @@ -144,7 +145,8 @@ private void deployRuntimeComponent(RuntimeComponent component) throws IOException, JBIDescriptorException, ArtifactDeployedException, ArtifactAdministrationException { String compId = component.getId(); File compFile = Files.createTempFile(compId, "zip").toFile(); - FileUtils.copyURLToFile(component.getUrl(), compFile); + FileUtils.copyURLToFile(component.getUrl(), compFile, ModelDeployer.CONNECTION_TIMEOUT, + ModelDeployer.READ_TIMEOUT); Jbi jbi = jdb.buildJavaJBIDescriptorFromArchive(compFile); LOG.fine("Deploying component " + component.getId()); diff --git a/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java b/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java index 157da52..ffb1399 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java @@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals; +import java.io.File; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; @@ -81,6 +82,7 @@ public void read() throws Exception { marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(of.createModel(model), marshalledModelWriter); + marshaller.marshal(of.createModel(model), new File("model.xml")); Model unmarshalledModel = unmarshaller .unmarshal(new StreamSource(new StringReader(marshalledModelWriter.toString())), Model.class) From d7158a1eea5bcf5310615e60dc5788a451fee82e Mon Sep 17 00:00:00 2001 From: Alexandre Lagane Date: Mon, 14 Jan 2019 17:36:51 +0100 Subject: [PATCH 04/21] Add some converter tests --- model.xml | 8 +- .../petals/deployer/utils/ModelConverter.java | 1 - .../utils/ModelValidationException.java | 27 - .../petals/deployer/utils/ModelValidator.java | 51 -- .../utils/RuntimeModelComparator.java | 126 ---- .../deployer/utils/RuntimeModelExporter.java | 1 - .../deployer/utils/ModelConverterTest.java | 74 ++ .../petals/deployer/utils/ParseModelTest.java | 14 +- .../utils/RuntimeModelComparatorTest.java | 638 ------------------ 9 files changed, 83 insertions(+), 857 deletions(-) delete mode 100644 src/main/java/org/ow2/petals/deployer/utils/ModelValidationException.java delete mode 100644 src/main/java/org/ow2/petals/deployer/utils/ModelValidator.java create mode 100644 src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java delete mode 100644 src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java diff --git a/model.xml b/model.xml index e1d7018..1cd8cc1 100644 --- a/model.xml +++ b/model.xml @@ -2,18 +2,18 @@ - file:/tmp/1171719596447134413.tmp + file:/artifacts/sa-SOAP-Hello_Service1-provide - file:/tmp/6122774382465243477.tmp + file:/artifacts/sa-SOAP-Hello_Service2-provide - file:/tmp/9130855944618382075.tmp + file:/artifacts/sa-SOAP-Hello_PortType-consume - file:/tmp/7682173910493042333.tmp + file:/artifacts/petals-bc-soap-5.0.0 diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java b/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java index ef8ea47..51d163f 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java +++ b/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java @@ -83,7 +83,6 @@ public RuntimeModel convertModelToRuntimeModel(Model model) throws MalformedURLE } ServiceUnitModel suModel = model.getServiceUnitModel(); - Map suById = new HashMap(); for (ServiceUnit su : suModel.getServiceUnit()) { suById.put(su.getId(), su); diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelValidationException.java b/src/main/java/org/ow2/petals/deployer/utils/ModelValidationException.java deleted file mode 100644 index f9b4ccf..0000000 --- a/src/main/java/org/ow2/petals/deployer/utils/ModelValidationException.java +++ /dev/null @@ -1,27 +0,0 @@ -/** - * Copyright (c) 2018-2019 Linagora - * - * This program/library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 2.1 of the License, or (at your - * option) any later version. - * - * This program/library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program/library; If not, see http://www.gnu.org/licenses/ - * for the GNU Lesser General Public License version 2.1. - */ - -package org.ow2.petals.deployer.utils; - -public class ModelValidationException extends Exception { - private static final long serialVersionUID = 5871650877543503924L; - - public ModelValidationException(String message) { - super(message); - } -} diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelValidator.java b/src/main/java/org/ow2/petals/deployer/utils/ModelValidator.java deleted file mode 100644 index 1fde404..0000000 --- a/src/main/java/org/ow2/petals/deployer/utils/ModelValidator.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Copyright (c) 2018-2019 Linagora - * - * This program/library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 2.1 of the License, or (at your - * option) any later version. - * - * This program/library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program/library; If not, see http://www.gnu.org/licenses/ - * for the GNU Lesser General Public License version 2.1. - */ - -package org.ow2.petals.deployer.utils; - -public class ModelValidator { - - // public void validateServiceUnitModel(ServiceUnitModel model) throws ModelValidationException { - // - // List sus = model.getServiceUnits(); - // if (sus.size() < 1) { - // throw new ModelValidationException("ServiceUnitModel must have 1 ServiceUnit minimum"); - // } - // - // HashSet suIds = new HashSet(); - // Map placeholders = new HashMap(); - // for (ServiceUnit su : sus) { - // for (Map.Entry suPh : su.getPlaceholders().entrySet()) { - // if (placeholders.containsKey(suPh.getKey())) { - // String phDefaultValue = placeholders.get(suPh.getKey()); - // if (suPh.getValue() == null && phDefaultValue != null - // || suPh.getValue() != null && !suPh.getValue().equals(phDefaultValue)) { - // throw new ModelValidationException("Placeholder with key " + suPh.getKey() - // + " is used on different ServiceUnit but its defaultValue differs."); - // } - // } else { - // placeholders.put(suPh.getKey(), suPh.getValue()); - // } - // - // } - // if (!suIds.add(su.getId())) { - // throw new ModelValidationException("ServiceUnit id " + su.getId() + " is not unique"); - // } - // } - // } -} diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java index ddee0eb..436785c 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java @@ -104,130 +104,4 @@ private boolean compareRuntimeServiceUnits(RuntimeServiceUnit su1, RuntimeServic private boolean compareRuntimeComponents(RuntimeComponent comp1, RuntimeComponent comp2) { return comp1.getId().equals(comp2.getId()); } - -// public boolean compareModels(final Model m1, final Model m2) { -// Bus bus1 = m1.getBusModel().getBuses().get(0); -// Bus bus2 = m2.getBusModel().getBuses().get(0); -// ContainerInstance contInst1 = bus1.getTopologyInstance().getContainerInstances().get(0); -// ContainerInstance contInst2 = bus2.getTopologyInstance().getContainerInstances().get(0); -// -// if (!compareContainerInstances(contInst1, contInst2)) { -// return false; -// } -// -// return true; -// } -// -// public boolean compareServiceUnitInstanceLists(final List suInstances1, -// final List suInstances2) { -// -// if (suInstances1.size() != suInstances2.size()) { -// return false; -// } -// -// // Check unicity and build map of suInstances1 -// Map suInstById1 = new HashMap(); -// for (ServiceUnitInstance suInst : suInstances1) { -// String suId = suInst.getReference(); -// if (suInstById1.containsKey(suId)) { -// return false; -// } -// suInstById1.put(suId, suInst); -// } -// -// // Check unicity of suInstances2 and compare its elements with suInstances1 -// Set suInstIds = new HashSet(); -// for (ServiceUnitInstance suInst : suInstances2) { -// String suId = suInst.getReference(); -// if (!suInstIds.add(suId) || !compareServiceUnitInstances(suInst, suInstById1.get(suId))) { -// return false; -// } -// } -// -// return true; -// } -// -// public boolean compareComponentInstanceLists(final List compInstances1, -// final List compInstances2) { -// -// if (compInstances1.size() != compInstances2.size()) { -// return false; -// } -// -// // Check unicity and build map of compInstances1 -// Map compInstById1 = new HashMap(); -// for (ComponentInstance compInst : compInstances1) { -// String compInstId = compInst.getReference(); -// if (compInstById1.containsKey(compInstId)) { -// return false; -// } -// compInstById1.put(compInstId, compInst); -// } -// -// // Check unicity of compInstances2 and compare its elements with compInstances1 -// Set compInstIds = new HashSet(); -// for (ComponentInstance compInst : compInstances2) { -// String compInstId = compInst.getReference(); -// if (!compInstIds.add(compInstId) || !compareComponentsInstances(compInst, compInstById1.get(compInstId))) { -// return false; -// } -// } -// -// return true; -// } -// -// /** -// * m1 and m2 must be both instances of {@link ProvisionedMachine} -// * -// * @param m1 -// * @param m2 -// * @return false if m1 and m2 are different -// */ -// public boolean compareMachines(Machine m1, Machine m2) { -// return m1 instanceof ProvisionedMachine && m2 instanceof ProvisionedMachine -// && ((ProvisionedMachine) m1).getHostname().equals(((ProvisionedMachine) m2).getHostname()); -// } -// -// /** -// * We only compare container instances, their getters will fetch data from their reference {@link Container}. -// * -// * @param ci1 -// * @param ci2 -// * @return false if ci1 and ci2 are different -// */ -// public boolean compareContainerInstances(final ContainerInstance ci1, final ContainerInstance ci2) { -// return ci1.getReference().equals(ci2.getReference()) && ci1.getJmxUser().equals(ci2.getJmxUser()) -// && ci1.getJmxPort().equals(ci2.getJmxPort()) && ci1.getJmxPassword().equals(ci2.getJmxPassword()) -// && compareServiceUnitInstanceLists(ci1.getServiceUnitInstances(), ci2.getServiceUnitInstances()) -// && compareComponentInstanceLists(ci1.getComponentInstances(), ci2.getComponentInstances()); -// } -// -// public boolean compareServiceUnitInstances(final ServiceUnitInstance sui1, final ServiceUnitInstance sui2) { -// return sui1.getContainerInstanceReference().equals(sui2.getContainerInstanceReference()) -// && sui1.getReference().equals(sui2.getReference()); -// } -// -// /** -// * @param su1 -// * @param su2 -// * @return false if su1 and su2 are different -// */ -// public boolean compareServiceUnits(final ServiceUnit su1, final ServiceUnit su2) { -// return su1.getId().equals(su2.getId()) && su1.getTargetComponent().equals(su2.getTargetComponent()); -// } -// -// public boolean compareComponentsInstances(final ComponentInstance ci1, final ComponentInstance ci2) { -// return ci1.getReference().equals(ci2.getReference()) && ci1.getReference().equals(ci2.getReference()); -// } -// -// /** -// * The urls are not compared, because we cannot set them when exporting model from a running Petals. -// * -// * @param c1 -// * @param c2 -// * @return false if c1 and c2 are different -// */ -// public boolean compareComponents(final Component c1, final Component c2) { -// return c1.getId().equals(c2.getId()); -// } } diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java index 833db98..532d2dd 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java @@ -77,7 +77,6 @@ public RuntimeModel exportRuntimeModel(final String hostname, final int port, fi case "SU": cont.addServiceUnit(new RuntimeServiceUnit( ((org.ow2.petals.admin.api.artifact.ServiceUnit) artifact).getName())); - // TODO what about targetComponent break; case "SA": // already get service units in "SU" case diff --git a/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java b/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java new file mode 100644 index 0000000..aa4b4fa --- /dev/null +++ b/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java @@ -0,0 +1,74 @@ +/** + * Copyright (c) 2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.utils; + +import static org.junit.Assert.assertEquals; + +import java.util.Collection; + +import org.junit.Test; +import org.ow2.petals.deployer.model.xml._1.Model; +import org.ow2.petals.deployer.runtimemodel.RuntimeComponent; +import org.ow2.petals.deployer.runtimemodel.RuntimeContainer; +import org.ow2.petals.deployer.runtimemodel.RuntimeModel; +import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit; + +public class ModelConverterTest { + + @Test + public void convertModelToRuntimeModel() throws Exception { + Model model = ParseModelTest.generateTestModel(); + + ModelConverter converter = new ModelConverter(); + RuntimeModel runtimeModel = converter.convertModelToRuntimeModel(model); + + Collection containers = runtimeModel.getContainers(); + assertEquals(1, containers.size()); + + RuntimeContainer cont = containers.iterator().next(); + assertEquals(ParseModelTest.CONTAINER_NAME, cont.getId()); + assertEquals(ParseModelTest.CONTAINER_HOST, cont.getHostname()); + assertEquals(ParseModelTest.CONTAINER_JMX_PORT, cont.getPort()); + assertEquals(ParseModelTest.CONTAINER_USER, cont.getUser()); + assertEquals(ParseModelTest.CONTAINER_PWD, cont.getPassword()); + + Collection serviceUnits = cont.getServiceUnits(); + assertEquals(3, serviceUnits.size()); + + RuntimeServiceUnit su = cont.getServiceUnit("su-SOAP-Hello_Service1-provide"); + assertEquals("su-SOAP-Hello_Service1-provide", su.getId()); + assertEquals("file:/artifacts/sa-SOAP-Hello_Service1-provide", su.getUrl().toString()); + + su = cont.getServiceUnit("su-SOAP-Hello_Service2-provide"); + assertEquals("su-SOAP-Hello_Service2-provide", su.getId()); + assertEquals("file:/artifacts/sa-SOAP-Hello_Service2-provide", su.getUrl().toString()); + + su = cont.getServiceUnit("su-SOAP-Hello_PortType-consume"); + assertEquals("su-SOAP-Hello_PortType-consume", su.getId()); + assertEquals("file:/artifacts/sa-SOAP-Hello_PortType-consume", su.getUrl().toString()); + + Collection components = cont.getComponents(); + assertEquals(1, components.size()); + + RuntimeComponent comp = cont.getComponent("petals-bc-soap"); + assertEquals("petals-bc-soap", comp.getId()); + assertEquals("file:/artifacts/petals-bc-soap-5.0.0", comp.getUrl().toString()); + } + +} diff --git a/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java b/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java index ffb1399..b2ec0cc 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java @@ -92,7 +92,7 @@ public void read() throws Exception { assertEquals(marshalledModelWriter.toString(), unmarshalledModelWriter.toString()); } - + public static Model generateTestModel() throws MalformedURLException, IOException, URISyntaxException { Model model = new Model(); @@ -103,8 +103,7 @@ public static Model generateTestModel() throws MalformedURLException, IOExceptio Component bcSoap = new Component(); bcSoap.setId("petals-bc-soap"); - bcSoap.setUrl( - ZipUtils.createZipFromResourceDirectory("artifacts/petals-bc-soap-5.0.0").toURI().toURL().toString()); + bcSoap.setUrl("file:/artifacts/petals-bc-soap-5.0.0"); compRepo.getComponent().add(bcSoap); /* Service Unit Model */ @@ -116,20 +115,17 @@ public static Model generateTestModel() throws MalformedURLException, IOExceptio ServiceUnit suProv1 = new ServiceUnit(); suProv1.setId("su-SOAP-Hello_Service1-provide"); - suProv1.setUrl(ZipUtils.createZipFromResourceDirectory("artifacts/sa-SOAP-Hello_Service1-provide").toURI() - .toURL().toString()); + suProv1.setUrl("file:/artifacts/sa-SOAP-Hello_Service1-provide"); serviceUnits.add(suProv1); ServiceUnit suProv2 = new ServiceUnit(); suProv2.setId("su-SOAP-Hello_Service2-provide"); - suProv2.setUrl(ZipUtils.createZipFromResourceDirectory("artifacts/sa-SOAP-Hello_Service2-provide").toURI() - .toURL().toString()); + suProv2.setUrl("file:/artifacts/sa-SOAP-Hello_Service2-provide"); serviceUnits.add(suProv2); ServiceUnit suCons = new ServiceUnit(); suCons.setId("su-SOAP-Hello_PortType-consume"); - suCons.setUrl(ZipUtils.createZipFromResourceDirectory("artifacts/sa-SOAP-Hello_PortType-consume").toURI() - .toURL().toString()); + suCons.setUrl("file:/artifacts/sa-SOAP-Hello_PortType-consume"); serviceUnits.add(suCons); /* Topology Model */ diff --git a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java deleted file mode 100644 index 6c0823b..0000000 --- a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java +++ /dev/null @@ -1,638 +0,0 @@ -/** - * Copyright (c) 2018-2019 Linagora - * - * This program/library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 2.1 of the License, or (at your - * option) any later version. - * - * This program/library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program/library; If not, see http://www.gnu.org/licenses/ - * for the GNU Lesser General Public License version 2.1. - */ - -package org.ow2.petals.deployer.utils; - -import org.junit.Before; - -public class RuntimeModelComparatorTest { - - private RuntimeModelComparator comparator; - - @Before - public void setupModelComparator() { - comparator = new RuntimeModelComparator(); - } - -// @Test -// public void compareComponentsWithDifferentIds() { -// Component c1 = new Component(); -// c1.setId("comp1"); -// -// Component c2 = new Component(); -// c2.setId("comp2"); -// -// assertFalse(comparator.compareComponents(c1, c2)); -// assertFalse(comparator.compareComponents(c1, c2)); -// } -// -// @Test -// public void compareComponents() { -// Component c1 = new Component(); -// c1.setId("comp"); -// -// Component c2 = new Component(); -// c2.setId("comp"); -// -// assertTrue(comparator.compareComponents(c1, c2)); -// } -// -// @Test -// public void compareComponentInstancesWithDifferentComponents() { -// ModelComparator mockedComparator = spy(ModelComparator.class); -// doReturn(false).when(mockedComparator).compareComponents(null, null); -// -// ComponentInstance ci1 = new ComponentInstance(); -// ci1.setReference("comp"); -// -// ComponentInstance ci2 = new ComponentInstance(); -// ci2.setReference("comp"); -// -// assertFalse(mockedComparator.compareComponentsInstances(ci1, ci2)); -// assertFalse(mockedComparator.compareComponentsInstances(ci2, ci1)); -// } -// -// @Test -// public void compareComponentInstancesWithDifferentIds() { -// ModelComparator mockedComparator = spy(ModelComparator.class); -// doReturn(true).when(mockedComparator).compareComponents(null, null); -// -// ComponentInstance ci1 = new ComponentInstance(); -// ci1.setReference("comp1"); -// -// ComponentInstance ci2 = new ComponentInstance(); -// ci2.setReference("comp2"); -// -// assertFalse(mockedComparator.compareComponentsInstances(ci1, ci2)); -// assertFalse(mockedComparator.compareComponentsInstances(ci2, ci1)); -// } -// -// @Test -// public void compareComponentInstances() { -// ModelComparator mockedComparator = spy(ModelComparator.class); -// doReturn(true).when(mockedComparator).compareComponents(null, null); -// -// ComponentInstance ci1 = new ComponentInstance(); -// ci1.setReference("comp"); -// -// ComponentInstance ci2 = new ComponentInstance(); -// ci2.setReference("comp"); -// -// assertTrue(mockedComparator.compareComponentsInstances(ci1, ci2)); -// assertTrue(mockedComparator.compareComponentsInstances(ci2, ci1)); -// } -// -// @Test -// public void compareServiceUnitsWithDifferentIds() { -// ServiceUnit su1 = new ServiceUnit(); -// su1.setId("su1"); -// su1.setTargetComponent("comp"); -// -// ServiceUnit su2 = new ServiceUnit(); -// su2.setId("su2"); -// su2.setTargetComponent("comp"); -// -// assertFalse(comparator.compareServiceUnits(su1, su2)); -// assertFalse(comparator.compareServiceUnits(su2, su1)); -// } -// -// @Test -// public void compareServiceUnitsWithDifferentComponents() { -// -// ServiceUnit su1 = new ServiceUnit(); -// su1.setId("su"); -// su1.setTargetComponent("comp1"); -// -// ServiceUnit su2 = new ServiceUnit(); -// su2.setId("su"); -// su2.setTargetComponent("comp2"); -// -// assertFalse(comparator.compareServiceUnits(su1, su2)); -// assertFalse(comparator.compareServiceUnits(su2, su1)); -// } -// -// @Test -// public void compareServiceUnits() { -// ServiceUnit su1 = new ServiceUnit(); -// su1.setId("su"); -// su1.setTargetComponent("comp"); -// -// ServiceUnit su2 = new ServiceUnit(); -// su2.setId("su"); -// su2.setTargetComponent("comp"); -// -// assertTrue(comparator.compareServiceUnits(su1, su2)); -// assertTrue(comparator.compareServiceUnits(su2, su1)); -// } -// -// @Test -// public void compareServiceUnitInstancesWithDifferentContainerInstances() { -// ModelComparator mockedComparator = spy(ModelComparator.class); -// doReturn(false).when(mockedComparator).compareContainerInstances(null, null); -// doReturn(true).when(mockedComparator).compareServiceUnits(null, null); -// -// ServiceUnitInstance sui1 = new ServiceUnitInstance(); -// -// ServiceUnitInstance sui2 = new ServiceUnitInstance(); -// -// assertFalse(mockedComparator.compareServiceUnitInstances(sui1, sui2)); -// assertFalse(mockedComparator.compareServiceUnitInstances(sui2, sui1)); -// } -// -// @Test -// public void compareServiceUnitInstancesWithDifferentServiceUnits() { -// ModelComparator mockedComparator = spy(ModelComparator.class); -// doReturn(true).when(mockedComparator).compareContainerInstances(null, null); -// doReturn(false).when(mockedComparator).compareServiceUnits(null, null); -// -// ServiceUnitInstance sui1 = new ServiceUnitInstance(); -// -// ServiceUnitInstance sui2 = new ServiceUnitInstance(); -// -// assertFalse(mockedComparator.compareServiceUnitInstances(sui1, sui2)); -// assertFalse(mockedComparator.compareServiceUnitInstances(sui2, sui1)); -// } -// -// @Test -// public void compareMachinesWithDifferentHostnames() { -// ProvisionedMachine m1 = new ProvisionedMachine(); -// m1.setId("machine"); -// m1.setHostname("localhost"); -// -// ProvisionedMachine m2 = new ProvisionedMachine(); -// m2.setId("machine"); -// m2.setHostname("1.2.3.4"); -// -// assertFalse(comparator.compareMachines(m1, m2)); -// assertFalse(comparator.compareMachines(m2, m1)); -// } -// -// @Test -// public void compareMachinesWithDifferentIds() { -// ProvisionedMachine m1 = new ProvisionedMachine(); -// m1.setId("machine1"); -// m1.setHostname("localhost"); -// -// ProvisionedMachine m2 = new ProvisionedMachine(); -// m2.setId("machine2"); -// m2.setHostname("localhost"); -// -// assertTrue(comparator.compareMachines(m1, m2)); -// assertTrue(comparator.compareMachines(m2, m1)); -// } -// -// @Test -// public void compareMachinesNotProvisioned() { -// Machine m1 = new Machine() { -// }; -// -// ProvisionedMachine m2 = new ProvisionedMachine(); -// m2.setId("machine"); -// m2.setHostname("localhost"); -// -// assertFalse(comparator.compareMachines(m1, m2)); -// assertFalse(comparator.compareMachines(m2, m1)); -// } -// -// @Test -// public void compareMachines() { -// ProvisionedMachine m1 = new ProvisionedMachine(); -// m1.setId("machine"); -// m1.setHostname("localhost"); -// -// ProvisionedMachine m2 = new ProvisionedMachine(); -// m2.setId("machine"); -// m2.setHostname("localhost"); -// -// assertTrue(comparator.compareMachines(m1, m2)); -// assertTrue(comparator.compareMachines(m2, m1)); -// } -// -// @Test -// public void compareServiceUnitInstances() { -// ModelComparator mockedComparator = spy(ModelComparator.class); -// doReturn(true).when(mockedComparator).compareContainerInstances(null, null); -// doReturn(true).when(mockedComparator).compareServiceUnits(null, null); -// -// ServiceUnitInstance sui1 = new ServiceUnitInstance(); -// -// ServiceUnitInstance sui2 = new ServiceUnitInstance(); -// -// assertTrue(mockedComparator.compareServiceUnitInstances(sui1, sui2)); -// assertTrue(mockedComparator.compareServiceUnitInstances(sui2, sui1)); -// } -// -// @Test -// public void compareContainerInstancesWithDifferentIds() { -// ModelComparator mockedComparator = spy(ModelComparator.class); -// doReturn(true).when(mockedComparator).compareMachines(null, null); -// -// Container c1 = new Container(); -// c1.setId("cont1"); -// c1.setDefaultJmxUser("petals"); -// c1.setDefaultJmxPort(7700); -// c1.setDefaultJmxPassword("password"); -// -// ContainerInstance ci1 = new ContainerInstance(); -// ci1.setReference(c1.getId()); -// -// Container c2 = new Container(); -// c2.setId("cont2"); -// -// ContainerInstance ci2 = new ContainerInstance(); -// ci2.setReference(c2.getId()); -// ci2.setJmxUser("petals"); -// ci2.setJmxPort(7700); -// ci2.setJmxPassword("password"); -// -// assertFalse(mockedComparator.compareContainerInstances(ci1, ci2)); -// assertFalse(mockedComparator.compareContainerInstances(ci2, ci1)); -// } -// -// @Test -// public void compareContainerInstancesWithDifferentMachines() { -// ModelComparator mockedComparator = spy(ModelComparator.class); -// doReturn(false).when(mockedComparator).compareMachines(null, null); -// -// Container c1 = new Container(); -// c1.setId("cont"); -// c1.setDefaultJmxUser("petals"); -// c1.setDefaultJmxPort(7700); -// c1.setDefaultJmxPassword("password"); -// -// ContainerInstance ci1 = new ContainerInstance(); -// ci1.setReference(c1.getId()); -// -// Container c2 = new Container(); -// c2.setId("cont"); -// -// ContainerInstance ci2 = new ContainerInstance(); -// ci2.setReference(c2.getId()); -// ci2.setJmxUser("petals"); -// ci2.setJmxPort(7700); -// ci2.setJmxPassword("password"); -// -// assertFalse(mockedComparator.compareContainerInstances(ci1, ci2)); -// assertFalse(mockedComparator.compareContainerInstances(ci2, ci1)); -// } -// -// @Test -// public void compareContainerInstancesWithDifferentJmxUsers() { -// ModelComparator mockedComparator = spy(ModelComparator.class); -// doReturn(true).when(mockedComparator).compareMachines(null, null); -// -// Container c1 = new Container(); -// c1.setId("cont"); -// c1.setDefaultJmxUser("petals"); -// c1.setDefaultJmxPort(7700); -// c1.setDefaultJmxPassword("password"); -// -// ContainerInstance ci1 = new ContainerInstance(); -// ci1.setReference(c1.getId()); -// -// Container c2 = new Container(); -// c2.setId("cont"); -// -// ContainerInstance ci2 = new ContainerInstance(); -// ci2.setReference(c2.getId()); -// ci2.setJmxUser("user"); -// ci2.setJmxPort(7700); -// ci2.setJmxPassword("password"); -// -// assertFalse(mockedComparator.compareContainerInstances(ci1, ci2)); -// assertFalse(mockedComparator.compareContainerInstances(ci2, ci1)); -// } -// -// @Test -// public void compareContainerInstancesWithDifferentJmxPorts() { -// ModelComparator mockedComparator = spy(ModelComparator.class); -// doReturn(true).when(mockedComparator).compareMachines(null, null); -// -// Container c1 = new Container(); -// c1.setId("cont"); -// c1.setDefaultJmxUser("petals"); -// c1.setDefaultJmxPort(80); -// c1.setDefaultJmxPassword("password"); -// -// ContainerInstance ci1 = new ContainerInstance(); -// ci1.setReference(c1.getId()); -// -// Container c2 = new Container(); -// c2.setId("cont"); -// -// ContainerInstance ci2 = new ContainerInstance(); -// ci2.setReference(c2.getId()); -// ci2.setJmxUser("petals"); -// ci2.setJmxPort(7700); -// ci2.setJmxPassword("password"); -// -// assertFalse(mockedComparator.compareContainerInstances(ci1, ci2)); -// assertFalse(mockedComparator.compareContainerInstances(ci2, ci1)); -// } -// -// @Test -// public void compareContainerInstancesWithDifferentJmxPasswords() { -// ModelComparator mockedComparator = spy(ModelComparator.class); -// doReturn(true).when(mockedComparator).compareMachines(null, null); -// -// Container c1 = new Container(); -// c1.setId("cont"); -// c1.setDefaultJmxUser("petals"); -// c1.setDefaultJmxPort(7700); -// c1.setDefaultJmxPassword("password"); -// -// ContainerInstance ci1 = new ContainerInstance(); -// ci1.setReference(c1.getId()); -// -// Container c2 = new Container(); -// c2.setId("cont"); -// -// ContainerInstance ci2 = new ContainerInstance(); -// ci2.setReference(c2.getId()); -// ci2.setJmxUser("petals"); -// ci2.setJmxPort(7700); -// ci2.setJmxPassword("azerty123"); -// -// assertFalse(mockedComparator.compareContainerInstances(ci1, ci2)); -// assertFalse(mockedComparator.compareContainerInstances(ci2, ci1)); -// } -// -// @Test -// public void compareContainerInstances() { -// ModelComparator mockedComparator = spy(ModelComparator.class); -// doReturn(true).when(mockedComparator).compareMachines(null, null); -// -// Container c1 = new Container(); -// c1.setId("cont"); -// c1.setDefaultJmxUser("petals"); -// c1.setDefaultJmxPort(7700); -// c1.setDefaultJmxPassword("password"); -// -// ContainerInstance ci1 = new ContainerInstance(); -// ci1.setReference(c1.getId()); -// -// Container c2 = new Container(); -// c2.setId("cont"); -// -// ContainerInstance ci2 = new ContainerInstance(); -// ci2.setReference(c2.getId()); -// ci2.setJmxUser("petals"); -// ci2.setJmxPort(7700); -// ci2.setJmxPassword("password"); -// -// assertTrue(mockedComparator.compareContainerInstances(ci1, ci2)); -// assertTrue(mockedComparator.compareContainerInstances(ci2, ci1)); -// } -// -// @Test -// public void compareComponentInstanceListsWithDifferentSizes() { -// List compInstances1 = new ArrayList<>(); -// compInstances1.add(null); -// -// List compInstances2 = new ArrayList<>(); -// compInstances2.add(null); -// compInstances2.add(null); -// -// assertFalse(comparator.compareComponentInstanceLists(compInstances1, compInstances2)); -// assertFalse(comparator.compareComponentInstanceLists(compInstances2, compInstances1)); -// } -// -// @Test -// public void compareComponentInstanceListsNotUnique() { -// ComponentInstance ci1 = new ComponentInstance(); -// ci1.setReference("comp1"); -// ComponentInstance ci2 = new ComponentInstance(); -// ci2.setReference("comp2"); -// -// ModelComparator mockedComparator = spy(ModelComparator.class); -// doReturn(false).when(mockedComparator).compareComponentsInstances(ci1, ci2); -// doReturn(false).when(mockedComparator).compareComponentsInstances(ci2, ci1); -// doReturn(true).when(mockedComparator).compareComponentsInstances(ci1, ci1); -// doReturn(true).when(mockedComparator).compareComponentsInstances(ci2, ci2); -// -// List compInstances1 = new ArrayList<>(); -// compInstances1.add(ci1); -// compInstances1.add(ci1); -// -// List compInstances2 = new ArrayList<>(); -// compInstances2.add(ci1); -// compInstances2.add(ci2); -// -// assertFalse(mockedComparator.compareComponentInstanceLists(compInstances1, compInstances2)); -// assertFalse(mockedComparator.compareComponentInstanceLists(compInstances2, compInstances1)); -// } -// -// @Test -// public void compareComponentInstanceListsWithDifferentItems() { -// ComponentInstance ci1 = new ComponentInstance(); -// ci1.setReference("comp"); -// -// ModelComparator mockedComparator = spy(ModelComparator.class); -// doReturn(false).when(mockedComparator).compareComponentsInstances(ci1, ci1); -// -// List compInstances1 = new ArrayList<>(); -// compInstances1.add(ci1); -// -// List compInstances2 = new ArrayList<>(); -// compInstances2.add(ci1); -// -// assertFalse(mockedComparator.compareComponentInstanceLists(compInstances1, compInstances2)); -// assertFalse(mockedComparator.compareComponentInstanceLists(compInstances2, compInstances1)); -// } -// -// @Test -// public void compareComponentInstanceLists() { -// ComponentInstance ci1 = new ComponentInstance(); -// ci1.setReference("comp1"); -// ComponentInstance ci2 = new ComponentInstance(); - // ci1.setId("comp2"); -// -// ModelComparator mockedComparator = spy(ModelComparator.class); -// doReturn(true).when(mockedComparator).compareComponentsInstances(ci1, ci1); -// doReturn(true).when(mockedComparator).compareComponentsInstances(ci2, ci2); -// -// List compInstances1 = new ArrayList<>(); -// compInstances1.add(ci1); -// compInstances1.add(ci2); -// -// List compInstances2 = new ArrayList<>(); -// compInstances2.add(ci2); -// compInstances2.add(ci1); -// -// assertTrue(mockedComparator.compareComponentInstanceLists(compInstances1, compInstances2)); -// assertTrue(mockedComparator.compareComponentInstanceLists(compInstances2, compInstances1)); -// } -// -// @Test -// public void compareServiceUnitInstanceListsWithDifferentSizes() { -// List suInstances1 = new ArrayList<>(); -// suInstances1.add(null); -// -// List suInstances2 = new ArrayList<>(); -// suInstances2.add(null); -// suInstances2.add(null); -// -// assertFalse(comparator.compareServiceUnitInstanceLists(suInstances1, suInstances2)); -// assertFalse(comparator.compareServiceUnitInstanceLists(suInstances2, suInstances1)); -// } -// -// @Test -// public void compareServiceUnitInstanceListsNotUnique() { -// ServiceUnit su1 = new ServiceUnit(); -// su1.setId("su1"); -// ServiceUnitInstance sui1 = new ServiceUnitInstance(); -// sui1.setReference(su1.getId()); -// ServiceUnit su2 = new ServiceUnit(); -// su2.setId("su2"); -// ServiceUnitInstance sui2 = new ServiceUnitInstance(); -// sui2.setReference(su2.getId()); -// -// ModelComparator mockedComparator = spy(ModelComparator.class); -// doReturn(false).when(mockedComparator).compareServiceUnitInstances(sui1, sui2); -// doReturn(false).when(mockedComparator).compareServiceUnitInstances(sui2, sui1); -// doReturn(true).when(mockedComparator).compareServiceUnitInstances(sui1, sui1); -// doReturn(true).when(mockedComparator).compareServiceUnitInstances(sui2, sui2); -// -// List suInstances1 = new ArrayList<>(); -// suInstances1.add(sui1); -// suInstances1.add(sui1); -// -// List suInstances2 = new ArrayList<>(); -// suInstances2.add(sui1); -// suInstances2.add(sui2); -// -// assertFalse(mockedComparator.compareServiceUnitInstanceLists(suInstances1, suInstances2)); -// assertFalse(mockedComparator.compareServiceUnitInstanceLists(suInstances2, suInstances1)); -// } -// -// @Test -// public void compareServiceUnitInstanceListsWithDifferentItems() { -// ServiceUnit su1 = new ServiceUnit(); -// su1.setId("su"); -// ServiceUnitInstance sui1 = new ServiceUnitInstance(); -// sui1.setReference(su1.getId()); -// -// ModelComparator mockedComparator = spy(ModelComparator.class); -// doReturn(false).when(mockedComparator).compareServiceUnitInstances(sui1, sui1); -// -// List suInstances1 = new ArrayList<>(); -// suInstances1.add(sui1); -// -// List suInstances2 = new ArrayList<>(); -// suInstances2.add(sui1); -// -// assertFalse(mockedComparator.compareServiceUnitInstanceLists(suInstances1, suInstances2)); -// assertFalse(mockedComparator.compareServiceUnitInstanceLists(suInstances2, suInstances1)); -// } -// -// @Test -// public void compareServiceUnitLists() { -// ServiceUnit su1 = new ServiceUnit(); -// su1.setId("su1"); -// ServiceUnitInstance sui1 = new ServiceUnitInstance(); -// sui1.setReference(su1.getId()); -// ServiceUnit su2 = new ServiceUnit(); -// su2.setId("su2"); -// ServiceUnitInstance sui2 = new ServiceUnitInstance(); -// sui2.setReference(su2.getId()); -// -// ModelComparator mockedComparator = spy(ModelComparator.class); -// doReturn(true).when(mockedComparator).compareServiceUnitInstances(sui1, sui1); -// doReturn(true).when(mockedComparator).compareServiceUnitInstances(sui2, sui2); -// -// List suInstances1 = new ArrayList<>(); -// suInstances1.add(sui1); -// suInstances1.add(sui2); -// -// List suInstances2 = new ArrayList<>(); -// suInstances2.add(sui2); -// suInstances2.add(sui1); -// -// assertTrue(mockedComparator.compareServiceUnitInstanceLists(suInstances1, suInstances2)); -// assertTrue(mockedComparator.compareServiceUnitInstanceLists(suInstances2, suInstances1)); -// } -// -// @Test -// public void compareModelsWithDifferentContainerInstances() { -// List containerInstances = new ArrayList(); -// containerInstances.add(null); -// TopologyInstance topoInst = new TopologyInstance(); -// topoInst.setContainerInstances(containerInstances); -// Bus bus = new Bus(); -// bus.setTopologyInstance(topoInst); -// List buses = new ArrayList(); -// buses.add(bus); -// BusModel busModel = new BusModel(); -// busModel.setBuses(buses); -// Model model = new Model(); -// model.setBusModel(busModel); -// -// ModelComparator mockedComparator = spy(ModelComparator.class); -// doReturn(false).when(mockedComparator).compareContainerInstances(null, null); -// doReturn(true).when(mockedComparator).compareServiceUnitInstanceLists(null, null); -// doReturn(true).when(mockedComparator).compareComponentInstanceLists(null, null); -// -// assertFalse(mockedComparator.compareModels(model, model)); -// } -// -// @Test -// public void compareModelsWithDifferentServiceUnitInstanceLists() { -// List containerInstances = new ArrayList(); -// containerInstances.add(null); -// TopologyInstance topoInst = new TopologyInstance(); -// topoInst.setContainerInstances(containerInstances); -// Bus bus = new Bus(); -// bus.setTopologyInstance(topoInst); -// List buses = new ArrayList(); -// buses.add(bus); -// BusModel busModel = new BusModel(); -// busModel.setBuses(buses); -// Model model = new Model(); -// model.setBusModel(busModel); -// -// ModelComparator mockedComparator = spy(ModelComparator.class); -// doReturn(true).when(mockedComparator).compareContainerInstances(null, null); -// doReturn(false).when(mockedComparator).compareServiceUnitInstanceLists(null, null); -// doReturn(true).when(mockedComparator).compareComponentInstanceLists(null, null); -// -// assertFalse(mockedComparator.compareModels(model, model)); -// } -// -// @Test -// public void compareModelsWithDifferentComponentInstanceLists() { -// List containerInstances = new ArrayList(); -// containerInstances.add(null); -// TopologyInstance topoInst = new TopologyInstance(); -// topoInst.setContainerInstances(containerInstances); -// Bus bus = new Bus(); -// bus.setTopologyInstance(topoInst); -// List buses = new ArrayList(); -// buses.add(bus); -// BusModel busModel = new BusModel(); -// busModel.setBuses(buses); -// Model model = new Model(); -// model.setBusModel(busModel); -// -// ModelComparator mockedComparator = spy(ModelComparator.class); -// doReturn(true).when(mockedComparator).compareContainerInstances(null, null); -// doReturn(true).when(mockedComparator).compareServiceUnitInstanceLists(null, null); -// doReturn(false).when(mockedComparator).compareComponentInstanceLists(null, null); -// -// assertFalse(mockedComparator.compareModels(model, model)); -// } -} From 97433820955d60b0ec35704a26a6c50b244d2356 Mon Sep 17 00:00:00 2001 From: Alexandre Lagane Date: Tue, 15 Jan 2019 16:39:15 +0100 Subject: [PATCH 05/21] Add some documentation (XSD and Java) --- pom.xml | 25 ---- .../runtimemodel/RuntimeComponent.java | 3 + .../runtimemodel/RuntimeContainer.java | 3 + .../deployer/runtimemodel/RuntimeModel.java | 3 + .../runtimemodel/RuntimeServiceUnit.java | 3 + .../petals/deployer/utils/ModelConverter.java | 6 +- .../petals/deployer/utils/ModelDeployer.java | 3 + .../utils/ModelDeployerException.java | 3 + .../utils/RuntimeModelComparator.java | 17 ++- .../deployer/utils/RuntimeModelDeployer.java | 3 + .../utils/RuntimeModelDeployerException.java | 3 + .../deployer/utils/RuntimeModelExporter.java | 3 + src/main/resources/binding.xjb | 2 +- src/main/resources/bus-model.xsd | 123 +++++++++++++++--- src/main/resources/component-repository.xsd | 28 +++- src/main/resources/model.xsd | 53 +++++++- src/main/resources/service-unit-model.xsd | 36 ++++- src/main/resources/topology-model.xsd | 61 +++++++-- .../deployer/utils/ModelConverterTest.java | 3 + .../petals/deployer/utils/ParseModelTest.java | 3 + .../utils/RuntimeModelDeployerTest.java | 7 +- .../ow2/petals/deployer/utils/ZipUtils.java | 3 + 22 files changed, 321 insertions(+), 73 deletions(-) diff --git a/pom.xml b/pom.xml index 9d9a99f..314454f 100644 --- a/pom.xml +++ b/pom.xml @@ -60,37 +60,12 @@ 2.4.0 - - - - - - commons-io commons-io 2.6 - - org.jvnet.jaxb2_commons jaxb2-basics-runtime diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java index c8fc2a5..e2f6a04 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java @@ -20,6 +20,9 @@ import java.net.URL; +/** + * @author alagane + */ public class RuntimeComponent { private final String id; diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java index 4d10778..e40d9ca 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java @@ -24,6 +24,9 @@ import org.ow2.petals.deployer.runtimemodel.RuntimeModel.RuntimeModelException; +/** + * @author alagane + */ public class RuntimeContainer { private final String id; diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java index da9c02e..7acbbf3 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java @@ -22,6 +22,9 @@ import java.util.HashMap; import java.util.Map; +/** + * @author alagane + */ public class RuntimeModel { private Map containers = new HashMap(); diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java index 1723ea2..f1c760f 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java @@ -20,6 +20,9 @@ import java.net.URL; +/** + * @author alagane + */ public class RuntimeServiceUnit { private final String id; diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java b/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java index 51d163f..510341e 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java +++ b/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java @@ -41,8 +41,12 @@ import org.ow2.petals.deployer.runtimemodel.RuntimeModel.RuntimeModelException; import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit; +/** + * @author alagane + */ public class ModelConverter { - public RuntimeModel convertModelToRuntimeModel(Model model) throws MalformedURLException, RuntimeModelException { + public static RuntimeModel convertModelToRuntimeModel(Model model) + throws MalformedURLException, RuntimeModelException { RuntimeModel runtimeModel = new RuntimeModel(); TopologyModel topoModel = model.getTopologyModel(); diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java index 415c289..aa60f36 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java +++ b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java @@ -39,6 +39,9 @@ import org.ow2.petals.deployer.runtimemodel.RuntimeModel.RuntimeModelException; import org.ow2.petals.jbi.descriptor.JBIDescriptorException; +/** + * @author alagane + */ public class ModelDeployer { /** diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployerException.java b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployerException.java index aef8710..6bc20d0 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployerException.java +++ b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployerException.java @@ -18,6 +18,9 @@ package org.ow2.petals.deployer.utils; +/** + * @author alagane + */ public class ModelDeployerException extends Exception { private static final long serialVersionUID = 7599724111843987402L; diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java index 436785c..f5348c1 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java @@ -25,12 +25,15 @@ import org.ow2.petals.deployer.runtimemodel.RuntimeModel; import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit; +/** + * @author alagane + */ public class RuntimeModelComparator { - public boolean compareRuntimeModels(final RuntimeModel m1, final RuntimeModel m2) { + public static boolean compareRuntimeModels(final RuntimeModel m1, final RuntimeModel m2) { return compareRuntimeContainerMaps(m1, m2); } - private boolean compareRuntimeComponentMaps(RuntimeContainer cont1, RuntimeContainer cont2) { + private static boolean compareRuntimeComponentMaps(RuntimeContainer cont1, RuntimeContainer cont2) { Collection compList1 = cont1.getComponents(); Collection compList2 = cont2.getComponents(); @@ -50,7 +53,7 @@ private boolean compareRuntimeComponentMaps(RuntimeContainer cont1, RuntimeConta return true; } - private boolean compareRuntimeContainerMaps(RuntimeModel m1, RuntimeModel m2) { + private static boolean compareRuntimeContainerMaps(RuntimeModel m1, RuntimeModel m2) { Collection contList1 = m1.getContainers(); Collection contList2 = m2.getContainers(); @@ -70,14 +73,14 @@ private boolean compareRuntimeContainerMaps(RuntimeModel m1, RuntimeModel m2) { return true; } - private boolean compareRuntimeContainers(RuntimeContainer cont1, RuntimeContainer cont2) { + private static boolean compareRuntimeContainers(RuntimeContainer cont1, RuntimeContainer cont2) { return cont1.getId().equals(cont2.getId()) && cont1.getPort() == cont2.getPort() && cont1.getUser().equals(cont2.getUser()) && cont1.getPassword().equals(cont2.getPassword()) && cont1.getHostname().equals(cont2.getHostname()) && compareRuntimeServiceUnitMaps(cont1, cont2) && compareRuntimeComponentMaps(cont1, cont2); } - private boolean compareRuntimeServiceUnitMaps(RuntimeContainer cont1, RuntimeContainer cont2) { + private static boolean compareRuntimeServiceUnitMaps(RuntimeContainer cont1, RuntimeContainer cont2) { Collection suList1 = cont1.getServiceUnits(); Collection suList2 = cont2.getServiceUnits(); @@ -97,11 +100,11 @@ private boolean compareRuntimeServiceUnitMaps(RuntimeContainer cont1, RuntimeCon return true; } - private boolean compareRuntimeServiceUnits(RuntimeServiceUnit su1, RuntimeServiceUnit su2) { + private static boolean compareRuntimeServiceUnits(RuntimeServiceUnit su1, RuntimeServiceUnit su2) { return su1.getId().equals(su2.getId()); } - private boolean compareRuntimeComponents(RuntimeComponent comp1, RuntimeComponent comp2) { + private static boolean compareRuntimeComponents(RuntimeComponent comp1, RuntimeComponent comp2) { return comp1.getId().equals(comp2.getId()); } } diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java index 37193c1..6d6ac1d 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java @@ -50,6 +50,9 @@ import org.ow2.petals.jbi.descriptor.original.generated.Jbi; import org.ow2.petals.jbi.descriptor.original.generated.ServiceAssembly; +/** + * @author alagane + */ public class RuntimeModelDeployer { private static final Logger LOG = Logger.getLogger(RuntimeModelDeployer.class.getName()); diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerException.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerException.java index 25621fc..55ddbee 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerException.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerException.java @@ -18,6 +18,9 @@ package org.ow2.petals.deployer.utils; +/** + * @author alagane + */ public class RuntimeModelDeployerException extends Exception { private static final long serialVersionUID = -3352449083809006549L; diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java index 532d2dd..26a3146 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java @@ -36,6 +36,9 @@ import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit; import org.ow2.petals.jbi.descriptor.JBIDescriptorException; +/** + * @author alagane + */ public class RuntimeModelExporter { private static final Logger LOG = Logger.getLogger(RuntimeModelExporter.class.getName()); diff --git a/src/main/resources/binding.xjb b/src/main/resources/binding.xjb index 3391092..ff83e04 100644 --- a/src/main/resources/binding.xjb +++ b/src/main/resources/binding.xjb @@ -18,7 +18,7 @@ --> - + diff --git a/src/main/resources/bus-model.xsd b/src/main/resources/bus-model.xsd index c96c3ed..14c9e37 100644 --- a/src/main/resources/bus-model.xsd +++ b/src/main/resources/bus-model.xsd @@ -27,43 +27,130 @@ - - + + + + The machines on which parts of a Petals ESB bus will be running. + + + + + + + The list of Petals ESB busses to deploy. + + + - + + + + The instances of Petals ESB containers forming the Petals ESB bus. + + + - + + + + The reference topology from the topology model. + + + - - + + + + The component instances required by service units. + + + + + + + The service unit instances to deploy on the container. + + + - - - - - + + + + Reference to a container from the topology model. + + + + + + + JMX port of the current Petals ESB container. A deployment property can be used. Each + container (from topology model) without a default JMX port must have one defined in this model. + + + + + + + JMX username of the current Petals ESB container. A deployment property can be used. Each + container (from topology model) without a default JMX username must have one defined in this model. + + + + + + + JMX password of the current Petals ESB container. A deployment property can be used. Each + container (from topology model) without a default JMX password must have one defined in this model. + + + + + + + The reference of the machine on which the container is running. + + + - + + + + Reference to a component from a component repository. + + + - + + + + Reference to a service unit from a service unit model. + + + - + + + + Hostname, IP address or deployment property name of the provisioned machine. + + + @@ -71,6 +158,12 @@ - + + + + Identifier of the machine. It must be unique in the model. + + + \ No newline at end of file diff --git a/src/main/resources/component-repository.xsd b/src/main/resources/component-repository.xsd index c920201..a47510a 100644 --- a/src/main/resources/component-repository.xsd +++ b/src/main/resources/component-repository.xsd @@ -17,19 +17,39 @@ for the GNU Lesser General Public License version 2.1. --> + xmlns="http://www.w3.org/2001/XMLSchema" xmlns:cr="http://petals.ow2.org/deployer/model/component-repository/xml/1.0" + elementFormDefault="qualified"> - + + + + The list of components of this repository. + + + - + + + + The URL of the associated archive. + + + - + + + + The identifier of this component in the model. It must be the same than the one defined in + the JBI descriptor of the component and must be unique in the model. + + + \ No newline at end of file diff --git a/src/main/resources/model.xsd b/src/main/resources/model.xsd index fe4424c..4265559 100644 --- a/src/main/resources/model.xsd +++ b/src/main/resources/model.xsd @@ -18,24 +18,65 @@ --> - + + + + Model defining Petals ESB buses to deploy. Documentation can be found here + https://doc.petalslink.com/display/petalscomponents/Petals+ESB+Deployer+1.0.0 + + - - - - + + + + This model defines a set of service units to deploy on your Petals ESB bus. This model + will be mainly written by development teams because they have the knowledge of service units to + deploy. + + + + + + + This model defines a set of binding components, service engines and shared libraries that + can be used to perform the deployment of a Petals ESB bus. Such models are included in Petals ESB + distribution packs, and you can write your own. + + + + + + + This model defines a set of topologies, used by Petals ESB buses. This model will be + mainly written by the Petals ESB bus architect. + + + + + + + This model defines your Petals ESB bus placing Petals ESB components on their containers: + - service unit on its Petals ESB container + - Petals ESB container on its machine + This model will be + mainly written by the Petals ESB bus architect in agreement with operators. + + + diff --git a/src/main/resources/service-unit-model.xsd b/src/main/resources/service-unit-model.xsd index 419337d..648c0ce 100644 --- a/src/main/resources/service-unit-model.xsd +++ b/src/main/resources/service-unit-model.xsd @@ -17,18 +17,46 @@ for the GNU Lesser General Public License version 2.1. --> + xmlns="http://www.w3.org/2001/XMLSchema" xmlns:sum="http://petals.ow2.org/deployer/model/service-unit/xml/1.0" + elementFormDefault="qualified"> + + Model defining Petals ESB buses to deploy. Documentation can be found here + https://doc.petalslink.com/display/petalscomponents/Petals+ESB+Deployer+1.0.0 + + - + + + + The list of service units to deploy. There must be at least one service unit in the model. + + + - + + + + The map of placeholder required by the service unit. The key of the map is the key of the + placeholder, and the value of the map is the default value of the placeholder. If there is no default + value, the value must be null. + + + - + + + + Identifier of the service unit. It must be the same than the one defined in the JBI + descriptor on the archive and must be + unique in the model. + + + diff --git a/src/main/resources/topology-model.xsd b/src/main/resources/topology-model.xsd index 3dd7d70..103d8e2 100644 --- a/src/main/resources/topology-model.xsd +++ b/src/main/resources/topology-model.xsd @@ -17,26 +17,71 @@ for the GNU Lesser General Public License version 2.1. --> + xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tm="http://petals.ow2.org/deployer/model/topology/xml/1.0" + elementFormDefault="qualified"> - + + + + The list of topologies in the model. Their id must be unique in the model. There must be + at least one topology in the model. + + + - + + + + Petals ESB containers of the topology. Their id must be unique in the topology. There must + be at least one container in the topology. + + + - + + + + Identifier of the topology. + + + - - - - + + + + Identifier of the Petals ESB container as used as name in the file topology.xml. + + + + + + + Default JMX port value. A deployment property can be used. + + + + + + + Default JMX username value. A deployment property can be used. + + + + + + + Default JMX password value. A deployment property can be used. + + + \ No newline at end of file diff --git a/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java b/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java index aa4b4fa..6c4f1fa 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java @@ -29,6 +29,9 @@ import org.ow2.petals.deployer.runtimemodel.RuntimeModel; import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit; +/** + * @author alagane + */ public class ModelConverterTest { @Test diff --git a/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java b/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java index b2ec0cc..2cd9986 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java @@ -51,6 +51,9 @@ import org.ow2.petals.deployer.model.xml._1.Model; import org.ow2.petals.deployer.model.xml._1.ObjectFactory; +/** + * @author alagane + */ public class ParseModelTest { final public static String CONTAINER_NAME = "sample-0"; diff --git a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java index 9b932fa..2de23e6 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java @@ -42,6 +42,9 @@ import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit; import org.ow2.petals.jbi.descriptor.original.JBIDescriptorBuilder; +/** + * @author alagane + */ public class RuntimeModelDeployerTest { final public static String CONTAINER_NAME = "sample-0"; @@ -86,8 +89,8 @@ public void demoSoap() throws Exception { org.ow2.petals.admin.topology.Container cont = createContainerSample(); petalsAdminApiRule.registerContainer(cont); ArtifactLifecycleFactoryMock artifactLifecycleFactoryMock = new ArtifactLifecycleFactoryMock(cont); - RuntimeModelDeployer modelDeployer = new RuntimeModelDeployer(petalsAdminApiRule.getSingleton(), artifactLifecycleFactoryMock, - JBIDescriptorBuilder.getInstance()); + RuntimeModelDeployer modelDeployer = new RuntimeModelDeployer(petalsAdminApiRule.getSingleton(), + artifactLifecycleFactoryMock, JBIDescriptorBuilder.getInstance()); modelDeployer.deployRuntimeModel(model); RuntimeModelExporter modelExporter = new RuntimeModelExporter(); diff --git a/src/test/java/org/ow2/petals/deployer/utils/ZipUtils.java b/src/test/java/org/ow2/petals/deployer/utils/ZipUtils.java index a1c44cb..80047ec 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/ZipUtils.java +++ b/src/test/java/org/ow2/petals/deployer/utils/ZipUtils.java @@ -27,6 +27,9 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; +/** + * @author alagane + */ public class ZipUtils { private static final int DEFAULT_BUFFER_SIZE = 1024; From 6c79b057fe10fd2a0abb60c02aa8d2d35d1b20fe Mon Sep 17 00:00:00 2001 From: Alexandre Lagane Date: Thu, 17 Jan 2019 16:29:53 +0100 Subject: [PATCH 06/21] Resolve comments on pull request --- model.xml | 2 +- .../petals/deployer/utils/ModelConverter.java | 5 +--- .../petals/deployer/utils/ModelDeployer.java | 4 +--- .../utils/RuntimeModelComparator.java | 7 ++++++ .../deployer/utils/RuntimeModelDeployer.java | 17 ++++++------- .../deployer/utils/RuntimeModelExporter.java | 24 +++++++++++++------ .../utils/RuntimeModelDeployerTest.java | 11 ++++----- 7 files changed, 41 insertions(+), 29 deletions(-) diff --git a/model.xml b/model.xml index 1cd8cc1..b5c0e6f 100644 --- a/model.xml +++ b/model.xml @@ -18,7 +18,7 @@ - + diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java b/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java index 510341e..f167dc5 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java +++ b/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java @@ -33,7 +33,6 @@ import org.ow2.petals.deployer.model.service_unit.xml._1.ServiceUnit; import org.ow2.petals.deployer.model.service_unit.xml._1.ServiceUnitModel; import org.ow2.petals.deployer.model.topology.xml._1.Container; -import org.ow2.petals.deployer.model.topology.xml._1.TopologyModel; import org.ow2.petals.deployer.model.xml._1.Model; import org.ow2.petals.deployer.runtimemodel.RuntimeComponent; import org.ow2.petals.deployer.runtimemodel.RuntimeContainer; @@ -49,9 +48,7 @@ public static RuntimeModel convertModelToRuntimeModel(Model model) throws MalformedURLException, RuntimeModelException { RuntimeModel runtimeModel = new RuntimeModel(); - TopologyModel topoModel = model.getTopologyModel(); - - Container cont = topoModel.getTopology().get(0).getContainer().get(0); + Container cont = model.getTopologyModel().getTopology().get(0).getContainer().get(0); BusModel busModel = model.getBusModel(); diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java index aa60f36..081ecfa 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java +++ b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java @@ -72,10 +72,8 @@ public static void deployModel(URL url) throws ModelDeployerException { Model model = unmarshaller.unmarshal(new StreamSource(modelFile), Model.class).getValue(); - ModelConverter converter = new ModelConverter(); - RuntimeModel runtimeModel; - runtimeModel = converter.convertModelToRuntimeModel(model); + runtimeModel = ModelConverter.convertModelToRuntimeModel(model); RuntimeModelDeployer deployer; deployer = new RuntimeModelDeployer(); diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java index f5348c1..12c2004 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java @@ -29,6 +29,13 @@ * @author alagane */ public class RuntimeModelComparator { + /** + * Compare two runtimes models. The URL are not checked. + * + * @param m1 + * @param m2 + * @return true if m1 and m2 are equivalents + */ public static boolean compareRuntimeModels(final RuntimeModel m1, final RuntimeModel m2) { return compareRuntimeContainerMaps(m1, m2); } diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java index 6d6ac1d..dcfe47b 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java @@ -23,6 +23,7 @@ import java.nio.file.Files; import java.util.Collection; import java.util.HashSet; +import java.util.Set; import java.util.logging.Logger; import org.apache.commons.io.FileUtils; @@ -63,9 +64,9 @@ public class RuntimeModelDeployer { private JBIDescriptorBuilder jdb; - private HashSet deployedComponents = new HashSet(); + private Set deployedComponents = new HashSet(); - private HashSet deployedServiceUnits = new HashSet(); + private Set deployedServiceUnits = new HashSet(); public RuntimeModelDeployer() throws DuplicatedServiceException, MissingServiceException, JBIDescriptorException { this(PetalsAdministrationFactory.getInstance().newPetalsAdministrationAPI(), null, @@ -155,22 +156,22 @@ private void deployRuntimeComponent(RuntimeComponent component) LOG.fine("Deploying component " + component.getId()); ComponentLifecycle compLifecycle = artifactLifecycleFactory .createComponentLifecycle(new org.ow2.petals.admin.api.artifact.Component(compId, - convertComponentType(jbi.getComponent().getType()))); + convertComponentTypeFromJbiToPetalsAdmin(jbi.getComponent().getType()))); compLifecycle.deploy(compFile.toURI().toURL()); compLifecycle.start(); LOG.fine("Component " + compId + " deployed and started"); } - public ComponentType convertComponentType( + public ComponentType convertComponentTypeFromJbiToPetalsAdmin( final org.ow2.petals.jbi.descriptor.original.generated.ComponentType jbiType) { + ComponentType compType = null; switch (jbiType) { case BINDING_COMPONENT: - return ComponentType.BC; + compType = ComponentType.BC; case SERVICE_ENGINE: - return ComponentType.SE; - default: - return null; + compType = ComponentType.SE; } + return compType; } } diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java index 26a3146..7e7c4e8 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java @@ -21,7 +21,6 @@ import java.util.logging.Logger; import org.ow2.petals.admin.api.ArtifactAdministration; -import org.ow2.petals.admin.api.ContainerAdministration; import org.ow2.petals.admin.api.PetalsAdministration; import org.ow2.petals.admin.api.PetalsAdministrationFactory; import org.ow2.petals.admin.api.artifact.Artifact; @@ -45,8 +44,6 @@ public class RuntimeModelExporter { private PetalsAdministration petalsAdmin; - private ContainerAdministration containerAdmin; - private ArtifactAdministration artifactAdmin; public RuntimeModelExporter() throws DuplicatedServiceException, MissingServiceException, JBIDescriptorException { @@ -55,19 +52,32 @@ public RuntimeModelExporter() throws DuplicatedServiceException, MissingServiceE public RuntimeModelExporter(PetalsAdministration petalsAdmin) { this.petalsAdmin = petalsAdmin; - containerAdmin = petalsAdmin.newContainerAdministration(); artifactAdmin = petalsAdmin.newArtifactAdministration(); } + /** + * If topologyPassphrase is null, the exported RuntimeModel will not contain JMX usernames and JMX passwords. + * + * @param hostname + * @param port + * @param user + * @param password + * @param topologyPassphrase + * @return the RuntimeModel of the container corresponding to other parameters + * @throws RuntimeModelException + * @throws ArtifactAdministrationException + * @throws ContainerAdministrationException + */ public RuntimeModel exportRuntimeModel(final String hostname, final int port, final String user, - final String password) + final String password, final String topologyPassphrase) throws RuntimeModelException, ArtifactAdministrationException, ContainerAdministrationException { petalsAdmin.connect(hostname, port, user, password); RuntimeModel model = new RuntimeModel(); - RuntimeContainer cont = new RuntimeContainer(petalsAdmin.newContainerAdministration().getTopology(null, false) - .getContainers().get(0).getContainerName(), port, user, password, hostname); + RuntimeContainer cont = new RuntimeContainer(petalsAdmin.newContainerAdministration() + .getTopology(topologyPassphrase, false).getContainers().get(0).getContainerName(), port, user, password, + hostname); model.addContainer(cont); for (Artifact artifact : artifactAdmin.listArtifacts()) { diff --git a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java index 2de23e6..bf3da93 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java @@ -29,7 +29,7 @@ import java.util.logging.LogRecord; import java.util.logging.Logger; -import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.ow2.petals.admin.junit.ArtifactLifecycleFactoryMock; @@ -61,8 +61,8 @@ public class RuntimeModelDeployerTest { @Rule public PetalsAdministrationApi petalsAdminApiRule = new PetalsAdministrationApi(); - @Before - public void setupLogger() throws Exception { + @BeforeClass + public static void setupLogger() throws Exception { Logger deployerLogger = Logger.getLogger(RuntimeModelDeployer.class.getName()); deployerLogger.setLevel(Level.FINER); Logger comparatorLogger = Logger.getLogger(RuntimeModelComparator.class.getName()); @@ -95,10 +95,9 @@ public void demoSoap() throws Exception { RuntimeModelExporter modelExporter = new RuntimeModelExporter(); RuntimeModel exportedModel = modelExporter.exportRuntimeModel(CONTAINER_HOST, CONTAINER_JMX_PORT, - CONTAINER_USER, CONTAINER_PWD); + CONTAINER_USER, CONTAINER_PWD, null); - RuntimeModelComparator modelComparator = new RuntimeModelComparator(); - assertTrue(modelComparator.compareRuntimeModels(model, exportedModel)); + assertTrue(RuntimeModelComparator.compareRuntimeModels(model, exportedModel)); } private org.ow2.petals.admin.topology.Container createContainerSample() { From e27d36cbf347812b738321cc8b985d3857d552f7 Mon Sep 17 00:00:00 2001 From: Alexandre Lagane Date: Mon, 21 Jan 2019 09:18:42 +0100 Subject: [PATCH 07/21] Replace Javadoc @author by full name and company Also remove model.xml because it should not be committed --- model.xml | 37 ------------------- .../runtimemodel/RuntimeComponent.java | 2 +- .../runtimemodel/RuntimeContainer.java | 2 +- .../deployer/runtimemodel/RuntimeModel.java | 2 +- .../runtimemodel/RuntimeServiceUnit.java | 2 +- .../petals/deployer/utils/ModelConverter.java | 2 +- .../petals/deployer/utils/ModelDeployer.java | 2 +- .../utils/ModelDeployerException.java | 2 +- .../utils/RuntimeModelComparator.java | 2 +- .../deployer/utils/RuntimeModelDeployer.java | 2 +- .../utils/RuntimeModelDeployerException.java | 2 +- .../deployer/utils/RuntimeModelExporter.java | 2 +- .../deployer/utils/ModelConverterTest.java | 2 +- .../petals/deployer/utils/ParseModelTest.java | 2 +- .../utils/RuntimeModelDeployerTest.java | 2 +- .../ow2/petals/deployer/utils/ZipUtils.java | 2 +- 16 files changed, 15 insertions(+), 52 deletions(-) delete mode 100644 model.xml diff --git a/model.xml b/model.xml deleted file mode 100644 index b5c0e6f..0000000 --- a/model.xml +++ /dev/null @@ -1,37 +0,0 @@ - - - - - file:/artifacts/sa-SOAP-Hello_Service1-provide - - - file:/artifacts/sa-SOAP-Hello_Service2-provide - - - file:/artifacts/sa-SOAP-Hello_PortType-consume - - - - - file:/artifacts/petals-bc-soap-5.0.0 - - - - - - - - - - localhost - - - - - - - - - - - diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java index e2f6a04..502d2c2 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java @@ -21,7 +21,7 @@ import java.net.URL; /** - * @author alagane + * @author Alexandre Lagane - Linagora */ public class RuntimeComponent { private final String id; diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java index e40d9ca..f80eb33 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java @@ -25,7 +25,7 @@ import org.ow2.petals.deployer.runtimemodel.RuntimeModel.RuntimeModelException; /** - * @author alagane + * @author Alexandre Lagane - Linagora */ public class RuntimeContainer { diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java index 7acbbf3..4972e1a 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java @@ -23,7 +23,7 @@ import java.util.Map; /** - * @author alagane + * @author Alexandre Lagane - Linagora */ public class RuntimeModel { diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java index f1c760f..4c8c39f 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java @@ -21,7 +21,7 @@ import java.net.URL; /** - * @author alagane + * @author Alexandre Lagane - Linagora */ public class RuntimeServiceUnit { diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java b/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java index f167dc5..9bd48b9 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java +++ b/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java @@ -41,7 +41,7 @@ import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit; /** - * @author alagane + * @author Alexandre Lagane - Linagora */ public class ModelConverter { public static RuntimeModel convertModelToRuntimeModel(Model model) diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java index 081ecfa..6b0bb92 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java +++ b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java @@ -40,7 +40,7 @@ import org.ow2.petals.jbi.descriptor.JBIDescriptorException; /** - * @author alagane + * @author Alexandre Lagane - Linagora */ public class ModelDeployer { diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployerException.java b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployerException.java index 6bc20d0..b310938 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployerException.java +++ b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployerException.java @@ -19,7 +19,7 @@ package org.ow2.petals.deployer.utils; /** - * @author alagane + * @author Alexandre Lagane - Linagora */ public class ModelDeployerException extends Exception { diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java index 12c2004..5d91a34 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java @@ -26,7 +26,7 @@ import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit; /** - * @author alagane + * @author Alexandre Lagane - Linagora */ public class RuntimeModelComparator { /** diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java index dcfe47b..9e5e4c4 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java @@ -52,7 +52,7 @@ import org.ow2.petals.jbi.descriptor.original.generated.ServiceAssembly; /** - * @author alagane + * @author Alexandre Lagane - Linagora */ public class RuntimeModelDeployer { diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerException.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerException.java index 55ddbee..bec34a2 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerException.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerException.java @@ -19,7 +19,7 @@ package org.ow2.petals.deployer.utils; /** - * @author alagane + * @author Alexandre Lagane - Linagora */ public class RuntimeModelDeployerException extends Exception { diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java index 7e7c4e8..db3340f 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java @@ -36,7 +36,7 @@ import org.ow2.petals.jbi.descriptor.JBIDescriptorException; /** - * @author alagane + * @author Alexandre Lagane - Linagora */ public class RuntimeModelExporter { diff --git a/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java b/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java index 6c4f1fa..e68704a 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java @@ -30,7 +30,7 @@ import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit; /** - * @author alagane + * @author Alexandre Lagane - Linagora */ public class ModelConverterTest { diff --git a/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java b/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java index 2cd9986..a81babe 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java @@ -52,7 +52,7 @@ import org.ow2.petals.deployer.model.xml._1.ObjectFactory; /** - * @author alagane + * @author Alexandre Lagane - Linagora */ public class ParseModelTest { diff --git a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java index bf3da93..f1ade0b 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java @@ -43,7 +43,7 @@ import org.ow2.petals.jbi.descriptor.original.JBIDescriptorBuilder; /** - * @author alagane + * @author Alexandre Lagane - Linagora */ public class RuntimeModelDeployerTest { final public static String CONTAINER_NAME = "sample-0"; diff --git a/src/test/java/org/ow2/petals/deployer/utils/ZipUtils.java b/src/test/java/org/ow2/petals/deployer/utils/ZipUtils.java index 80047ec..a134dc4 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/ZipUtils.java +++ b/src/test/java/org/ow2/petals/deployer/utils/ZipUtils.java @@ -28,7 +28,7 @@ import java.util.zip.ZipOutputStream; /** - * @author alagane + * @author Alexandre Lagane - Linagora */ public class ZipUtils { private static final int DEFAULT_BUFFER_SIZE = 1024; From 9af3a1633d87f128fc1062cedeb3b86cf4ef487d Mon Sep 17 00:00:00 2001 From: Alexandre Lagane Date: Mon, 21 Jan 2019 09:21:43 +0100 Subject: [PATCH 08/21] Use return instead of storing result in variable --- .../ow2/petals/deployer/utils/RuntimeModelDeployer.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java index 9e5e4c4..88bfe57 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java @@ -165,13 +165,13 @@ private void deployRuntimeComponent(RuntimeComponent component) public ComponentType convertComponentTypeFromJbiToPetalsAdmin( final org.ow2.petals.jbi.descriptor.original.generated.ComponentType jbiType) { - ComponentType compType = null; switch (jbiType) { case BINDING_COMPONENT: - compType = ComponentType.BC; + return ComponentType.BC; case SERVICE_ENGINE: - compType = ComponentType.SE; + return ComponentType.SE; + default: + return null; } - return compType; } } From d62343fa53dc0ecafd2593f4e5e03195932e2e12 Mon Sep 17 00:00:00 2001 From: Alexandre Lagane Date: Tue, 22 Jan 2019 11:49:56 +0100 Subject: [PATCH 09/21] Refactor from pull request comments --- pom.xml | 14 ++++- .../runtimemodel/RuntimeComponent.java | 18 ++++-- .../runtimemodel/RuntimeContainer.java | 55 +++++++++++++++---- .../deployer/runtimemodel/RuntimeModel.java | 5 +- .../runtimemodel/RuntimeServiceUnit.java | 19 ++++--- .../petals/deployer/utils/ModelConverter.java | 6 +- .../petals/deployer/utils/ModelDeployer.java | 18 ++---- .../utils/RuntimeModelComparator.java | 15 ++--- .../deployer/utils/RuntimeModelDeployer.java | 26 ++++----- .../utils/RuntimeModelDeployerException.java | 2 +- .../deployer/utils/RuntimeModelExporter.java | 6 +- .../runtimemodel/RuntimeModelTest.java | 29 ++++++++++ .../deployer/utils/ModelConverterTest.java | 3 +- .../petals/deployer/utils/ParseModelTest.java | 4 +- .../utils/RuntimeModelDeployerTest.java | 2 +- 15 files changed, 147 insertions(+), 75 deletions(-) create mode 100644 src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeModelTest.java diff --git a/pom.xml b/pom.xml index 314454f..30b190d 100644 --- a/pom.xml +++ b/pom.xml @@ -26,7 +26,6 @@ 1.1.1-SNAPSHOT - org.ow2.petals petals-esb-deployer 0.0.1-SNAPSHOT jar @@ -69,7 +68,6 @@ org.jvnet.jaxb2_commons jaxb2-basics-runtime - 0.11.1 @@ -92,6 +90,18 @@ + + com.github.spotbugs + spotbugs-maven-plugin + 3.1.8 + + + com.github.spotbugs + spotbugs + 3.1.9 + + +
diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java index 502d2c2..c332b21 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java @@ -28,10 +28,20 @@ public class RuntimeComponent { private URL url; + /** + * + * @param id + * must not be null + */ public RuntimeComponent(final String id) { this.id = id; } + /** + * + * @param id + * must not be null + */ public RuntimeComponent(final String id, final URL url) { this(id); this.url = url; @@ -50,12 +60,8 @@ public void setUrl(final URL url) { } @Override - public boolean equals(Object obj) { - if (!(obj instanceof RuntimeComponent)) { - return false; - } - - return id.equals(((RuntimeComponent) obj).id); + public boolean equals(final Object obj) { + return obj instanceof RuntimeComponent && id.equals(((RuntimeComponent) obj).id); } @Override diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java index f80eb33..c300317 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java @@ -28,7 +28,6 @@ * @author Alexandre Lagane - Linagora */ public class RuntimeContainer { - private final String id; private int port; @@ -39,12 +38,28 @@ public class RuntimeContainer { private String hostname; - private Map serviceUnits = new HashMap(); - - private Map components = new HashMap(); - + private final Map serviceUnits = new HashMap<>(); + + private final Map components = new HashMap<>(); + + /** + * + * @param id + * must not be null + * @param port + * @param user + * must not be null + * @param password + * must not be null + * @param hostname + * must not be null + */ public RuntimeContainer(final String id, final int port, final String user, final String password, final String hostname) { + assert id != null; + assert user != null; + assert password != null; + assert hostname != null; this.id = id; this.port = port; this.user = user; @@ -72,7 +87,13 @@ public String getHostname() { return hostname; } + /** + * + * @param hostname + * must not be null + */ public void setHostname(final String hostname) { + assert hostname != null; this.hostname = hostname; } @@ -80,7 +101,15 @@ public RuntimeServiceUnit getServiceUnit(final String id) { return serviceUnits.get(id); } + /** + * + * @param serviceUnit + * must not be null + * @throws RuntimeModelException + * Service unit is already in the list + */ public void addServiceUnit(final RuntimeServiceUnit serviceUnit) throws RuntimeModelException { + assert serviceUnit != null; if (serviceUnits.put(serviceUnit.getId(), serviceUnit) != null) { throw new RuntimeModelException("Service unit " + serviceUnit.getId() + " is already in the list"); } @@ -90,7 +119,15 @@ public Collection getServiceUnits() { return serviceUnits.values(); } + /** + * + * @param component + * must not be null + * @throws RuntimeModelException + * Component is already in the list + */ public void addComponent(final RuntimeComponent component) throws RuntimeModelException { + assert component != null; if (components.put(component.getId(), component) != null) { throw new RuntimeModelException("Component " + component.getId() + " is already in the list"); } @@ -105,12 +142,8 @@ public Collection getComponents() { } @Override - public boolean equals(Object obj) { - if (!(obj instanceof RuntimeContainer)) { - return false; - } - - return id.equals(((RuntimeContainer) obj).id); + public boolean equals(final Object obj) { + return obj instanceof RuntimeContainer && id.equals(((RuntimeContainer) obj).id); } @Override diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java index 4972e1a..59c7759 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java @@ -26,8 +26,7 @@ * @author Alexandre Lagane - Linagora */ public class RuntimeModel { - - private Map containers = new HashMap(); + private final Map containers = new HashMap<>(); public void addContainer(final RuntimeContainer container) throws RuntimeModelException { if (containers.put(container.getId(), container) != null) { @@ -46,7 +45,7 @@ public Collection getContainers() { public static class RuntimeModelException extends Exception { private static final long serialVersionUID = -4775138643228668670L; - public RuntimeModelException(String message) { + public RuntimeModelException(final String message) { super(message); } } diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java index 4c8c39f..40f2caf 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java @@ -24,15 +24,24 @@ * @author Alexandre Lagane - Linagora */ public class RuntimeServiceUnit { - private final String id; private URL url; + /** + * + * @param id + * must not be null + */ public RuntimeServiceUnit(final String id) { this.id = id; } + /** + * + * @param id + * must not be null + */ public RuntimeServiceUnit(final String id, final URL url) { this(id); this.url = url; @@ -51,12 +60,8 @@ public void setUrl(final URL url) { } @Override - public boolean equals(Object obj) { - if (!(obj instanceof RuntimeServiceUnit)) { - return false; - } - - return id.equals(((RuntimeServiceUnit) obj).id); + public boolean equals(final Object obj) { + return obj instanceof RuntimeServiceUnit && id.equals(((RuntimeServiceUnit) obj).id); } @Override diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java b/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java index 9bd48b9..13c6351 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java +++ b/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java @@ -44,7 +44,7 @@ * @author Alexandre Lagane - Linagora */ public class ModelConverter { - public static RuntimeModel convertModelToRuntimeModel(Model model) + public static RuntimeModel convertModelToRuntimeModel(final Model model) throws MalformedURLException, RuntimeModelException { RuntimeModel runtimeModel = new RuntimeModel(); @@ -73,7 +73,7 @@ public static RuntimeModel convertModelToRuntimeModel(Model model) runtimeModel.addContainer(runtimeCont); ComponentRepository compRepo = model.getComponentRepository(); - Map compById = new HashMap(); + Map compById = new HashMap<>(); for (Component comp : compRepo.getComponent()) { compById.put(comp.getId(), comp); } @@ -84,7 +84,7 @@ public static RuntimeModel convertModelToRuntimeModel(Model model) } ServiceUnitModel suModel = model.getServiceUnitModel(); - Map suById = new HashMap(); + Map suById = new HashMap<>(); for (ServiceUnit su : suModel.getServiceUnit()) { suById.put(su.getId(), su); } diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java index 6b0bb92..9c6af70 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java +++ b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java @@ -19,27 +19,21 @@ package org.ow2.petals.deployer.utils; import java.io.File; -import java.io.IOException; import java.net.URL; import java.nio.file.Files; import java.util.logging.Logger; import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import javax.xml.transform.stream.StreamSource; import org.apache.commons.io.FileUtils; -import org.ow2.petals.admin.api.exception.ArtifactAdministrationException; -import org.ow2.petals.admin.api.exception.ContainerAdministrationException; -import org.ow2.petals.admin.api.exception.DuplicatedServiceException; -import org.ow2.petals.admin.api.exception.MissingServiceException; import org.ow2.petals.deployer.model.xml._1.Model; import org.ow2.petals.deployer.runtimemodel.RuntimeModel; -import org.ow2.petals.deployer.runtimemodel.RuntimeModel.RuntimeModelException; -import org.ow2.petals.jbi.descriptor.JBIDescriptorException; /** + * The main class used for deploying XML models. + * * @author Alexandre Lagane - Linagora */ public class ModelDeployer { @@ -50,13 +44,13 @@ public class ModelDeployer { public static final int CONNECTION_TIMEOUT = 5000; /** - * Read timeout in milliseconds to read model or artifacts from URL. + * Reading timeout in milliseconds to read model or artifacts from URL. */ public static final int READ_TIMEOUT = 5000; private static final Logger LOG = Logger.getLogger(ModelDeployer.class.getName()); - public static void deployModel(URL url) throws ModelDeployerException { + public static void deployModel(final URL url) throws ModelDeployerException { File modelFile; try { LOG.fine("Downloadind XML model"); @@ -80,9 +74,7 @@ public static void deployModel(URL url) throws ModelDeployerException { deployer.deployRuntimeModel(runtimeModel); - } catch (JAXBException | IOException | RuntimeModelException | DuplicatedServiceException - | MissingServiceException | JBIDescriptorException | ContainerAdministrationException - | ArtifactAdministrationException | RuntimeModelDeployerException e) { + } catch (Exception e) { throw new ModelDeployerException(e); } } diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java index 5d91a34..d292f45 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java @@ -30,7 +30,8 @@ */ public class RuntimeModelComparator { /** - * Compare two runtimes models. The URL are not checked. + * Compares two runtimes models. + * URLs are not checked. * * @param m1 * @param m2 @@ -40,7 +41,7 @@ public static boolean compareRuntimeModels(final RuntimeModel m1, final RuntimeM return compareRuntimeContainerMaps(m1, m2); } - private static boolean compareRuntimeComponentMaps(RuntimeContainer cont1, RuntimeContainer cont2) { + private static boolean compareRuntimeComponentMaps(final RuntimeContainer cont1, final RuntimeContainer cont2) { Collection compList1 = cont1.getComponents(); Collection compList2 = cont2.getComponents(); @@ -60,7 +61,7 @@ private static boolean compareRuntimeComponentMaps(RuntimeContainer cont1, Runti return true; } - private static boolean compareRuntimeContainerMaps(RuntimeModel m1, RuntimeModel m2) { + private static boolean compareRuntimeContainerMaps(final RuntimeModel m1, final RuntimeModel m2) { Collection contList1 = m1.getContainers(); Collection contList2 = m2.getContainers(); @@ -80,14 +81,14 @@ private static boolean compareRuntimeContainerMaps(RuntimeModel m1, RuntimeModel return true; } - private static boolean compareRuntimeContainers(RuntimeContainer cont1, RuntimeContainer cont2) { + private static boolean compareRuntimeContainers(final RuntimeContainer cont1, final RuntimeContainer cont2) { return cont1.getId().equals(cont2.getId()) && cont1.getPort() == cont2.getPort() && cont1.getUser().equals(cont2.getUser()) && cont1.getPassword().equals(cont2.getPassword()) && cont1.getHostname().equals(cont2.getHostname()) && compareRuntimeServiceUnitMaps(cont1, cont2) && compareRuntimeComponentMaps(cont1, cont2); } - private static boolean compareRuntimeServiceUnitMaps(RuntimeContainer cont1, RuntimeContainer cont2) { + private static boolean compareRuntimeServiceUnitMaps(final RuntimeContainer cont1, final RuntimeContainer cont2) { Collection suList1 = cont1.getServiceUnits(); Collection suList2 = cont2.getServiceUnits(); @@ -107,11 +108,11 @@ private static boolean compareRuntimeServiceUnitMaps(RuntimeContainer cont1, Run return true; } - private static boolean compareRuntimeServiceUnits(RuntimeServiceUnit su1, RuntimeServiceUnit su2) { + private static boolean compareRuntimeServiceUnits(final RuntimeServiceUnit su1, final RuntimeServiceUnit su2) { return su1.getId().equals(su2.getId()); } - private static boolean compareRuntimeComponents(RuntimeComponent comp1, RuntimeComponent comp2) { + private static boolean compareRuntimeComponents(final RuntimeComponent comp1, final RuntimeComponent comp2) { return comp1.getId().equals(comp2.getId()); } } diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java index 88bfe57..56de8be 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java @@ -58,15 +58,11 @@ public class RuntimeModelDeployer { private static final Logger LOG = Logger.getLogger(RuntimeModelDeployer.class.getName()); - private PetalsAdministration petalsAdmin; + private final PetalsAdministration petalsAdmin; - private ArtifactLifecycleFactory artifactLifecycleFactory; + private final ArtifactLifecycleFactory artifactLifecycleFactory; - private JBIDescriptorBuilder jdb; - - private Set deployedComponents = new HashSet(); - - private Set deployedServiceUnits = new HashSet(); + private final JBIDescriptorBuilder jdb; public RuntimeModelDeployer() throws DuplicatedServiceException, MissingServiceException, JBIDescriptorException { this(PetalsAdministrationFactory.getInstance().newPetalsAdministrationAPI(), null, @@ -74,15 +70,15 @@ public RuntimeModelDeployer() throws DuplicatedServiceException, MissingServiceE } - public RuntimeModelDeployer(PetalsAdministration petalsAdmin, ArtifactLifecycleFactory artifactLifecycleFactory, - JBIDescriptorBuilder jdb) { + public RuntimeModelDeployer(final PetalsAdministration petalsAdmin, + final ArtifactLifecycleFactory artifactLifecycleFactory, final JBIDescriptorBuilder jdb) { this.petalsAdmin = petalsAdmin; this.artifactLifecycleFactory = artifactLifecycleFactory != null ? artifactLifecycleFactory : petalsAdmin.newArtifactLifecycleFactory(); this.jdb = jdb; } - public void deployRuntimeModel(RuntimeModel model) + public void deployRuntimeModel(final RuntimeModel model) throws ConnectionFailedException, ContainerAdministrationException, ArtifactStartedException, ArtifactNotDeployedException, ArtifactNotFoundException, IOException, JBIDescriptorException, ArtifactAdministrationException, RuntimeModelDeployerException { @@ -98,14 +94,18 @@ public void deployRuntimeModel(RuntimeModel model) petalsAdmin.connect(hostname, port, user, password); + Set deployedComponents = new HashSet(); + Set deployedServiceUnits = new HashSet(); + for (RuntimeServiceUnit serviceUnit : serviceUnits) { - deployRuntimeServiceUnit(serviceUnit, model); + deployRuntimeServiceUnit(serviceUnit, model, deployedComponents, deployedServiceUnits); } LOG.fine("Model deployed"); } - private void deployRuntimeServiceUnit(RuntimeServiceUnit serviceUnit, RuntimeModel model) + private void deployRuntimeServiceUnit(final RuntimeServiceUnit serviceUnit, final RuntimeModel model, + final Set deployedComponents, final Set deployedServiceUnits) throws IOException, JBIDescriptorException, ArtifactStartedException, ArtifactNotDeployedException, ArtifactNotFoundException, ArtifactAdministrationException, RuntimeModelDeployerException { String suId = serviceUnit.getId(); @@ -145,7 +145,7 @@ private void deployRuntimeServiceUnit(RuntimeServiceUnit serviceUnit, RuntimeMod } } - private void deployRuntimeComponent(RuntimeComponent component) + private void deployRuntimeComponent(final RuntimeComponent component) throws IOException, JBIDescriptorException, ArtifactDeployedException, ArtifactAdministrationException { String compId = component.getId(); File compFile = Files.createTempFile(compId, "zip").toFile(); diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerException.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerException.java index bec34a2..dc74d94 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerException.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerException.java @@ -25,7 +25,7 @@ public class RuntimeModelDeployerException extends Exception { private static final long serialVersionUID = -3352449083809006549L; - public RuntimeModelDeployerException(String message) { + public RuntimeModelDeployerException(final String message) { super(message); } } diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java index db3340f..5367d54 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java @@ -42,15 +42,15 @@ public class RuntimeModelExporter { private static final Logger LOG = Logger.getLogger(RuntimeModelExporter.class.getName()); - private PetalsAdministration petalsAdmin; + private final PetalsAdministration petalsAdmin; - private ArtifactAdministration artifactAdmin; + private final ArtifactAdministration artifactAdmin; public RuntimeModelExporter() throws DuplicatedServiceException, MissingServiceException, JBIDescriptorException { this(PetalsAdministrationFactory.getInstance().newPetalsAdministrationAPI()); } - public RuntimeModelExporter(PetalsAdministration petalsAdmin) { + public RuntimeModelExporter(final PetalsAdministration petalsAdmin) { this.petalsAdmin = petalsAdmin; artifactAdmin = petalsAdmin.newArtifactAdministration(); } diff --git a/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeModelTest.java b/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeModelTest.java new file mode 100644 index 0000000..9f53f37 --- /dev/null +++ b/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeModelTest.java @@ -0,0 +1,29 @@ +/** + * Copyright (c) 2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.runtimemodel; + +import org.junit.Test; + +public class RuntimeModelTest { + + @Test + public void testAnnotations() { + } + +} diff --git a/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java b/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java index e68704a..6e1752f 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java @@ -38,8 +38,7 @@ public class ModelConverterTest { public void convertModelToRuntimeModel() throws Exception { Model model = ParseModelTest.generateTestModel(); - ModelConverter converter = new ModelConverter(); - RuntimeModel runtimeModel = converter.convertModelToRuntimeModel(model); + RuntimeModel runtimeModel = ModelConverter.convertModelToRuntimeModel(model); Collection containers = runtimeModel.getContainers(); assertEquals(1, containers.size()); diff --git a/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java b/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java index a81babe..3117bcd 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java @@ -20,7 +20,6 @@ import static org.junit.Assert.assertEquals; -import java.io.File; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; @@ -69,7 +68,7 @@ public class ParseModelTest { final public static State CONTAINER_STATE = State.REACHABLE; @Test - public void read() throws Exception { + public void parseModel() throws Exception { ObjectFactory of = new ObjectFactory(); Model model = generateTestModel(); @@ -85,7 +84,6 @@ public void read() throws Exception { marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(of.createModel(model), marshalledModelWriter); - marshaller.marshal(of.createModel(model), new File("model.xml")); Model unmarshalledModel = unmarshaller .unmarshal(new StreamSource(new StringReader(marshalledModelWriter.toString())), Model.class) diff --git a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java index f1ade0b..55afd63 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java @@ -81,7 +81,7 @@ public String format(LogRecord record) { } @Test - public void demoSoap() throws Exception { + public void deployDemoSoap() throws Exception { RuntimeModel model = new RuntimeModel(); initializeRuntimeModel(model); From 54eba4255e69e80235015fdac35dff3456945232 Mon Sep 17 00:00:00 2001 From: Alexandre Lagane Date: Tue, 22 Jan 2019 17:27:02 +0100 Subject: [PATCH 10/21] Replace exception with log warning --- .../petals/deployer/utils/RuntimeModelDeployer.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java index 56de8be..7dc15d6 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java @@ -121,12 +121,13 @@ private void deployRuntimeServiceUnit(final RuntimeServiceUnit serviceUnit, fina String compName = jbiSu.getTarget().getComponentName(); if (!deployedComponents.contains(compName)) { RuntimeComponent component = model.getContainers().iterator().next().getComponent(compName); - if (component == null) { - throw new RuntimeModelDeployerException("Component " + compName + " (needed by service unit " - + jbiSu.getIdentification().getName() + ") not found"); + if (component != null) { + deployRuntimeComponent(component); + deployedComponents.add(compName); + } else { + LOG.warning("Component " + compName + " (needed by service unit " + + jbiSu.getIdentification().getName() + ") not found in the model"); } - deployRuntimeComponent(component); - deployedComponents.add(compName); } } ServiceAssemblyLifecycle saLifecycle = artifactLifecycleFactory.createServiceAssemblyLifecycle( From 56915432c663e34bb7abe55c6cee1fa565bd1edb Mon Sep 17 00:00:00 2001 From: Alexandre Lagane Date: Tue, 22 Jan 2019 17:49:08 +0100 Subject: [PATCH 11/21] Add max and min occurs attributes on models xsd --- src/main/resources/bus-model.xsd | 12 ++++++------ src/main/resources/component-repository.xsd | 4 ++-- src/main/resources/model.xsd | 8 ++++---- src/main/resources/service-unit-model.xsd | 4 ++-- src/main/resources/topology-model.xsd | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main/resources/bus-model.xsd b/src/main/resources/bus-model.xsd index 14c9e37..ba3b96d 100644 --- a/src/main/resources/bus-model.xsd +++ b/src/main/resources/bus-model.xsd @@ -27,14 +27,14 @@ - + The machines on which parts of a Petals ESB bus will be running. - + The list of Petals ESB busses to deploy. @@ -46,7 +46,7 @@ - + The instances of Petals ESB containers forming the Petals ESB bus. @@ -65,14 +65,14 @@ - + The component instances required by service units. - + The service unit instances to deploy on the container. @@ -144,7 +144,7 @@ - + Hostname, IP address or deployment property name of the provisioned machine. diff --git a/src/main/resources/component-repository.xsd b/src/main/resources/component-repository.xsd index a47510a..b9bab6f 100644 --- a/src/main/resources/component-repository.xsd +++ b/src/main/resources/component-repository.xsd @@ -22,7 +22,7 @@ - + The list of components of this repository. @@ -34,7 +34,7 @@ - + The URL of the associated archive. diff --git a/src/main/resources/model.xsd b/src/main/resources/model.xsd index 4265559..6a716be 100644 --- a/src/main/resources/model.xsd +++ b/src/main/resources/model.xsd @@ -40,7 +40,7 @@ - + This model defines a set of service units to deploy on your Petals ESB bus. This model @@ -49,7 +49,7 @@ - + This model defines a set of binding components, service engines and shared libraries that @@ -58,7 +58,7 @@ - + This model defines a set of topologies, used by Petals ESB buses. This model will be @@ -66,7 +66,7 @@ - + This model defines your Petals ESB bus placing Petals ESB components on their containers: diff --git a/src/main/resources/service-unit-model.xsd b/src/main/resources/service-unit-model.xsd index 648c0ce..d658f67 100644 --- a/src/main/resources/service-unit-model.xsd +++ b/src/main/resources/service-unit-model.xsd @@ -27,7 +27,7 @@ - + The list of service units to deploy. There must be at least one service unit in the model. @@ -39,7 +39,7 @@ - + The map of placeholder required by the service unit. The key of the map is the key of the diff --git a/src/main/resources/topology-model.xsd b/src/main/resources/topology-model.xsd index 103d8e2..10a929d 100644 --- a/src/main/resources/topology-model.xsd +++ b/src/main/resources/topology-model.xsd @@ -22,7 +22,7 @@ - + The list of topologies in the model. Their id must be unique in the model. There must be @@ -35,7 +35,7 @@ - + Petals ESB containers of the topology. Their id must be unique in the topology. There must From 5fa7d66bf82b6f5e471bd435b1858ad7aa2190aa Mon Sep 17 00:00:00 2001 From: Alexandre Lagane Date: Mon, 28 Jan 2019 09:37:31 +0100 Subject: [PATCH 12/21] Improve Javadoc and remove empty test --- .../runtimemodel/RuntimeComponent.java | 4 +-- .../runtimemodel/RuntimeContainer.java | 14 ++++----- .../runtimemodel/RuntimeServiceUnit.java | 4 +-- .../utils/RuntimeModelComparator.java | 8 ++--- .../runtimemodel/RuntimeModelTest.java | 29 ------------------- 5 files changed, 15 insertions(+), 44 deletions(-) delete mode 100644 src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeModelTest.java diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java index c332b21..4b90a90 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java @@ -31,7 +31,7 @@ public class RuntimeComponent { /** * * @param id - * must not be null + * must not be {code null} */ public RuntimeComponent(final String id) { this.id = id; @@ -40,7 +40,7 @@ public RuntimeComponent(final String id) { /** * * @param id - * must not be null + * must not be {code null} */ public RuntimeComponent(final String id, final URL url) { this(id); diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java index c300317..319a051 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java @@ -45,14 +45,14 @@ public class RuntimeContainer { /** * * @param id - * must not be null + * must not be {code null} * @param port * @param user - * must not be null + * must not be {code null} * @param password - * must not be null + * must not be {code null} * @param hostname - * must not be null + * must not be {code null} */ public RuntimeContainer(final String id, final int port, final String user, final String password, final String hostname) { @@ -90,7 +90,7 @@ public String getHostname() { /** * * @param hostname - * must not be null + * must not be {code null} */ public void setHostname(final String hostname) { assert hostname != null; @@ -104,7 +104,7 @@ public RuntimeServiceUnit getServiceUnit(final String id) { /** * * @param serviceUnit - * must not be null + * must not be {code null} * @throws RuntimeModelException * Service unit is already in the list */ @@ -122,7 +122,7 @@ public Collection getServiceUnits() { /** * * @param component - * must not be null + * must not be {code null} * @throws RuntimeModelException * Component is already in the list */ diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java index 40f2caf..ec25668 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java @@ -31,7 +31,7 @@ public class RuntimeServiceUnit { /** * * @param id - * must not be null + * must not be {code null} */ public RuntimeServiceUnit(final String id) { this.id = id; @@ -40,7 +40,7 @@ public RuntimeServiceUnit(final String id) { /** * * @param id - * must not be null + * must not be {code null} */ public RuntimeServiceUnit(final String id, final URL url) { this(id); diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java index d292f45..60df53b 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java @@ -46,14 +46,14 @@ private static boolean compareRuntimeComponentMaps(final RuntimeContainer cont1, Collection compList2 = cont2.getComponents(); for (RuntimeComponent comp1 : compList1) { - RuntimeComponent comp2 = cont1.getComponent(comp1.getId()); + RuntimeComponent comp2 = cont2.getComponent(comp1.getId()); if (comp2 == null || !compareRuntimeComponents(comp1, comp2)) { return false; } } for (RuntimeComponent comp2 : compList2) { - if (cont2.getComponent(comp2.getId()) == null) { + if (cont1.getComponent(comp2.getId()) == null) { return false; } } @@ -66,14 +66,14 @@ private static boolean compareRuntimeContainerMaps(final RuntimeModel m1, final Collection contList2 = m2.getContainers(); for (RuntimeContainer cont1 : contList1) { - RuntimeContainer cont2 = m1.getContainer(cont1.getId()); + RuntimeContainer cont2 = m2.getContainer(cont1.getId()); if (cont2 == null || !compareRuntimeContainers(cont1, cont2)) { return false; } } for (RuntimeContainer cont2 : contList2) { - if (m2.getContainer(cont2.getId()) == null) { + if (m1.getContainer(cont2.getId()) == null) { return false; } } diff --git a/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeModelTest.java b/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeModelTest.java deleted file mode 100644 index 9f53f37..0000000 --- a/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeModelTest.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright (c) 2019 Linagora - * - * This program/library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 2.1 of the License, or (at your - * option) any later version. - * - * This program/library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program/library; If not, see http://www.gnu.org/licenses/ - * for the GNU Lesser General Public License version 2.1. - */ - -package org.ow2.petals.deployer.runtimemodel; - -import org.junit.Test; - -public class RuntimeModelTest { - - @Test - public void testAnnotations() { - } - -} From 636fa17535ce21a8c088f4cfd02adae4ea6ca99b Mon Sep 17 00:00:00 2001 From: Alexandre Lagane Date: Mon, 28 Jan 2019 16:24:52 +0100 Subject: [PATCH 13/21] Refactors --- .../petals/deployer/utils/ModelDeployer.java | 19 ++- .../deployer/utils/ModelConverterTest.java | 2 +- .../ow2/petals/deployer/utils/ModelUtils.java | 116 ++++++++++++++++++ .../petals/deployer/utils/ParseModelTest.java | 110 +---------------- .../utils/RuntimeModelComparatorTest.java | 18 +++ .../utils/RuntimeModelDeployerTest.java | 2 +- 6 files changed, 151 insertions(+), 116 deletions(-) create mode 100644 src/test/java/org/ow2/petals/deployer/utils/ModelUtils.java create mode 100644 src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java index 9c6af70..e3558b8 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java +++ b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java @@ -24,6 +24,7 @@ import java.util.logging.Logger; import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import javax.xml.transform.stream.StreamSource; @@ -50,6 +51,18 @@ public class ModelDeployer { private static final Logger LOG = Logger.getLogger(ModelDeployer.class.getName()); + private static final Unmarshaller UNMARSHALLER; + static { + Unmarshaller unmarshaller = null; + try { + JAXBContext jaxbContext = JAXBContext.newInstance(Model.class); + unmarshaller = jaxbContext.createUnmarshaller(); + } catch (JAXBException e) { + e.printStackTrace(); + } + UNMARSHALLER = unmarshaller; + } + public static void deployModel(final URL url) throws ModelDeployerException { File modelFile; try { @@ -60,11 +73,7 @@ public static void deployModel(final URL url) throws ModelDeployerException { LOG.fine("Parsing XML model"); - JAXBContext jaxbContext = JAXBContext.newInstance(Model.class); - - Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); - - Model model = unmarshaller.unmarshal(new StreamSource(modelFile), Model.class).getValue(); + Model model = UNMARSHALLER.unmarshal(new StreamSource(modelFile), Model.class).getValue(); RuntimeModel runtimeModel; runtimeModel = ModelConverter.convertModelToRuntimeModel(model); diff --git a/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java b/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java index 6e1752f..6e52ad0 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java @@ -36,7 +36,7 @@ public class ModelConverterTest { @Test public void convertModelToRuntimeModel() throws Exception { - Model model = ParseModelTest.generateTestModel(); + Model model = ModelUtils.generateTestModel(); RuntimeModel runtimeModel = ModelConverter.convertModelToRuntimeModel(model); diff --git a/src/test/java/org/ow2/petals/deployer/utils/ModelUtils.java b/src/test/java/org/ow2/petals/deployer/utils/ModelUtils.java new file mode 100644 index 0000000..ef7395a --- /dev/null +++ b/src/test/java/org/ow2/petals/deployer/utils/ModelUtils.java @@ -0,0 +1,116 @@ +package org.ow2.petals.deployer.utils; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URISyntaxException; +import java.util.List; + +import org.ow2.petals.deployer.model.bus.xml._1.Bus; +import org.ow2.petals.deployer.model.bus.xml._1.BusModel; +import org.ow2.petals.deployer.model.bus.xml._1.ComponentInstance; +import org.ow2.petals.deployer.model.bus.xml._1.ContainerInstance; +import org.ow2.petals.deployer.model.bus.xml._1.ProvisionedMachine; +import org.ow2.petals.deployer.model.bus.xml._1.ServiceUnitInstance; +import org.ow2.petals.deployer.model.component_repository.xml._1.Component; +import org.ow2.petals.deployer.model.component_repository.xml._1.ComponentRepository; +import org.ow2.petals.deployer.model.service_unit.xml._1.ServiceUnit; +import org.ow2.petals.deployer.model.service_unit.xml._1.ServiceUnitModel; +import org.ow2.petals.deployer.model.topology.xml._1.Container; +import org.ow2.petals.deployer.model.topology.xml._1.Topology; +import org.ow2.petals.deployer.model.topology.xml._1.TopologyModel; +import org.ow2.petals.deployer.model.xml._1.Model; + +public class ModelUtils { + + public static Model generateTestModel() throws MalformedURLException, IOException, URISyntaxException { + Model model = new Model(); + + /* Component Repository */ + + ComponentRepository compRepo = new ComponentRepository(); + model.setComponentRepository(compRepo); + + Component bcSoap = new Component(); + bcSoap.setId("petals-bc-soap"); + bcSoap.setUrl("file:/artifacts/petals-bc-soap-5.0.0"); + compRepo.getComponent().add(bcSoap); + + /* Service Unit Model */ + + ServiceUnitModel suModel = new ServiceUnitModel(); + model.setServiceUnitModel(suModel); + + List serviceUnits = suModel.getServiceUnit(); + + ServiceUnit suProv1 = new ServiceUnit(); + suProv1.setId("su-SOAP-Hello_Service1-provide"); + suProv1.setUrl("file:/artifacts/sa-SOAP-Hello_Service1-provide"); + serviceUnits.add(suProv1); + + ServiceUnit suProv2 = new ServiceUnit(); + suProv2.setId("su-SOAP-Hello_Service2-provide"); + suProv2.setUrl("file:/artifacts/sa-SOAP-Hello_Service2-provide"); + serviceUnits.add(suProv2); + + ServiceUnit suCons = new ServiceUnit(); + suCons.setId("su-SOAP-Hello_PortType-consume"); + suCons.setUrl("file:/artifacts/sa-SOAP-Hello_PortType-consume"); + serviceUnits.add(suCons); + + /* Topology Model */ + + TopologyModel topoModel = new TopologyModel(); + model.setTopologyModel(topoModel); + + Topology topo = new Topology(); + topo.setId("topo1"); + topoModel.getTopology().add(topo); + + Container cont = new Container(); + cont.setId(ParseModelTest.CONTAINER_NAME); + cont.setDefaultJmxPort(ParseModelTest.CONTAINER_JMX_PORT); + cont.setDefaultJmxUser(ParseModelTest.CONTAINER_USER); + cont.setDefaultJmxPassword(ParseModelTest.CONTAINER_PWD); + topo.getContainer().add(cont); + + /* Bus Model */ + + BusModel busModel = new BusModel(); + model.setBusModel(busModel); + + ProvisionedMachine machine = new ProvisionedMachine(); + machine.setId("main"); + machine.setHostname("localhost"); + busModel.getMachine().add(machine); + + Bus bus = new Bus(); + bus.setTopologyRef(topo.getId()); + busModel.getBus().add(bus); + + ContainerInstance contInst = new ContainerInstance(); + contInst.setRef(cont.getId()); + contInst.setMachineRef(machine.getId()); + bus.getContainerInstance().add(contInst); + + ComponentInstance bcSoapInst = new ComponentInstance(); + bcSoapInst.setRef(bcSoap.getId()); + contInst.getComponentInstance().add(bcSoapInst); + + List suInstances = contInst.getServiceUnitInstance(); + + ServiceUnitInstance suInst = new ServiceUnitInstance(); + suInst.setRef(suProv1.getId()); + suInstances.add(suInst); + + suInst = new ServiceUnitInstance(); + suInst.setRef(suProv2.getId()); + suInstances.add(suInst); + + suInst = new ServiceUnitInstance(); + suInst.setRef(suCons.getId()); + suInstances.add(suInst); + + return model; + } + +} diff --git a/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java b/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java index 3117bcd..1c720e7 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java @@ -20,12 +20,8 @@ import static org.junit.Assert.assertEquals; -import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; -import java.net.MalformedURLException; -import java.net.URISyntaxException; -import java.util.List; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; @@ -34,19 +30,6 @@ import org.junit.Test; import org.ow2.petals.admin.topology.Container.State; -import org.ow2.petals.deployer.model.bus.xml._1.Bus; -import org.ow2.petals.deployer.model.bus.xml._1.BusModel; -import org.ow2.petals.deployer.model.bus.xml._1.ComponentInstance; -import org.ow2.petals.deployer.model.bus.xml._1.ContainerInstance; -import org.ow2.petals.deployer.model.bus.xml._1.ProvisionedMachine; -import org.ow2.petals.deployer.model.bus.xml._1.ServiceUnitInstance; -import org.ow2.petals.deployer.model.component_repository.xml._1.Component; -import org.ow2.petals.deployer.model.component_repository.xml._1.ComponentRepository; -import org.ow2.petals.deployer.model.service_unit.xml._1.ServiceUnit; -import org.ow2.petals.deployer.model.service_unit.xml._1.ServiceUnitModel; -import org.ow2.petals.deployer.model.topology.xml._1.Container; -import org.ow2.petals.deployer.model.topology.xml._1.Topology; -import org.ow2.petals.deployer.model.topology.xml._1.TopologyModel; import org.ow2.petals.deployer.model.xml._1.Model; import org.ow2.petals.deployer.model.xml._1.ObjectFactory; @@ -71,7 +54,7 @@ public class ParseModelTest { public void parseModel() throws Exception { ObjectFactory of = new ObjectFactory(); - Model model = generateTestModel(); + Model model = ModelUtils.generateTestModel(); StringWriter marshalledModelWriter = new StringWriter(); StringWriter unmarshalledModelWriter = new StringWriter(); @@ -93,95 +76,4 @@ public void parseModel() throws Exception { assertEquals(marshalledModelWriter.toString(), unmarshalledModelWriter.toString()); } - - public static Model generateTestModel() throws MalformedURLException, IOException, URISyntaxException { - Model model = new Model(); - - /* Component Repository */ - - ComponentRepository compRepo = new ComponentRepository(); - model.setComponentRepository(compRepo); - - Component bcSoap = new Component(); - bcSoap.setId("petals-bc-soap"); - bcSoap.setUrl("file:/artifacts/petals-bc-soap-5.0.0"); - compRepo.getComponent().add(bcSoap); - - /* Service Unit Model */ - - ServiceUnitModel suModel = new ServiceUnitModel(); - model.setServiceUnitModel(suModel); - - List serviceUnits = suModel.getServiceUnit(); - - ServiceUnit suProv1 = new ServiceUnit(); - suProv1.setId("su-SOAP-Hello_Service1-provide"); - suProv1.setUrl("file:/artifacts/sa-SOAP-Hello_Service1-provide"); - serviceUnits.add(suProv1); - - ServiceUnit suProv2 = new ServiceUnit(); - suProv2.setId("su-SOAP-Hello_Service2-provide"); - suProv2.setUrl("file:/artifacts/sa-SOAP-Hello_Service2-provide"); - serviceUnits.add(suProv2); - - ServiceUnit suCons = new ServiceUnit(); - suCons.setId("su-SOAP-Hello_PortType-consume"); - suCons.setUrl("file:/artifacts/sa-SOAP-Hello_PortType-consume"); - serviceUnits.add(suCons); - - /* Topology Model */ - - TopologyModel topoModel = new TopologyModel(); - model.setTopologyModel(topoModel); - - Topology topo = new Topology(); - topo.setId("topo1"); - topoModel.getTopology().add(topo); - - Container cont = new Container(); - cont.setId(CONTAINER_NAME); - cont.setDefaultJmxPort(CONTAINER_JMX_PORT); - cont.setDefaultJmxUser(CONTAINER_USER); - cont.setDefaultJmxPassword(CONTAINER_PWD); - topo.getContainer().add(cont); - - /* Bus Model */ - - BusModel busModel = new BusModel(); - model.setBusModel(busModel); - - ProvisionedMachine machine = new ProvisionedMachine(); - machine.setId("main"); - machine.setHostname("localhost"); - busModel.getMachine().add(machine); - - Bus bus = new Bus(); - bus.setTopologyRef(topo.getId()); - busModel.getBus().add(bus); - - ContainerInstance contInst = new ContainerInstance(); - contInst.setRef(cont.getId()); - contInst.setMachineRef(machine.getId()); - bus.getContainerInstance().add(contInst); - - ComponentInstance bcSoapInst = new ComponentInstance(); - bcSoapInst.setRef(bcSoap.getId()); - contInst.getComponentInstance().add(bcSoapInst); - - List suInstances = contInst.getServiceUnitInstance(); - - ServiceUnitInstance suInst = new ServiceUnitInstance(); - suInst.setRef(suProv1.getId()); - suInstances.add(suInst); - - suInst = new ServiceUnitInstance(); - suInst.setRef(suProv2.getId()); - suInstances.add(suInst); - - suInst = new ServiceUnitInstance(); - suInst.setRef(suCons.getId()); - suInstances.add(suInst); - - return model; - } } diff --git a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java new file mode 100644 index 0000000..8f83b7e --- /dev/null +++ b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java @@ -0,0 +1,18 @@ +package org.ow2.petals.deployer.utils; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URISyntaxException; + +import org.junit.Test; +import org.ow2.petals.deployer.model.xml._1.Model; + +public class RuntimeModelComparatorTest { + + @Test + public void equivalentModels() throws MalformedURLException, IOException, URISyntaxException { + Model model = ModelUtils.generateTestModel(); + + } + +} diff --git a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java index 55afd63..55647ea 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java @@ -97,7 +97,7 @@ public void deployDemoSoap() throws Exception { RuntimeModel exportedModel = modelExporter.exportRuntimeModel(CONTAINER_HOST, CONTAINER_JMX_PORT, CONTAINER_USER, CONTAINER_PWD, null); - assertTrue(RuntimeModelComparator.compareRuntimeModels(model, exportedModel)); + assertTrue(RuntimeModelComparator.compareRuntimeModelsWithoutUrls(model, exportedModel)); } private org.ow2.petals.admin.topology.Container createContainerSample() { From 78eaf0a5c95807ac471283541dc4a7f0b7022d85 Mon Sep 17 00:00:00 2001 From: Alexandre Lagane Date: Tue, 29 Jan 2019 11:47:05 +0100 Subject: [PATCH 14/21] Refactor test & test runtime model comparator --- .../runtimemodel/RuntimeModelException.java | 7 +++ .../petals/deployer/utils/ModelDeployer.java | 35 ++++++++---- .../utils/RuntimeModelComparator.java | 4 +- .../deployer/utils/ModelConverterTest.java | 10 ++-- .../ow2/petals/deployer/utils/ModelUtils.java | 50 +++++++++++++++-- .../petals/deployer/utils/ParseModelTest.java | 13 ----- .../utils/RuntimeModelComparatorTest.java | 56 +++++++++++++++++-- .../utils/RuntimeModelDeployerTest.java | 28 +++------- 8 files changed, 141 insertions(+), 62 deletions(-) create mode 100644 src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModelException.java diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModelException.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModelException.java new file mode 100644 index 0000000..933717f --- /dev/null +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModelException.java @@ -0,0 +1,7 @@ +package org.ow2.petals.deployer.runtimemodel; + +public class RuntimeModelException extends Exception { + public static class DuplicatedServiceUnitException extends RuntimeModelException { + RuntimeModelException.DuplicatedServiceUnitException e; + } +} diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java index e3558b8..8988df0 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java +++ b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java @@ -24,7 +24,6 @@ import java.util.logging.Logger; import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import javax.xml.transform.stream.StreamSource; @@ -32,6 +31,8 @@ import org.ow2.petals.deployer.model.xml._1.Model; import org.ow2.petals.deployer.runtimemodel.RuntimeModel; +import com.ebmwebsourcing.easycommons.lang.UncheckedException; + /** * The main class used for deploying XML models. * @@ -53,16 +54,30 @@ public class ModelDeployer { private static final Unmarshaller UNMARSHALLER; static { - Unmarshaller unmarshaller = null; try { JAXBContext jaxbContext = JAXBContext.newInstance(Model.class); - unmarshaller = jaxbContext.createUnmarshaller(); - } catch (JAXBException e) { - e.printStackTrace(); + UNMARSHALLER = jaxbContext.createUnmarshaller(); + } catch (Exception e) { + throw new UncheckedException(e); } - UNMARSHALLER = unmarshaller; } + private static final RuntimeModelDeployer DEPLOYER; + static { + try { + DEPLOYER = new RuntimeModelDeployer(); + } catch (Exception e) { + throw new UncheckedException(e); + } + } + + /** + * Download and deploy the model at the url. The model must be an XML model with XSD {code model.xsd} in resources + * directory. + * + * @param url + * @throws ModelDeployerException + */ public static void deployModel(final URL url) throws ModelDeployerException { File modelFile; try { @@ -75,13 +90,9 @@ public static void deployModel(final URL url) throws ModelDeployerException { Model model = UNMARSHALLER.unmarshal(new StreamSource(modelFile), Model.class).getValue(); - RuntimeModel runtimeModel; - runtimeModel = ModelConverter.convertModelToRuntimeModel(model); - - RuntimeModelDeployer deployer; - deployer = new RuntimeModelDeployer(); + RuntimeModel runtimeModel = ModelConverter.convertModelToRuntimeModel(model); - deployer.deployRuntimeModel(runtimeModel); + DEPLOYER.deployRuntimeModel(runtimeModel); } catch (Exception e) { throw new ModelDeployerException(e); diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java index 60df53b..3bd5eb5 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java @@ -93,14 +93,14 @@ private static boolean compareRuntimeServiceUnitMaps(final RuntimeContainer cont Collection suList2 = cont2.getServiceUnits(); for (RuntimeServiceUnit su1 : suList1) { - RuntimeServiceUnit su2 = cont1.getServiceUnit(su1.getId()); + RuntimeServiceUnit su2 = cont2.getServiceUnit(su1.getId()); if (su2 == null || !compareRuntimeServiceUnits(su1, su2)) { return false; } } for (RuntimeServiceUnit su2 : suList2) { - if (cont2.getServiceUnit(su2.getId()) == null) { + if (cont1.getServiceUnit(su2.getId()) == null) { return false; } } diff --git a/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java b/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java index 6e52ad0..6c8341d 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java @@ -44,11 +44,11 @@ public void convertModelToRuntimeModel() throws Exception { assertEquals(1, containers.size()); RuntimeContainer cont = containers.iterator().next(); - assertEquals(ParseModelTest.CONTAINER_NAME, cont.getId()); - assertEquals(ParseModelTest.CONTAINER_HOST, cont.getHostname()); - assertEquals(ParseModelTest.CONTAINER_JMX_PORT, cont.getPort()); - assertEquals(ParseModelTest.CONTAINER_USER, cont.getUser()); - assertEquals(ParseModelTest.CONTAINER_PWD, cont.getPassword()); + assertEquals(ModelUtils.CONTAINER_NAME, cont.getId()); + assertEquals(ModelUtils.CONTAINER_HOST, cont.getHostname()); + assertEquals(ModelUtils.CONTAINER_JMX_PORT, cont.getPort()); + assertEquals(ModelUtils.CONTAINER_USER, cont.getUser()); + assertEquals(ModelUtils.CONTAINER_PWD, cont.getPassword()); Collection serviceUnits = cont.getServiceUnits(); assertEquals(3, serviceUnits.size()); diff --git a/src/test/java/org/ow2/petals/deployer/utils/ModelUtils.java b/src/test/java/org/ow2/petals/deployer/utils/ModelUtils.java index ef7395a..f73cdbb 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/ModelUtils.java +++ b/src/test/java/org/ow2/petals/deployer/utils/ModelUtils.java @@ -3,8 +3,10 @@ import java.io.IOException; import java.net.MalformedURLException; import java.net.URISyntaxException; +import java.net.URL; import java.util.List; +import org.ow2.petals.admin.topology.Container.State; import org.ow2.petals.deployer.model.bus.xml._1.Bus; import org.ow2.petals.deployer.model.bus.xml._1.BusModel; import org.ow2.petals.deployer.model.bus.xml._1.ComponentInstance; @@ -19,9 +21,27 @@ import org.ow2.petals.deployer.model.topology.xml._1.Topology; import org.ow2.petals.deployer.model.topology.xml._1.TopologyModel; import org.ow2.petals.deployer.model.xml._1.Model; +import org.ow2.petals.deployer.runtimemodel.RuntimeComponent; +import org.ow2.petals.deployer.runtimemodel.RuntimeContainer; +import org.ow2.petals.deployer.runtimemodel.RuntimeModel; +import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit; + +import com.ebmwebsourcing.easycommons.lang.UncheckedException; public class ModelUtils { + final public static String CONTAINER_NAME = "sample-0"; + + final public static String CONTAINER_HOST = "localhost"; + + final public static int CONTAINER_JMX_PORT = 7700; + + final public static String CONTAINER_USER = "petals"; + + final public static String CONTAINER_PWD = "petals"; + + final public static State CONTAINER_STATE = State.REACHABLE; + public static Model generateTestModel() throws MalformedURLException, IOException, URISyntaxException { Model model = new Model(); @@ -67,10 +87,10 @@ public static Model generateTestModel() throws MalformedURLException, IOExceptio topoModel.getTopology().add(topo); Container cont = new Container(); - cont.setId(ParseModelTest.CONTAINER_NAME); - cont.setDefaultJmxPort(ParseModelTest.CONTAINER_JMX_PORT); - cont.setDefaultJmxUser(ParseModelTest.CONTAINER_USER); - cont.setDefaultJmxPassword(ParseModelTest.CONTAINER_PWD); + cont.setId(CONTAINER_NAME); + cont.setDefaultJmxPort(CONTAINER_JMX_PORT); + cont.setDefaultJmxUser(CONTAINER_USER); + cont.setDefaultJmxPassword(CONTAINER_PWD); topo.getContainer().add(cont); /* Bus Model */ @@ -113,4 +133,26 @@ public static Model generateTestModel() throws MalformedURLException, IOExceptio return model; } + public static RuntimeModel generateTestRuntimeModel() { + try { + RuntimeModel model = new RuntimeModel(); + + RuntimeContainer cont = new RuntimeContainer(CONTAINER_NAME, CONTAINER_JMX_PORT, CONTAINER_USER, + CONTAINER_PWD, CONTAINER_HOST); + model.addContainer(cont); + + cont.addServiceUnit(new RuntimeServiceUnit("su-SOAP-Hello_Service1-provide", + new URL("file:/artifacts/sa-SOAP-Hello_Service1-provide"))); + cont.addServiceUnit(new RuntimeServiceUnit("su-SOAP-Hello_Service2-provide", + new URL("file:/artifacts/sa-SOAP-Hello_Service2-provide"))); + cont.addServiceUnit(new RuntimeServiceUnit("su-SOAP-Hello_PortType-consume", + new URL("file:/artifacts/sa-SOAP-Hello_PortType-consume"))); + + cont.addComponent(new RuntimeComponent("petals-bc-soap", new URL("file:/artifacts/petals-bc-soap-5.0.0"))); + + return model; + } catch (Exception e) { + throw new UncheckedException(e); + } + } } diff --git a/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java b/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java index 1c720e7..38895c2 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java @@ -29,7 +29,6 @@ import javax.xml.transform.stream.StreamSource; import org.junit.Test; -import org.ow2.petals.admin.topology.Container.State; import org.ow2.petals.deployer.model.xml._1.Model; import org.ow2.petals.deployer.model.xml._1.ObjectFactory; @@ -38,18 +37,6 @@ */ public class ParseModelTest { - final public static String CONTAINER_NAME = "sample-0"; - - final public static String CONTAINER_HOST = "localhost"; - - final public static int CONTAINER_JMX_PORT = 7700; - - final public static String CONTAINER_USER = "petals"; - - final public static String CONTAINER_PWD = "petals"; - - final public static State CONTAINER_STATE = State.REACHABLE; - @Test public void parseModel() throws Exception { ObjectFactory of = new ObjectFactory(); diff --git a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java index 8f83b7e..1f214fe 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java @@ -1,18 +1,62 @@ package org.ow2.petals.deployer.utils; -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URISyntaxException; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.net.URL; import org.junit.Test; -import org.ow2.petals.deployer.model.xml._1.Model; +import org.ow2.petals.deployer.runtimemodel.RuntimeComponent; +import org.ow2.petals.deployer.runtimemodel.RuntimeContainer; +import org.ow2.petals.deployer.runtimemodel.RuntimeModel; +import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit; public class RuntimeModelComparatorTest { @Test - public void equivalentModels() throws MalformedURLException, IOException, URISyntaxException { - Model model = ModelUtils.generateTestModel(); + public void equivalentRuntimeModels() throws Exception { + RuntimeModel model = ModelUtils.generateTestRuntimeModel(); + + RuntimeModel equivalentModel = ModelUtils.generateTestRuntimeModel(); + + assertTrue(RuntimeModelComparator.compareRuntimeModels(model, equivalentModel)); + assertTrue(RuntimeModelComparator.compareRuntimeModels(equivalentModel, model)); + } + + @Test + public void differentServiceUnitListsRuntimeModels() throws Exception { + RuntimeModel model = ModelUtils.generateTestRuntimeModel(); + + RuntimeModel modelWithDifferentServiceUnitList = ModelUtils.generateTestRuntimeModel(); + modelWithDifferentServiceUnitList.getContainers().iterator().next() + .addServiceUnit(new RuntimeServiceUnit("my-test-su", new URL("file:/artifact/my-test-su.zip"))); + + assertFalse(RuntimeModelComparator.compareRuntimeModels(model, modelWithDifferentServiceUnitList)); + assertFalse(RuntimeModelComparator.compareRuntimeModels(modelWithDifferentServiceUnitList, model)); + } + + @Test + public void differentComponentListsRuntimeModels() throws Exception { + RuntimeModel model = ModelUtils.generateTestRuntimeModel(); + + RuntimeModel modelWithDifferentComponentList = ModelUtils.generateTestRuntimeModel(); + modelWithDifferentComponentList.getContainers().iterator().next() + .addComponent(new RuntimeComponent("my-test-comp", new URL("file:/artifact/my-test-comp.zip"))); + assertFalse(RuntimeModelComparator.compareRuntimeModels(model, modelWithDifferentComponentList)); + assertFalse(RuntimeModelComparator.compareRuntimeModels(modelWithDifferentComponentList, model)); } + @Test + public void differentContainersRuntimeModels() throws Exception { + RuntimeModel model = ModelUtils.generateTestRuntimeModel(); + + RuntimeModel modelWithDifferentContainer = ModelUtils.generateTestRuntimeModel(); + modelWithDifferentContainer.getContainers().clear(); + RuntimeContainer differentCont = new RuntimeContainer("different-cont", 7700, "other", "azerty", "localhost"); + modelWithDifferentContainer.addContainer(differentCont); + + assertFalse(RuntimeModelComparator.compareRuntimeModels(model, modelWithDifferentContainer)); + assertFalse(RuntimeModelComparator.compareRuntimeModels(modelWithDifferentContainer, model)); + } } diff --git a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java index 55647ea..e302bd0 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java @@ -35,7 +35,6 @@ import org.ow2.petals.admin.junit.ArtifactLifecycleFactoryMock; import org.ow2.petals.admin.junit.PetalsAdministrationApi; import org.ow2.petals.admin.topology.Container.PortType; -import org.ow2.petals.admin.topology.Container.State; import org.ow2.petals.deployer.runtimemodel.RuntimeComponent; import org.ow2.petals.deployer.runtimemodel.RuntimeContainer; import org.ow2.petals.deployer.runtimemodel.RuntimeModel; @@ -46,17 +45,6 @@ * @author Alexandre Lagane - Linagora */ public class RuntimeModelDeployerTest { - final public static String CONTAINER_NAME = "sample-0"; - - final public static String CONTAINER_HOST = "localhost"; - - final public static int CONTAINER_JMX_PORT = 7700; - - final public static String CONTAINER_USER = "petals"; - - final public static String CONTAINER_PWD = "petals"; - - final public static State CONTAINER_STATE = State.REACHABLE; @Rule public PetalsAdministrationApi petalsAdminApiRule = new PetalsAdministrationApi(); @@ -94,23 +82,23 @@ public void deployDemoSoap() throws Exception { modelDeployer.deployRuntimeModel(model); RuntimeModelExporter modelExporter = new RuntimeModelExporter(); - RuntimeModel exportedModel = modelExporter.exportRuntimeModel(CONTAINER_HOST, CONTAINER_JMX_PORT, - CONTAINER_USER, CONTAINER_PWD, null); + RuntimeModel exportedModel = modelExporter.exportRuntimeModel(ModelUtils.CONTAINER_HOST, + ModelUtils.CONTAINER_JMX_PORT, ModelUtils.CONTAINER_USER, ModelUtils.CONTAINER_PWD, null); - assertTrue(RuntimeModelComparator.compareRuntimeModelsWithoutUrls(model, exportedModel)); + assertTrue(RuntimeModelComparator.compareRuntimeModels(model, exportedModel)); } private org.ow2.petals.admin.topology.Container createContainerSample() { final Map ports = new HashMap<>(); - ports.put(PortType.JMX, CONTAINER_JMX_PORT); - return new org.ow2.petals.admin.topology.Container(CONTAINER_NAME, CONTAINER_HOST, ports, CONTAINER_USER, - CONTAINER_PWD, CONTAINER_STATE); + ports.put(PortType.JMX, ModelUtils.CONTAINER_JMX_PORT); + return new org.ow2.petals.admin.topology.Container(ModelUtils.CONTAINER_NAME, ModelUtils.CONTAINER_HOST, ports, + ModelUtils.CONTAINER_USER, ModelUtils.CONTAINER_PWD, ModelUtils.CONTAINER_STATE); } private void initializeRuntimeModel(RuntimeModel model) throws Exception { - RuntimeContainer cont = new RuntimeContainer(CONTAINER_NAME, CONTAINER_JMX_PORT, CONTAINER_USER, CONTAINER_PWD, - "localhost"); + RuntimeContainer cont = new RuntimeContainer(ModelUtils.CONTAINER_NAME, ModelUtils.CONTAINER_JMX_PORT, + ModelUtils.CONTAINER_USER, ModelUtils.CONTAINER_PWD, "localhost"); cont.addComponent(new RuntimeComponent("petals-bc-soap", ZipUtils.createZipFromResourceDirectory("artifacts/petals-bc-soap-5.0.0").toURI().toURL())); cont.addServiceUnit(new RuntimeServiceUnit("su-SOAP-Hello_Service1-provide", From 687cd9495fa34d9b77414b22f939876ed3aedfda Mon Sep 17 00:00:00 2001 From: Alexandre Lagane Date: Tue, 29 Jan 2019 14:54:09 +0100 Subject: [PATCH 15/21] RuntimeModel exceptions --- .../runtimemodel/RuntimeComponent.java | 1 + .../runtimemodel/RuntimeContainer.java | 15 +++++---- .../deployer/runtimemodel/RuntimeModel.java | 19 ++++++----- .../runtimemodel/RuntimeModelException.java | 7 ---- .../DuplicatedComponentException.java | 32 +++++++++++++++++++ .../DuplicatedContainerException.java | 32 +++++++++++++++++++ .../DuplicatedServiceUnitException.java | 32 +++++++++++++++++++ .../exceptions/RuntimeModelException.java | 31 ++++++++++++++++++ .../petals/deployer/utils/ModelConverter.java | 2 +- .../petals/deployer/utils/ModelDeployer.java | 6 ++-- .../deployer/utils/RuntimeModelExporter.java | 2 +- .../ow2/petals/deployer/utils/ModelUtils.java | 22 +++++++++++-- .../utils/RuntimeModelComparatorTest.java | 18 +++++++++++ 13 files changed, 186 insertions(+), 33 deletions(-) delete mode 100644 src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModelException.java create mode 100644 src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedComponentException.java create mode 100644 src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedContainerException.java create mode 100644 src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedServiceUnitException.java create mode 100644 src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/RuntimeModelException.java diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java index 4b90a90..f8b8719 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java @@ -41,6 +41,7 @@ public RuntimeComponent(final String id) { * * @param id * must not be {code null} + * @param url */ public RuntimeComponent(final String id, final URL url) { this(id); diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java index 319a051..c934283 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java @@ -22,7 +22,8 @@ import java.util.HashMap; import java.util.Map; -import org.ow2.petals.deployer.runtimemodel.RuntimeModel.RuntimeModelException; +import org.ow2.petals.deployer.runtimemodel.exceptions.DuplicatedComponentException; +import org.ow2.petals.deployer.runtimemodel.exceptions.DuplicatedServiceUnitException; /** * @author Alexandre Lagane - Linagora @@ -105,13 +106,13 @@ public RuntimeServiceUnit getServiceUnit(final String id) { * * @param serviceUnit * must not be {code null} - * @throws RuntimeModelException + * @throws DuplicatedServiceUnitException * Service unit is already in the list */ - public void addServiceUnit(final RuntimeServiceUnit serviceUnit) throws RuntimeModelException { + public void addServiceUnit(final RuntimeServiceUnit serviceUnit) throws DuplicatedServiceUnitException { assert serviceUnit != null; if (serviceUnits.put(serviceUnit.getId(), serviceUnit) != null) { - throw new RuntimeModelException("Service unit " + serviceUnit.getId() + " is already in the list"); + throw new DuplicatedServiceUnitException("Service unit " + serviceUnit.getId() + " is already in the list"); } } @@ -123,13 +124,13 @@ public Collection getServiceUnits() { * * @param component * must not be {code null} - * @throws RuntimeModelException + * @throws DuplicatedComponentException * Component is already in the list */ - public void addComponent(final RuntimeComponent component) throws RuntimeModelException { + public void addComponent(final RuntimeComponent component) throws DuplicatedComponentException { assert component != null; if (components.put(component.getId(), component) != null) { - throw new RuntimeModelException("Component " + component.getId() + " is already in the list"); + throw new DuplicatedComponentException("Component " + component.getId() + " is already in the list"); } } diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java index 59c7759..94271a2 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java @@ -22,15 +22,22 @@ import java.util.HashMap; import java.util.Map; +import org.ow2.petals.deployer.runtimemodel.exceptions.DuplicatedContainerException; + /** * @author Alexandre Lagane - Linagora */ public class RuntimeModel { private final Map containers = new HashMap<>(); - public void addContainer(final RuntimeContainer container) throws RuntimeModelException { + /** + * @param container + * must not be {code null} + * @throws DuplicatedContainerException + */ + public void addContainer(final RuntimeContainer container) throws DuplicatedContainerException { if (containers.put(container.getId(), container) != null) { - throw new RuntimeModelException("Container " + container.getId() + " is already in the list"); + throw new DuplicatedContainerException("Container " + container.getId() + " is already in the list"); } } @@ -41,12 +48,4 @@ public RuntimeContainer getContainer(final String id) { public Collection getContainers() { return containers.values(); } - - public static class RuntimeModelException extends Exception { - private static final long serialVersionUID = -4775138643228668670L; - - public RuntimeModelException(final String message) { - super(message); - } - } } diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModelException.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModelException.java deleted file mode 100644 index 933717f..0000000 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModelException.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.ow2.petals.deployer.runtimemodel; - -public class RuntimeModelException extends Exception { - public static class DuplicatedServiceUnitException extends RuntimeModelException { - RuntimeModelException.DuplicatedServiceUnitException e; - } -} diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedComponentException.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedComponentException.java new file mode 100644 index 0000000..621c356 --- /dev/null +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedComponentException.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.runtimemodel.exceptions; + +/** + * @author Alexandre Lagane - Linagora + */ +public class DuplicatedComponentException extends RuntimeModelException { + + private static final long serialVersionUID = -5826228789271638203L; + + public DuplicatedComponentException(String message) { + super(message); + } + +} diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedContainerException.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedContainerException.java new file mode 100644 index 0000000..3fffd66 --- /dev/null +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedContainerException.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.runtimemodel.exceptions; + +/** + * @author Alexandre Lagane - Linagora + */ +public class DuplicatedContainerException extends RuntimeModelException { + + private static final long serialVersionUID = -6281782979104342739L; + + public DuplicatedContainerException(String message) { + super(message); + } + +} diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedServiceUnitException.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedServiceUnitException.java new file mode 100644 index 0000000..2c18ab8 --- /dev/null +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedServiceUnitException.java @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.runtimemodel.exceptions; + +/** + * @author Alexandre Lagane - Linagora + */ +public class DuplicatedServiceUnitException extends RuntimeModelException { + + private static final long serialVersionUID = -8251466267062830623L; + + public DuplicatedServiceUnitException(String message) { + super(message); + } + +} diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/RuntimeModelException.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/RuntimeModelException.java new file mode 100644 index 0000000..a8e980e --- /dev/null +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/RuntimeModelException.java @@ -0,0 +1,31 @@ +/** + * Copyright (c) 2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.runtimemodel.exceptions; + +/** + * @author Alexandre Lagane - Linagora + */ +public class RuntimeModelException extends Exception { + + private static final long serialVersionUID = -2799783010070052000L; + + public RuntimeModelException(final String message) { + super(message); + } +} diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java b/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java index 13c6351..ec21619 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java +++ b/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java @@ -37,8 +37,8 @@ import org.ow2.petals.deployer.runtimemodel.RuntimeComponent; import org.ow2.petals.deployer.runtimemodel.RuntimeContainer; import org.ow2.petals.deployer.runtimemodel.RuntimeModel; -import org.ow2.petals.deployer.runtimemodel.RuntimeModel.RuntimeModelException; import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit; +import org.ow2.petals.deployer.runtimemodel.exceptions.RuntimeModelException; /** * @author Alexandre Lagane - Linagora diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java index 8988df0..a72a45b 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java +++ b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java @@ -31,8 +31,6 @@ import org.ow2.petals.deployer.model.xml._1.Model; import org.ow2.petals.deployer.runtimemodel.RuntimeModel; -import com.ebmwebsourcing.easycommons.lang.UncheckedException; - /** * The main class used for deploying XML models. * @@ -58,7 +56,7 @@ public class ModelDeployer { JAXBContext jaxbContext = JAXBContext.newInstance(Model.class); UNMARSHALLER = jaxbContext.createUnmarshaller(); } catch (Exception e) { - throw new UncheckedException(e); + throw new RuntimeException(e); } } @@ -67,7 +65,7 @@ public class ModelDeployer { try { DEPLOYER = new RuntimeModelDeployer(); } catch (Exception e) { - throw new UncheckedException(e); + throw new RuntimeException(e); } } diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java index 5367d54..0e1e5b2 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java @@ -31,8 +31,8 @@ import org.ow2.petals.deployer.runtimemodel.RuntimeComponent; import org.ow2.petals.deployer.runtimemodel.RuntimeContainer; import org.ow2.petals.deployer.runtimemodel.RuntimeModel; -import org.ow2.petals.deployer.runtimemodel.RuntimeModel.RuntimeModelException; import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit; +import org.ow2.petals.deployer.runtimemodel.exceptions.RuntimeModelException; import org.ow2.petals.jbi.descriptor.JBIDescriptorException; /** diff --git a/src/test/java/org/ow2/petals/deployer/utils/ModelUtils.java b/src/test/java/org/ow2/petals/deployer/utils/ModelUtils.java index f73cdbb..891dac2 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/ModelUtils.java +++ b/src/test/java/org/ow2/petals/deployer/utils/ModelUtils.java @@ -1,3 +1,21 @@ +/** + * Copyright (c) 2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + package org.ow2.petals.deployer.utils; import java.io.IOException; @@ -26,8 +44,6 @@ import org.ow2.petals.deployer.runtimemodel.RuntimeModel; import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit; -import com.ebmwebsourcing.easycommons.lang.UncheckedException; - public class ModelUtils { final public static String CONTAINER_NAME = "sample-0"; @@ -152,7 +168,7 @@ public static RuntimeModel generateTestRuntimeModel() { return model; } catch (Exception e) { - throw new UncheckedException(e); + throw new RuntimeException(e); } } } diff --git a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java index 1f214fe..b4385c4 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java @@ -1,3 +1,21 @@ +/** + * Copyright (c) 2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + package org.ow2.petals.deployer.utils; import static org.junit.Assert.assertFalse; From ce23050c588d0009e2684eee8f4ba97caa7e40ba Mon Sep 17 00:00:00 2001 From: Alexandre Lagane Date: Tue, 29 Jan 2019 17:07:37 +0100 Subject: [PATCH 16/21] Exceptions --- .../petals/deployer/utils/ModelDeployer.java | 1 + .../deployer/utils/RuntimeModelDeployer.java | 4 ++- .../ComponentDeploymentException.java | 31 +++++++++++++++++++ .../ModelDeployerException.java | 2 +- .../RuntimeModelDeployerException.java | 2 +- 5 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/ow2/petals/deployer/utils/exceptions/ComponentDeploymentException.java rename src/main/java/org/ow2/petals/deployer/utils/{ => exceptions}/ModelDeployerException.java (95%) rename src/main/java/org/ow2/petals/deployer/utils/{ => exceptions}/RuntimeModelDeployerException.java (95%) diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java index a72a45b..ea9349e 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java +++ b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java @@ -30,6 +30,7 @@ import org.apache.commons.io.FileUtils; import org.ow2.petals.deployer.model.xml._1.Model; import org.ow2.petals.deployer.runtimemodel.RuntimeModel; +import org.ow2.petals.deployer.utils.exceptions.ModelDeployerException; /** * The main class used for deploying XML models. diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java index 7dc15d6..7c1f42c 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java @@ -46,6 +46,8 @@ import org.ow2.petals.deployer.runtimemodel.RuntimeContainer; import org.ow2.petals.deployer.runtimemodel.RuntimeModel; import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit; +import org.ow2.petals.deployer.utils.exceptions.ComponentDeploymentException; +import org.ow2.petals.deployer.utils.exceptions.RuntimeModelDeployerException; import org.ow2.petals.jbi.descriptor.JBIDescriptorException; import org.ow2.petals.jbi.descriptor.original.JBIDescriptorBuilder; import org.ow2.petals.jbi.descriptor.original.generated.Jbi; @@ -125,7 +127,7 @@ private void deployRuntimeServiceUnit(final RuntimeServiceUnit serviceUnit, fina deployRuntimeComponent(component); deployedComponents.add(compName); } else { - LOG.warning("Component " + compName + " (needed by service unit " + throw new ComponentDeploymentException("Component " + compName + " (needed by service unit " + jbiSu.getIdentification().getName() + ") not found in the model"); } } diff --git a/src/main/java/org/ow2/petals/deployer/utils/exceptions/ComponentDeploymentException.java b/src/main/java/org/ow2/petals/deployer/utils/exceptions/ComponentDeploymentException.java new file mode 100644 index 0000000..6605730 --- /dev/null +++ b/src/main/java/org/ow2/petals/deployer/utils/exceptions/ComponentDeploymentException.java @@ -0,0 +1,31 @@ +/** + * Copyright (c) 2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.utils.exceptions; + +/** + * @author Alexandre Lagane - Linagora + */ +public class ComponentDeploymentException extends RuntimeModelDeployerException { + + private static final long serialVersionUID = 3893935147643008477L; + + public ComponentDeploymentException(final String message) { + super(message); + } +} diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployerException.java b/src/main/java/org/ow2/petals/deployer/utils/exceptions/ModelDeployerException.java similarity index 95% rename from src/main/java/org/ow2/petals/deployer/utils/ModelDeployerException.java rename to src/main/java/org/ow2/petals/deployer/utils/exceptions/ModelDeployerException.java index b310938..7925ab7 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployerException.java +++ b/src/main/java/org/ow2/petals/deployer/utils/exceptions/ModelDeployerException.java @@ -16,7 +16,7 @@ * for the GNU Lesser General Public License version 2.1. */ -package org.ow2.petals.deployer.utils; +package org.ow2.petals.deployer.utils.exceptions; /** * @author Alexandre Lagane - Linagora diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerException.java b/src/main/java/org/ow2/petals/deployer/utils/exceptions/RuntimeModelDeployerException.java similarity index 95% rename from src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerException.java rename to src/main/java/org/ow2/petals/deployer/utils/exceptions/RuntimeModelDeployerException.java index dc74d94..08864b7 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerException.java +++ b/src/main/java/org/ow2/petals/deployer/utils/exceptions/RuntimeModelDeployerException.java @@ -16,7 +16,7 @@ * for the GNU Lesser General Public License version 2.1. */ -package org.ow2.petals.deployer.utils; +package org.ow2.petals.deployer.utils.exceptions; /** * @author Alexandre Lagane - Linagora From a3529f779fe6265784e00d5869297ad6ff00dd57 Mon Sep 17 00:00:00 2001 From: Alexandre Lagane Date: Thu, 31 Jan 2019 15:14:05 +0100 Subject: [PATCH 17/21] Add UncheckedException; finals, finals everywhere --- .../DuplicatedComponentException.java | 2 +- .../DuplicatedContainerException.java | 2 +- .../DuplicatedServiceUnitException.java | 2 +- .../petals/deployer/utils/ModelConverter.java | 38 +++++++-------- .../petals/deployer/utils/ModelDeployer.java | 19 ++++---- .../utils/RuntimeModelComparator.java | 33 +++++++------ .../deployer/utils/RuntimeModelDeployer.java | 46 +++++++++---------- .../deployer/utils/RuntimeModelExporter.java | 6 +-- .../utils/exceptions/UncheckedException.java | 41 +++++++++++++++++ .../deployer/utils/ModelConverterTest.java | 14 +++--- .../ow2/petals/deployer/utils/ModelUtils.java | 43 ++++++++--------- .../petals/deployer/utils/ParseModelTest.java | 16 +++---- .../utils/RuntimeModelComparatorTest.java | 19 ++++---- .../utils/RuntimeModelDeployerTest.java | 10 ++-- .../ow2/petals/deployer/utils/ZipUtils.java | 19 ++++---- 15 files changed, 178 insertions(+), 132 deletions(-) create mode 100644 src/main/java/org/ow2/petals/deployer/utils/exceptions/UncheckedException.java diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedComponentException.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedComponentException.java index 621c356..d4924f7 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedComponentException.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedComponentException.java @@ -25,7 +25,7 @@ public class DuplicatedComponentException extends RuntimeModelException { private static final long serialVersionUID = -5826228789271638203L; - public DuplicatedComponentException(String message) { + public DuplicatedComponentException(final String message) { super(message); } diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedContainerException.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedContainerException.java index 3fffd66..d935090 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedContainerException.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedContainerException.java @@ -25,7 +25,7 @@ public class DuplicatedContainerException extends RuntimeModelException { private static final long serialVersionUID = -6281782979104342739L; - public DuplicatedContainerException(String message) { + public DuplicatedContainerException(final String message) { super(message); } diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedServiceUnitException.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedServiceUnitException.java index 2c18ab8..0a159df 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedServiceUnitException.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/exceptions/DuplicatedServiceUnitException.java @@ -25,7 +25,7 @@ public class DuplicatedServiceUnitException extends RuntimeModelException { private static final long serialVersionUID = -8251466267062830623L; - public DuplicatedServiceUnitException(String message) { + public DuplicatedServiceUnitException(final String message) { super(message); } diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java b/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java index ec21619..908aede 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java +++ b/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java @@ -46,16 +46,16 @@ public class ModelConverter { public static RuntimeModel convertModelToRuntimeModel(final Model model) throws MalformedURLException, RuntimeModelException { - RuntimeModel runtimeModel = new RuntimeModel(); + final RuntimeModel runtimeModel = new RuntimeModel(); - Container cont = model.getTopologyModel().getTopology().get(0).getContainer().get(0); + final Container cont = model.getTopologyModel().getTopology().get(0).getContainer().get(0); - BusModel busModel = model.getBusModel(); + final BusModel busModel = model.getBusModel(); - ContainerInstance contInst = busModel.getBus().get(0).getContainerInstance().get(0); + final ContainerInstance contInst = busModel.getBus().get(0).getContainerInstance().get(0); - String contId = cont.getId(); - String hostname = ((ProvisionedMachine) busModel.getMachine().get(0)).getHostname(); + final String contId = cont.getId(); + final String hostname = ((ProvisionedMachine) busModel.getMachine().get(0)).getHostname(); Integer contPort = contInst.getJmxPort(); if (contPort == null) { contPort = cont.getDefaultJmxPort(); @@ -69,28 +69,28 @@ public static RuntimeModel convertModelToRuntimeModel(final Model model) contPassword = cont.getDefaultJmxPassword(); } - RuntimeContainer runtimeCont = new RuntimeContainer(contId, contPort, contUser, contPassword, hostname); + final RuntimeContainer runtimeCont = new RuntimeContainer(contId, contPort, contUser, contPassword, hostname); runtimeModel.addContainer(runtimeCont); - ComponentRepository compRepo = model.getComponentRepository(); - Map compById = new HashMap<>(); - for (Component comp : compRepo.getComponent()) { + final ComponentRepository compRepo = model.getComponentRepository(); + final Map compById = new HashMap<>(); + for (final Component comp : compRepo.getComponent()) { compById.put(comp.getId(), comp); } - for (ComponentInstance compInst : contInst.getComponentInstance()) { - String compId = compInst.getRef(); - Component compRef = compById.get(compId); + for (final ComponentInstance compInst : contInst.getComponentInstance()) { + final String compId = compInst.getRef(); + final Component compRef = compById.get(compId); runtimeCont.addComponent(new RuntimeComponent(compId, new URL(compRef.getUrl()))); } - ServiceUnitModel suModel = model.getServiceUnitModel(); - Map suById = new HashMap<>(); - for (ServiceUnit su : suModel.getServiceUnit()) { + final ServiceUnitModel suModel = model.getServiceUnitModel(); + final Map suById = new HashMap<>(); + for (final ServiceUnit su : suModel.getServiceUnit()) { suById.put(su.getId(), su); } - for (ServiceUnitInstance suInst : contInst.getServiceUnitInstance()) { - String suId = suInst.getRef(); - ServiceUnit suRef = suById.get(suId); + for (final ServiceUnitInstance suInst : contInst.getServiceUnitInstance()) { + final String suId = suInst.getRef(); + final ServiceUnit suRef = suById.get(suId); runtimeCont.addServiceUnit(new RuntimeServiceUnit(suId, new URL(suRef.getUrl()))); } diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java index ea9349e..d324f1a 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java +++ b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java @@ -31,6 +31,7 @@ import org.ow2.petals.deployer.model.xml._1.Model; import org.ow2.petals.deployer.runtimemodel.RuntimeModel; import org.ow2.petals.deployer.utils.exceptions.ModelDeployerException; +import org.ow2.petals.deployer.utils.exceptions.UncheckedException; /** * The main class used for deploying XML models. @@ -54,10 +55,10 @@ public class ModelDeployer { private static final Unmarshaller UNMARSHALLER; static { try { - JAXBContext jaxbContext = JAXBContext.newInstance(Model.class); + final JAXBContext jaxbContext = JAXBContext.newInstance(Model.class); UNMARSHALLER = jaxbContext.createUnmarshaller(); - } catch (Exception e) { - throw new RuntimeException(e); + } catch (final Exception e) { + throw new UncheckedException(e); } } @@ -65,8 +66,8 @@ public class ModelDeployer { static { try { DEPLOYER = new RuntimeModelDeployer(); - } catch (Exception e) { - throw new RuntimeException(e); + } catch (final Exception e) { + throw new UncheckedException(e); } } @@ -78,7 +79,7 @@ public class ModelDeployer { * @throws ModelDeployerException */ public static void deployModel(final URL url) throws ModelDeployerException { - File modelFile; + final File modelFile; try { LOG.fine("Downloadind XML model"); @@ -87,13 +88,13 @@ public static void deployModel(final URL url) throws ModelDeployerException { LOG.fine("Parsing XML model"); - Model model = UNMARSHALLER.unmarshal(new StreamSource(modelFile), Model.class).getValue(); + final Model model = UNMARSHALLER.unmarshal(new StreamSource(modelFile), Model.class).getValue(); - RuntimeModel runtimeModel = ModelConverter.convertModelToRuntimeModel(model); + final RuntimeModel runtimeModel = ModelConverter.convertModelToRuntimeModel(model); DEPLOYER.deployRuntimeModel(runtimeModel); - } catch (Exception e) { + } catch (final Exception e) { throw new ModelDeployerException(e); } } diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java index 3bd5eb5..4214ecd 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java @@ -30,8 +30,7 @@ */ public class RuntimeModelComparator { /** - * Compares two runtimes models. - * URLs are not checked. + * Compares two runtimes models. URLs are not checked. * * @param m1 * @param m2 @@ -42,17 +41,17 @@ public static boolean compareRuntimeModels(final RuntimeModel m1, final RuntimeM } private static boolean compareRuntimeComponentMaps(final RuntimeContainer cont1, final RuntimeContainer cont2) { - Collection compList1 = cont1.getComponents(); - Collection compList2 = cont2.getComponents(); + final Collection compList1 = cont1.getComponents(); + final Collection compList2 = cont2.getComponents(); - for (RuntimeComponent comp1 : compList1) { - RuntimeComponent comp2 = cont2.getComponent(comp1.getId()); + for (final RuntimeComponent comp1 : compList1) { + final RuntimeComponent comp2 = cont2.getComponent(comp1.getId()); if (comp2 == null || !compareRuntimeComponents(comp1, comp2)) { return false; } } - for (RuntimeComponent comp2 : compList2) { + for (final RuntimeComponent comp2 : compList2) { if (cont1.getComponent(comp2.getId()) == null) { return false; } @@ -62,17 +61,17 @@ private static boolean compareRuntimeComponentMaps(final RuntimeContainer cont1, } private static boolean compareRuntimeContainerMaps(final RuntimeModel m1, final RuntimeModel m2) { - Collection contList1 = m1.getContainers(); - Collection contList2 = m2.getContainers(); + final Collection contList1 = m1.getContainers(); + final Collection contList2 = m2.getContainers(); - for (RuntimeContainer cont1 : contList1) { - RuntimeContainer cont2 = m2.getContainer(cont1.getId()); + for (final RuntimeContainer cont1 : contList1) { + final RuntimeContainer cont2 = m2.getContainer(cont1.getId()); if (cont2 == null || !compareRuntimeContainers(cont1, cont2)) { return false; } } - for (RuntimeContainer cont2 : contList2) { + for (final RuntimeContainer cont2 : contList2) { if (m1.getContainer(cont2.getId()) == null) { return false; } @@ -89,17 +88,17 @@ private static boolean compareRuntimeContainers(final RuntimeContainer cont1, fi } private static boolean compareRuntimeServiceUnitMaps(final RuntimeContainer cont1, final RuntimeContainer cont2) { - Collection suList1 = cont1.getServiceUnits(); - Collection suList2 = cont2.getServiceUnits(); + final Collection suList1 = cont1.getServiceUnits(); + final Collection suList2 = cont2.getServiceUnits(); - for (RuntimeServiceUnit su1 : suList1) { - RuntimeServiceUnit su2 = cont2.getServiceUnit(su1.getId()); + for (final RuntimeServiceUnit su1 : suList1) { + final RuntimeServiceUnit su2 = cont2.getServiceUnit(su1.getId()); if (su2 == null || !compareRuntimeServiceUnits(su1, su2)) { return false; } } - for (RuntimeServiceUnit su2 : suList2) { + for (final RuntimeServiceUnit su2 : suList2) { if (cont1.getServiceUnit(su2.getId()) == null) { return false; } diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java index 7c1f42c..dbbf819 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java @@ -84,22 +84,22 @@ public void deployRuntimeModel(final RuntimeModel model) throws ConnectionFailedException, ContainerAdministrationException, ArtifactStartedException, ArtifactNotDeployedException, ArtifactNotFoundException, IOException, JBIDescriptorException, ArtifactAdministrationException, RuntimeModelDeployerException { - RuntimeContainer container = model.getContainers().iterator().next(); - Collection serviceUnits = container.getServiceUnits(); + final RuntimeContainer container = model.getContainers().iterator().next(); + final Collection serviceUnits = container.getServiceUnits(); LOG.fine("Deploying model (" + serviceUnits.size() + " service units)"); - String hostname = container.getHostname(); - int port = container.getPort(); - String user = container.getUser(); - String password = container.getPassword(); + final String hostname = container.getHostname(); + final int port = container.getPort(); + final String user = container.getUser(); + final String password = container.getPassword(); petalsAdmin.connect(hostname, port, user, password); - Set deployedComponents = new HashSet(); - Set deployedServiceUnits = new HashSet(); + final Set deployedComponents = new HashSet(); + final Set deployedServiceUnits = new HashSet(); - for (RuntimeServiceUnit serviceUnit : serviceUnits) { + for (final RuntimeServiceUnit serviceUnit : serviceUnits) { deployRuntimeServiceUnit(serviceUnit, model, deployedComponents, deployedServiceUnits); } @@ -110,19 +110,19 @@ private void deployRuntimeServiceUnit(final RuntimeServiceUnit serviceUnit, fina final Set deployedComponents, final Set deployedServiceUnits) throws IOException, JBIDescriptorException, ArtifactStartedException, ArtifactNotDeployedException, ArtifactNotFoundException, ArtifactAdministrationException, RuntimeModelDeployerException { - String suId = serviceUnit.getId(); - File suFile = Files.createTempFile(suId, ".zip").toFile(); + final String suId = serviceUnit.getId(); + final File suFile = Files.createTempFile(suId, ".zip").toFile(); FileUtils.copyURLToFile(serviceUnit.getUrl(), suFile, ModelDeployer.CONNECTION_TIMEOUT, ModelDeployer.READ_TIMEOUT); - Jbi jbi = jdb.buildJavaJBIDescriptorFromArchive(suFile); - ServiceAssembly jbiSa = jbi.getServiceAssembly(); + final Jbi jbi = jdb.buildJavaJBIDescriptorFromArchive(suFile); + final ServiceAssembly jbiSa = jbi.getServiceAssembly(); if (!deployedServiceUnits.contains(suId)) { LOG.fine("Deploying service assembly"); - for (org.ow2.petals.jbi.descriptor.original.generated.ServiceUnit jbiSu : jbiSa.getServiceUnit()) { - String compName = jbiSu.getTarget().getComponentName(); + for (final org.ow2.petals.jbi.descriptor.original.generated.ServiceUnit jbiSu : jbiSa.getServiceUnit()) { + final String compName = jbiSu.getTarget().getComponentName(); if (!deployedComponents.contains(compName)) { - RuntimeComponent component = model.getContainers().iterator().next().getComponent(compName); + final RuntimeComponent component = model.getContainers().iterator().next().getComponent(compName); if (component != null) { deployRuntimeComponent(component); deployedComponents.add(compName); @@ -132,12 +132,12 @@ private void deployRuntimeServiceUnit(final RuntimeServiceUnit serviceUnit, fina } } } - ServiceAssemblyLifecycle saLifecycle = artifactLifecycleFactory.createServiceAssemblyLifecycle( + final ServiceAssemblyLifecycle saLifecycle = artifactLifecycleFactory.createServiceAssemblyLifecycle( new org.ow2.petals.admin.api.artifact.ServiceAssembly(jbiSa.getIdentification().getName())); saLifecycle.deploy(suFile.toURI().toURL()); saLifecycle.start(); - for (org.ow2.petals.jbi.descriptor.original.generated.ServiceUnit jbiSu : jbiSa.getServiceUnit()) { - String suName = jbiSu.getIdentification().getName(); + for (final org.ow2.petals.jbi.descriptor.original.generated.ServiceUnit jbiSu : jbiSa.getServiceUnit()) { + final String suName = jbiSu.getIdentification().getName(); if (!deployedServiceUnits.contains(suName)) { deployedServiceUnits.add(suName); LOG.fine("Service unit " + suName + " deployed and started"); @@ -150,14 +150,14 @@ private void deployRuntimeServiceUnit(final RuntimeServiceUnit serviceUnit, fina private void deployRuntimeComponent(final RuntimeComponent component) throws IOException, JBIDescriptorException, ArtifactDeployedException, ArtifactAdministrationException { - String compId = component.getId(); - File compFile = Files.createTempFile(compId, "zip").toFile(); + final String compId = component.getId(); + final File compFile = Files.createTempFile(compId, "zip").toFile(); FileUtils.copyURLToFile(component.getUrl(), compFile, ModelDeployer.CONNECTION_TIMEOUT, ModelDeployer.READ_TIMEOUT); - Jbi jbi = jdb.buildJavaJBIDescriptorFromArchive(compFile); + final Jbi jbi = jdb.buildJavaJBIDescriptorFromArchive(compFile); LOG.fine("Deploying component " + component.getId()); - ComponentLifecycle compLifecycle = artifactLifecycleFactory + final ComponentLifecycle compLifecycle = artifactLifecycleFactory .createComponentLifecycle(new org.ow2.petals.admin.api.artifact.Component(compId, convertComponentTypeFromJbiToPetalsAdmin(jbi.getComponent().getType()))); diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java index 0e1e5b2..dbb9834 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java @@ -73,14 +73,14 @@ public RuntimeModel exportRuntimeModel(final String hostname, final int port, fi throws RuntimeModelException, ArtifactAdministrationException, ContainerAdministrationException { petalsAdmin.connect(hostname, port, user, password); - RuntimeModel model = new RuntimeModel(); + final RuntimeModel model = new RuntimeModel(); - RuntimeContainer cont = new RuntimeContainer(petalsAdmin.newContainerAdministration() + final RuntimeContainer cont = new RuntimeContainer(petalsAdmin.newContainerAdministration() .getTopology(topologyPassphrase, false).getContainers().get(0).getContainerName(), port, user, password, hostname); model.addContainer(cont); - for (Artifact artifact : artifactAdmin.listArtifacts()) { + for (final Artifact artifact : artifactAdmin.listArtifacts()) { switch (artifact.getType()) { case "BC": case "SE": diff --git a/src/main/java/org/ow2/petals/deployer/utils/exceptions/UncheckedException.java b/src/main/java/org/ow2/petals/deployer/utils/exceptions/UncheckedException.java new file mode 100644 index 0000000..679e69d --- /dev/null +++ b/src/main/java/org/ow2/petals/deployer/utils/exceptions/UncheckedException.java @@ -0,0 +1,41 @@ +/** + * Copyright (c) 2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.utils.exceptions; + +/** + * + * @author Alexandre Lagane - Linagora + * + */ +public class UncheckedException extends RuntimeException { + + private static final long serialVersionUID = 1339368144114468807L; + + public UncheckedException(final Throwable cause) { + super(cause); + } + + public UncheckedException(final String message, final Throwable cause) { + super(message, cause); + } + + public UncheckedException(final String message) { + super(message); + } +} diff --git a/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java b/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java index 6c8341d..9ce0196 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/ModelConverterTest.java @@ -36,21 +36,21 @@ public class ModelConverterTest { @Test public void convertModelToRuntimeModel() throws Exception { - Model model = ModelUtils.generateTestModel(); + final Model model = ModelUtils.generateTestModel(); - RuntimeModel runtimeModel = ModelConverter.convertModelToRuntimeModel(model); + final RuntimeModel runtimeModel = ModelConverter.convertModelToRuntimeModel(model); - Collection containers = runtimeModel.getContainers(); + final Collection containers = runtimeModel.getContainers(); assertEquals(1, containers.size()); - RuntimeContainer cont = containers.iterator().next(); + final RuntimeContainer cont = containers.iterator().next(); assertEquals(ModelUtils.CONTAINER_NAME, cont.getId()); assertEquals(ModelUtils.CONTAINER_HOST, cont.getHostname()); assertEquals(ModelUtils.CONTAINER_JMX_PORT, cont.getPort()); assertEquals(ModelUtils.CONTAINER_USER, cont.getUser()); assertEquals(ModelUtils.CONTAINER_PWD, cont.getPassword()); - Collection serviceUnits = cont.getServiceUnits(); + final Collection serviceUnits = cont.getServiceUnits(); assertEquals(3, serviceUnits.size()); RuntimeServiceUnit su = cont.getServiceUnit("su-SOAP-Hello_Service1-provide"); @@ -65,10 +65,10 @@ public void convertModelToRuntimeModel() throws Exception { assertEquals("su-SOAP-Hello_PortType-consume", su.getId()); assertEquals("file:/artifacts/sa-SOAP-Hello_PortType-consume", su.getUrl().toString()); - Collection components = cont.getComponents(); + final Collection components = cont.getComponents(); assertEquals(1, components.size()); - RuntimeComponent comp = cont.getComponent("petals-bc-soap"); + final RuntimeComponent comp = cont.getComponent("petals-bc-soap"); assertEquals("petals-bc-soap", comp.getId()); assertEquals("file:/artifacts/petals-bc-soap-5.0.0", comp.getUrl().toString()); } diff --git a/src/test/java/org/ow2/petals/deployer/utils/ModelUtils.java b/src/test/java/org/ow2/petals/deployer/utils/ModelUtils.java index 891dac2..18e37d8 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/ModelUtils.java +++ b/src/test/java/org/ow2/petals/deployer/utils/ModelUtils.java @@ -43,6 +43,7 @@ import org.ow2.petals.deployer.runtimemodel.RuntimeContainer; import org.ow2.petals.deployer.runtimemodel.RuntimeModel; import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit; +import org.ow2.petals.deployer.utils.exceptions.UncheckedException; public class ModelUtils { @@ -59,50 +60,50 @@ public class ModelUtils { final public static State CONTAINER_STATE = State.REACHABLE; public static Model generateTestModel() throws MalformedURLException, IOException, URISyntaxException { - Model model = new Model(); + final Model model = new Model(); /* Component Repository */ - ComponentRepository compRepo = new ComponentRepository(); + final ComponentRepository compRepo = new ComponentRepository(); model.setComponentRepository(compRepo); - Component bcSoap = new Component(); + final Component bcSoap = new Component(); bcSoap.setId("petals-bc-soap"); bcSoap.setUrl("file:/artifacts/petals-bc-soap-5.0.0"); compRepo.getComponent().add(bcSoap); /* Service Unit Model */ - ServiceUnitModel suModel = new ServiceUnitModel(); + final ServiceUnitModel suModel = new ServiceUnitModel(); model.setServiceUnitModel(suModel); - List serviceUnits = suModel.getServiceUnit(); + final List serviceUnits = suModel.getServiceUnit(); - ServiceUnit suProv1 = new ServiceUnit(); + final ServiceUnit suProv1 = new ServiceUnit(); suProv1.setId("su-SOAP-Hello_Service1-provide"); suProv1.setUrl("file:/artifacts/sa-SOAP-Hello_Service1-provide"); serviceUnits.add(suProv1); - ServiceUnit suProv2 = new ServiceUnit(); + final ServiceUnit suProv2 = new ServiceUnit(); suProv2.setId("su-SOAP-Hello_Service2-provide"); suProv2.setUrl("file:/artifacts/sa-SOAP-Hello_Service2-provide"); serviceUnits.add(suProv2); - ServiceUnit suCons = new ServiceUnit(); + final ServiceUnit suCons = new ServiceUnit(); suCons.setId("su-SOAP-Hello_PortType-consume"); suCons.setUrl("file:/artifacts/sa-SOAP-Hello_PortType-consume"); serviceUnits.add(suCons); /* Topology Model */ - TopologyModel topoModel = new TopologyModel(); + final TopologyModel topoModel = new TopologyModel(); model.setTopologyModel(topoModel); - Topology topo = new Topology(); + final Topology topo = new Topology(); topo.setId("topo1"); topoModel.getTopology().add(topo); - Container cont = new Container(); + final Container cont = new Container(); cont.setId(CONTAINER_NAME); cont.setDefaultJmxPort(CONTAINER_JMX_PORT); cont.setDefaultJmxUser(CONTAINER_USER); @@ -111,28 +112,28 @@ public static Model generateTestModel() throws MalformedURLException, IOExceptio /* Bus Model */ - BusModel busModel = new BusModel(); + final BusModel busModel = new BusModel(); model.setBusModel(busModel); - ProvisionedMachine machine = new ProvisionedMachine(); + final ProvisionedMachine machine = new ProvisionedMachine(); machine.setId("main"); machine.setHostname("localhost"); busModel.getMachine().add(machine); - Bus bus = new Bus(); + final Bus bus = new Bus(); bus.setTopologyRef(topo.getId()); busModel.getBus().add(bus); - ContainerInstance contInst = new ContainerInstance(); + final ContainerInstance contInst = new ContainerInstance(); contInst.setRef(cont.getId()); contInst.setMachineRef(machine.getId()); bus.getContainerInstance().add(contInst); - ComponentInstance bcSoapInst = new ComponentInstance(); + final ComponentInstance bcSoapInst = new ComponentInstance(); bcSoapInst.setRef(bcSoap.getId()); contInst.getComponentInstance().add(bcSoapInst); - List suInstances = contInst.getServiceUnitInstance(); + final List suInstances = contInst.getServiceUnitInstance(); ServiceUnitInstance suInst = new ServiceUnitInstance(); suInst.setRef(suProv1.getId()); @@ -151,9 +152,9 @@ public static Model generateTestModel() throws MalformedURLException, IOExceptio public static RuntimeModel generateTestRuntimeModel() { try { - RuntimeModel model = new RuntimeModel(); + final RuntimeModel model = new RuntimeModel(); - RuntimeContainer cont = new RuntimeContainer(CONTAINER_NAME, CONTAINER_JMX_PORT, CONTAINER_USER, + final RuntimeContainer cont = new RuntimeContainer(CONTAINER_NAME, CONTAINER_JMX_PORT, CONTAINER_USER, CONTAINER_PWD, CONTAINER_HOST); model.addContainer(cont); @@ -167,8 +168,8 @@ public static RuntimeModel generateTestRuntimeModel() { cont.addComponent(new RuntimeComponent("petals-bc-soap", new URL("file:/artifacts/petals-bc-soap-5.0.0"))); return model; - } catch (Exception e) { - throw new RuntimeException(e); + } catch (final Exception e) { + throw new UncheckedException(e); } } } diff --git a/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java b/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java index 38895c2..9a4f14d 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java @@ -39,23 +39,23 @@ public class ParseModelTest { @Test public void parseModel() throws Exception { - ObjectFactory of = new ObjectFactory(); + final ObjectFactory of = new ObjectFactory(); - Model model = ModelUtils.generateTestModel(); + final Model model = ModelUtils.generateTestModel(); - StringWriter marshalledModelWriter = new StringWriter(); - StringWriter unmarshalledModelWriter = new StringWriter(); + final StringWriter marshalledModelWriter = new StringWriter(); + final StringWriter unmarshalledModelWriter = new StringWriter(); - JAXBContext jaxbContext = JAXBContext.newInstance(Model.class); + final JAXBContext jaxbContext = JAXBContext.newInstance(Model.class); - Marshaller marshaller = jaxbContext.createMarshaller(); - Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + final Marshaller marshaller = jaxbContext.createMarshaller(); + final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(of.createModel(model), marshalledModelWriter); - Model unmarshalledModel = unmarshaller + final Model unmarshalledModel = unmarshaller .unmarshal(new StreamSource(new StringReader(marshalledModelWriter.toString())), Model.class) .getValue(); diff --git a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java index b4385c4..3917fe2 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java @@ -33,9 +33,9 @@ public class RuntimeModelComparatorTest { @Test public void equivalentRuntimeModels() throws Exception { - RuntimeModel model = ModelUtils.generateTestRuntimeModel(); + final RuntimeModel model = ModelUtils.generateTestRuntimeModel(); - RuntimeModel equivalentModel = ModelUtils.generateTestRuntimeModel(); + final RuntimeModel equivalentModel = ModelUtils.generateTestRuntimeModel(); assertTrue(RuntimeModelComparator.compareRuntimeModels(model, equivalentModel)); assertTrue(RuntimeModelComparator.compareRuntimeModels(equivalentModel, model)); @@ -43,9 +43,9 @@ public void equivalentRuntimeModels() throws Exception { @Test public void differentServiceUnitListsRuntimeModels() throws Exception { - RuntimeModel model = ModelUtils.generateTestRuntimeModel(); + final RuntimeModel model = ModelUtils.generateTestRuntimeModel(); - RuntimeModel modelWithDifferentServiceUnitList = ModelUtils.generateTestRuntimeModel(); + final RuntimeModel modelWithDifferentServiceUnitList = ModelUtils.generateTestRuntimeModel(); modelWithDifferentServiceUnitList.getContainers().iterator().next() .addServiceUnit(new RuntimeServiceUnit("my-test-su", new URL("file:/artifact/my-test-su.zip"))); @@ -55,9 +55,9 @@ public void differentServiceUnitListsRuntimeModels() throws Exception { @Test public void differentComponentListsRuntimeModels() throws Exception { - RuntimeModel model = ModelUtils.generateTestRuntimeModel(); + final RuntimeModel model = ModelUtils.generateTestRuntimeModel(); - RuntimeModel modelWithDifferentComponentList = ModelUtils.generateTestRuntimeModel(); + final RuntimeModel modelWithDifferentComponentList = ModelUtils.generateTestRuntimeModel(); modelWithDifferentComponentList.getContainers().iterator().next() .addComponent(new RuntimeComponent("my-test-comp", new URL("file:/artifact/my-test-comp.zip"))); @@ -67,11 +67,12 @@ public void differentComponentListsRuntimeModels() throws Exception { @Test public void differentContainersRuntimeModels() throws Exception { - RuntimeModel model = ModelUtils.generateTestRuntimeModel(); + final RuntimeModel model = ModelUtils.generateTestRuntimeModel(); - RuntimeModel modelWithDifferentContainer = ModelUtils.generateTestRuntimeModel(); + final RuntimeModel modelWithDifferentContainer = ModelUtils.generateTestRuntimeModel(); modelWithDifferentContainer.getContainers().clear(); - RuntimeContainer differentCont = new RuntimeContainer("different-cont", 7700, "other", "azerty", "localhost"); + final RuntimeContainer differentCont = new RuntimeContainer("different-cont", 7700, "other", "azerty", + "localhost"); modelWithDifferentContainer.addContainer(differentCont); assertFalse(RuntimeModelComparator.compareRuntimeModels(model, modelWithDifferentContainer)); diff --git a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java index e302bd0..48c05fc 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java @@ -51,15 +51,15 @@ public class RuntimeModelDeployerTest { @BeforeClass public static void setupLogger() throws Exception { - Logger deployerLogger = Logger.getLogger(RuntimeModelDeployer.class.getName()); + final Logger deployerLogger = Logger.getLogger(RuntimeModelDeployer.class.getName()); deployerLogger.setLevel(Level.FINER); - Logger comparatorLogger = Logger.getLogger(RuntimeModelComparator.class.getName()); + final Logger comparatorLogger = Logger.getLogger(RuntimeModelComparator.class.getName()); comparatorLogger.setLevel(Level.FINER); - Handler consoleHandler = new ConsoleHandler(); + final Handler consoleHandler = new ConsoleHandler(); consoleHandler.setLevel(Level.FINER); - Formatter formatter = new Formatter() { + final Formatter formatter = new Formatter() { @Override - public String format(LogRecord record) { + public String format(final LogRecord record) { return record.getMessage() + "\n"; } }; diff --git a/src/test/java/org/ow2/petals/deployer/utils/ZipUtils.java b/src/test/java/org/ow2/petals/deployer/utils/ZipUtils.java index a134dc4..ee18efa 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/ZipUtils.java +++ b/src/test/java/org/ow2/petals/deployer/utils/ZipUtils.java @@ -44,25 +44,28 @@ public class ZipUtils { * @throws IOException * @throws URISyntaxException */ - public static File createZipFromResourceDirectory(String resourcePath) throws IOException, URISyntaxException { - File zip = Files.createTempFile(null, null).toFile(); - File resource = new File(Thread.currentThread().getContextClassLoader().getResource(resourcePath).toURI()); - ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zip)); - for (File file : resource.listFiles()) { + public static File createZipFromResourceDirectory(final String resourcePath) + throws IOException, URISyntaxException { + final File zip = Files.createTempFile(null, null).toFile(); + final File resource = new File( + Thread.currentThread().getContextClassLoader().getResource(resourcePath).toURI()); + final ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zip)); + for (final File file : resource.listFiles()) { addDirectoryToZip("", file, zos); } zos.close(); return zip; } - private static void addDirectoryToZip(String prefix, File file, ZipOutputStream zos) throws IOException { + private static void addDirectoryToZip(final String prefix, final File file, final ZipOutputStream zos) + throws IOException { if (file.isDirectory()) { - for (File child : file.listFiles()) { + for (final File child : file.listFiles()) { addDirectoryToZip(prefix + file.getName() + "/", child, zos); } } else { zos.putNextEntry(new ZipEntry(prefix + file.getName())); - FileInputStream fis = new FileInputStream(file); + final FileInputStream fis = new FileInputStream(file); byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; while (fis.available() > 0) { int read = fis.read(buffer, 0, buffer.length); From ac1f0cbb926c546b64c9d72adcbc5d85121a198e Mon Sep 17 00:00:00 2001 From: Alexandre Lagane Date: Thu, 31 Jan 2019 17:13:36 +0100 Subject: [PATCH 18/21] Replace Comparator with Similar interface on model --- .../runtimemodel/RuntimeComponent.java | 9 +- .../runtimemodel/RuntimeContainer.java | 51 +++++++- .../deployer/runtimemodel/RuntimeModel.java | 29 ++++- .../runtimemodel/RuntimeServiceUnit.java | 9 +- .../runtimemodel/interfaces/Similar.java | 33 +++++ .../utils/RuntimeModelComparator.java | 117 ------------------ .../utils/RuntimeModelComparatorTest.java | 18 +-- .../utils/RuntimeModelDeployerTest.java | 19 ++- 8 files changed, 144 insertions(+), 141 deletions(-) create mode 100644 src/main/java/org/ow2/petals/deployer/runtimemodel/interfaces/Similar.java delete mode 100644 src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java index f8b8719..4cd929b 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java @@ -20,10 +20,12 @@ import java.net.URL; +import org.ow2.petals.deployer.runtimemodel.interfaces.Similar; + /** * @author Alexandre Lagane - Linagora */ -public class RuntimeComponent { +public class RuntimeComponent implements Similar { private final String id; private URL url; @@ -69,4 +71,9 @@ public boolean equals(final Object obj) { public int hashCode() { return id.hashCode(); } + + @Override + public boolean isSimilarTo(Object o) { + return o instanceof RuntimeComponent && this.getId().equals(((RuntimeComponent) o).getId()); + } } diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java index c934283..c878a27 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java @@ -24,11 +24,12 @@ import org.ow2.petals.deployer.runtimemodel.exceptions.DuplicatedComponentException; import org.ow2.petals.deployer.runtimemodel.exceptions.DuplicatedServiceUnitException; +import org.ow2.petals.deployer.runtimemodel.interfaces.Similar; /** * @author Alexandre Lagane - Linagora */ -public class RuntimeContainer { +public class RuntimeContainer implements Similar { private final String id; private int port; @@ -151,4 +152,52 @@ public boolean equals(final Object obj) { public int hashCode() { return id.hashCode(); } + + @Override + public boolean isSimilarTo(Object o) { + if (!(o instanceof RuntimeContainer)) { + return false; + } + RuntimeContainer otherContainer = (RuntimeContainer) o; + + return this.getId().equals(otherContainer.getId()) && this.getPort() == otherContainer.getPort() + && this.getUser().equals(otherContainer.getUser()) + && this.getPassword().equals(otherContainer.getPassword()) + && this.getHostname().equals(otherContainer.getHostname()) + && compareRuntimeServiceUnitMaps(otherContainer) && compareRuntimeComponentMaps(otherContainer); + } + + private boolean compareRuntimeServiceUnitMaps(final RuntimeContainer otherCont) { + for (final RuntimeServiceUnit thisContSu : this.getServiceUnits()) { + final RuntimeServiceUnit otherContSu = otherCont.getServiceUnit(thisContSu.getId()); + if (thisContSu == null || !thisContSu.isSimilarTo(otherContSu)) { + return false; + } + } + + for (final RuntimeServiceUnit otherContSu : otherCont.getServiceUnits()) { + if (this.getServiceUnit(otherContSu.getId()) == null) { + return false; + } + } + + return true; + } + + private boolean compareRuntimeComponentMaps(final RuntimeContainer otherCont) { + for (final RuntimeComponent thisContComp : this.getComponents()) { + final RuntimeComponent otherContComp = otherCont.getComponent(thisContComp.getId()); + if (otherContComp == null || !thisContComp.isSimilarTo(otherContComp)) { + return false; + } + } + + for (final RuntimeComponent otherContComp : otherCont.getComponents()) { + if (this.getComponent(otherContComp.getId()) == null) { + return false; + } + } + + return true; + } } diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java index 94271a2..c5ffe3c 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java @@ -23,11 +23,12 @@ import java.util.Map; import org.ow2.petals.deployer.runtimemodel.exceptions.DuplicatedContainerException; +import org.ow2.petals.deployer.runtimemodel.interfaces.Similar; /** * @author Alexandre Lagane - Linagora */ -public class RuntimeModel { +public class RuntimeModel implements Similar { private final Map containers = new HashMap<>(); /** @@ -48,4 +49,30 @@ public RuntimeContainer getContainer(final String id) { public Collection getContainers() { return containers.values(); } + + @Override + public boolean isSimilarTo(Object o) { + if (!(o instanceof RuntimeModel)) { + return false; + } + RuntimeModel otherModel = (RuntimeModel) o; + + final Collection thisModelContainers = this.getContainers(); + final Collection otherModelContainers = otherModel.getContainers(); + + for (final RuntimeContainer thisModelCont : thisModelContainers) { + final RuntimeContainer otherModelCont = otherModel.getContainer(thisModelCont.getId()); + if (otherModelCont == null || !thisModelCont.isSimilarTo(otherModelCont)) { + return false; + } + } + + for (final RuntimeContainer otherModelCont : otherModelContainers) { + if (this.getContainer(otherModelCont.getId()) == null) { + return false; + } + } + + return true; + } } diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java index ec25668..5c86348 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java @@ -20,10 +20,12 @@ import java.net.URL; +import org.ow2.petals.deployer.runtimemodel.interfaces.Similar; + /** * @author Alexandre Lagane - Linagora */ -public class RuntimeServiceUnit { +public class RuntimeServiceUnit implements Similar { private final String id; private URL url; @@ -68,4 +70,9 @@ public boolean equals(final Object obj) { public int hashCode() { return id.hashCode(); } + + @Override + public boolean isSimilarTo(Object o) { + return o instanceof RuntimeServiceUnit && this.getId().equals(((RuntimeServiceUnit) o).getId()); + } } diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/interfaces/Similar.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/interfaces/Similar.java new file mode 100644 index 0000000..5eb00a0 --- /dev/null +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/interfaces/Similar.java @@ -0,0 +1,33 @@ +/** + * Copyright (c) 2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.runtimemodel.interfaces; + +/** + * @author Alexandre Lagane - Linagora + */ +public interface Similar { + /** + * Return true if current object and o are similar. + * + * @param o + * object compared with current object + * @return true if similar + */ + public boolean isSimilarTo(Object o); +} diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java deleted file mode 100644 index 4214ecd..0000000 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelComparator.java +++ /dev/null @@ -1,117 +0,0 @@ -/** - * Copyright (c) 2018-2019 Linagora - * - * This program/library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 2.1 of the License, or (at your - * option) any later version. - * - * This program/library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program/library; If not, see http://www.gnu.org/licenses/ - * for the GNU Lesser General Public License version 2.1. - */ - -package org.ow2.petals.deployer.utils; - -import java.util.Collection; - -import org.ow2.petals.deployer.runtimemodel.RuntimeComponent; -import org.ow2.petals.deployer.runtimemodel.RuntimeContainer; -import org.ow2.petals.deployer.runtimemodel.RuntimeModel; -import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit; - -/** - * @author Alexandre Lagane - Linagora - */ -public class RuntimeModelComparator { - /** - * Compares two runtimes models. URLs are not checked. - * - * @param m1 - * @param m2 - * @return true if m1 and m2 are equivalents - */ - public static boolean compareRuntimeModels(final RuntimeModel m1, final RuntimeModel m2) { - return compareRuntimeContainerMaps(m1, m2); - } - - private static boolean compareRuntimeComponentMaps(final RuntimeContainer cont1, final RuntimeContainer cont2) { - final Collection compList1 = cont1.getComponents(); - final Collection compList2 = cont2.getComponents(); - - for (final RuntimeComponent comp1 : compList1) { - final RuntimeComponent comp2 = cont2.getComponent(comp1.getId()); - if (comp2 == null || !compareRuntimeComponents(comp1, comp2)) { - return false; - } - } - - for (final RuntimeComponent comp2 : compList2) { - if (cont1.getComponent(comp2.getId()) == null) { - return false; - } - } - - return true; - } - - private static boolean compareRuntimeContainerMaps(final RuntimeModel m1, final RuntimeModel m2) { - final Collection contList1 = m1.getContainers(); - final Collection contList2 = m2.getContainers(); - - for (final RuntimeContainer cont1 : contList1) { - final RuntimeContainer cont2 = m2.getContainer(cont1.getId()); - if (cont2 == null || !compareRuntimeContainers(cont1, cont2)) { - return false; - } - } - - for (final RuntimeContainer cont2 : contList2) { - if (m1.getContainer(cont2.getId()) == null) { - return false; - } - } - - return true; - } - - private static boolean compareRuntimeContainers(final RuntimeContainer cont1, final RuntimeContainer cont2) { - return cont1.getId().equals(cont2.getId()) && cont1.getPort() == cont2.getPort() - && cont1.getUser().equals(cont2.getUser()) && cont1.getPassword().equals(cont2.getPassword()) - && cont1.getHostname().equals(cont2.getHostname()) && compareRuntimeServiceUnitMaps(cont1, cont2) - && compareRuntimeComponentMaps(cont1, cont2); - } - - private static boolean compareRuntimeServiceUnitMaps(final RuntimeContainer cont1, final RuntimeContainer cont2) { - final Collection suList1 = cont1.getServiceUnits(); - final Collection suList2 = cont2.getServiceUnits(); - - for (final RuntimeServiceUnit su1 : suList1) { - final RuntimeServiceUnit su2 = cont2.getServiceUnit(su1.getId()); - if (su2 == null || !compareRuntimeServiceUnits(su1, su2)) { - return false; - } - } - - for (final RuntimeServiceUnit su2 : suList2) { - if (cont1.getServiceUnit(su2.getId()) == null) { - return false; - } - } - - return true; - } - - private static boolean compareRuntimeServiceUnits(final RuntimeServiceUnit su1, final RuntimeServiceUnit su2) { - return su1.getId().equals(su2.getId()); - } - - private static boolean compareRuntimeComponents(final RuntimeComponent comp1, final RuntimeComponent comp2) { - return comp1.getId().equals(comp2.getId()); - } -} diff --git a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java index 3917fe2..4de6bc6 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelComparatorTest.java @@ -35,10 +35,10 @@ public class RuntimeModelComparatorTest { public void equivalentRuntimeModels() throws Exception { final RuntimeModel model = ModelUtils.generateTestRuntimeModel(); - final RuntimeModel equivalentModel = ModelUtils.generateTestRuntimeModel(); + final RuntimeModel similarModel = ModelUtils.generateTestRuntimeModel(); - assertTrue(RuntimeModelComparator.compareRuntimeModels(model, equivalentModel)); - assertTrue(RuntimeModelComparator.compareRuntimeModels(equivalentModel, model)); + assertTrue(model.isSimilarTo(similarModel)); + assertTrue(similarModel.isSimilarTo(model)); } @Test @@ -49,8 +49,8 @@ public void differentServiceUnitListsRuntimeModels() throws Exception { modelWithDifferentServiceUnitList.getContainers().iterator().next() .addServiceUnit(new RuntimeServiceUnit("my-test-su", new URL("file:/artifact/my-test-su.zip"))); - assertFalse(RuntimeModelComparator.compareRuntimeModels(model, modelWithDifferentServiceUnitList)); - assertFalse(RuntimeModelComparator.compareRuntimeModels(modelWithDifferentServiceUnitList, model)); + assertFalse(model.isSimilarTo(modelWithDifferentServiceUnitList)); + assertFalse(modelWithDifferentServiceUnitList.isSimilarTo(model)); } @Test @@ -61,8 +61,8 @@ public void differentComponentListsRuntimeModels() throws Exception { modelWithDifferentComponentList.getContainers().iterator().next() .addComponent(new RuntimeComponent("my-test-comp", new URL("file:/artifact/my-test-comp.zip"))); - assertFalse(RuntimeModelComparator.compareRuntimeModels(model, modelWithDifferentComponentList)); - assertFalse(RuntimeModelComparator.compareRuntimeModels(modelWithDifferentComponentList, model)); + assertFalse(model.isSimilarTo(modelWithDifferentComponentList)); + assertFalse(modelWithDifferentComponentList.isSimilarTo(model)); } @Test @@ -75,7 +75,7 @@ public void differentContainersRuntimeModels() throws Exception { "localhost"); modelWithDifferentContainer.addContainer(differentCont); - assertFalse(RuntimeModelComparator.compareRuntimeModels(model, modelWithDifferentContainer)); - assertFalse(RuntimeModelComparator.compareRuntimeModels(modelWithDifferentContainer, model)); + assertFalse(model.isSimilarTo(modelWithDifferentContainer)); + assertFalse(modelWithDifferentContainer.isSimilarTo(model)); } } diff --git a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java index 48c05fc..d8259c0 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java @@ -53,8 +53,6 @@ public class RuntimeModelDeployerTest { public static void setupLogger() throws Exception { final Logger deployerLogger = Logger.getLogger(RuntimeModelDeployer.class.getName()); deployerLogger.setLevel(Level.FINER); - final Logger comparatorLogger = Logger.getLogger(RuntimeModelComparator.class.getName()); - comparatorLogger.setLevel(Level.FINER); final Handler consoleHandler = new ConsoleHandler(); consoleHandler.setLevel(Level.FINER); final Formatter formatter = new Formatter() { @@ -65,27 +63,26 @@ public String format(final LogRecord record) { }; consoleHandler.setFormatter(formatter); deployerLogger.addHandler(consoleHandler); - comparatorLogger.addHandler(consoleHandler); } @Test public void deployDemoSoap() throws Exception { - RuntimeModel model = new RuntimeModel(); + final RuntimeModel model = new RuntimeModel(); initializeRuntimeModel(model); petalsAdminApiRule.registerDomain(); org.ow2.petals.admin.topology.Container cont = createContainerSample(); petalsAdminApiRule.registerContainer(cont); - ArtifactLifecycleFactoryMock artifactLifecycleFactoryMock = new ArtifactLifecycleFactoryMock(cont); - RuntimeModelDeployer modelDeployer = new RuntimeModelDeployer(petalsAdminApiRule.getSingleton(), + final ArtifactLifecycleFactoryMock artifactLifecycleFactoryMock = new ArtifactLifecycleFactoryMock(cont); + final RuntimeModelDeployer modelDeployer = new RuntimeModelDeployer(petalsAdminApiRule.getSingleton(), artifactLifecycleFactoryMock, JBIDescriptorBuilder.getInstance()); modelDeployer.deployRuntimeModel(model); - RuntimeModelExporter modelExporter = new RuntimeModelExporter(); - RuntimeModel exportedModel = modelExporter.exportRuntimeModel(ModelUtils.CONTAINER_HOST, + final RuntimeModelExporter modelExporter = new RuntimeModelExporter(); + final RuntimeModel exportedModel = modelExporter.exportRuntimeModel(ModelUtils.CONTAINER_HOST, ModelUtils.CONTAINER_JMX_PORT, ModelUtils.CONTAINER_USER, ModelUtils.CONTAINER_PWD, null); - assertTrue(RuntimeModelComparator.compareRuntimeModels(model, exportedModel)); + assertTrue(model.isSimilarTo(exportedModel)); } private org.ow2.petals.admin.topology.Container createContainerSample() { @@ -95,9 +92,9 @@ private org.ow2.petals.admin.topology.Container createContainerSample() { ModelUtils.CONTAINER_USER, ModelUtils.CONTAINER_PWD, ModelUtils.CONTAINER_STATE); } - private void initializeRuntimeModel(RuntimeModel model) throws Exception { + private void initializeRuntimeModel(final RuntimeModel model) throws Exception { - RuntimeContainer cont = new RuntimeContainer(ModelUtils.CONTAINER_NAME, ModelUtils.CONTAINER_JMX_PORT, + final RuntimeContainer cont = new RuntimeContainer(ModelUtils.CONTAINER_NAME, ModelUtils.CONTAINER_JMX_PORT, ModelUtils.CONTAINER_USER, ModelUtils.CONTAINER_PWD, "localhost"); cont.addComponent(new RuntimeComponent("petals-bc-soap", ZipUtils.createZipFromResourceDirectory("artifacts/petals-bc-soap-5.0.0").toURI().toURL())); From f27ebc1ed081dca3b288b83e2cbd774568a42feb Mon Sep 17 00:00:00 2001 From: Alexandre Lagane Date: Fri, 1 Feb 2019 09:29:40 +0100 Subject: [PATCH 19/21] Add draw.io XML class diagram --- src/main/resources/drawio-model.xml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 src/main/resources/drawio-model.xml diff --git a/src/main/resources/drawio-model.xml b/src/main/resources/drawio-model.xml new file mode 100644 index 0000000..ec696b0 --- /dev/null +++ b/src/main/resources/drawio-model.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file From 037d3619f23bd5147c069c100b8657b2e4eb93e4 Mon Sep 17 00:00:00 2001 From: Alexandre Lagane Date: Fri, 1 Feb 2019 09:59:10 +0100 Subject: [PATCH 20/21] Forgot copyrights --- src/main/resources/drawio-model.xml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/main/resources/drawio-model.xml b/src/main/resources/drawio-model.xml index ec696b0..fab42b4 100644 --- a/src/main/resources/drawio-model.xml +++ b/src/main/resources/drawio-model.xml @@ -1,2 +1,19 @@ + \ No newline at end of file From 7ca26db08f5820078a217aa949ef024d8f61f91f Mon Sep 17 00:00:00 2001 From: Alexandre Lagane Date: Fri, 8 Feb 2019 17:05:49 +0100 Subject: [PATCH 21/21] Add tests and refactor --- pom.xml | 35 ++- .../runtimemodel/RuntimeComponent.java | 11 +- .../runtimemodel/RuntimeContainer.java | 11 +- .../deployer/runtimemodel/RuntimeModel.java | 7 + .../runtimemodel/RuntimeServiceUnit.java | 11 +- .../runtimemodel/interfaces/Similar.java | 7 +- .../petals/deployer/utils/ModelConverter.java | 6 + .../petals/deployer/utils/ModelDeployer.java | 72 +++--- .../deployer/utils/RuntimeModelDeployer.java | 34 ++- .../deployer/utils/RuntimeModelExporter.java | 12 +- .../deployer/utils/XmlModelBuilder.java | 108 ++++++++ ...ion.java => ModelDeploymentException.java} | 6 +- .../exceptions/ModelParsingException.java | 31 +++ .../utils/exceptions/UncheckedException.java | 10 - .../runtimemodel/RuntimeComponentTest.java | 67 +++++ .../runtimemodel/RuntimeContainerTest.java | 244 ++++++++++++++++++ .../runtimemodel/RuntimeModelTest.java | 129 +++++++++ .../runtimemodel/RuntimeServiceUnitTest.java | 67 +++++ .../deployer/utils/ModelDeployerTest.java | 50 ++++ .../petals/deployer/utils/ParseModelTest.java | 66 ----- .../utils/RuntimeModelDeployerTest.java | 21 +- .../deployer/utils/XmlModelBuilderTest.java | 50 ++++ .../ow2/petals/deployer/utils/ZipUtils.java | 1 + src/test/resources/model.xml | 54 ++++ 24 files changed, 919 insertions(+), 191 deletions(-) create mode 100644 src/main/java/org/ow2/petals/deployer/utils/XmlModelBuilder.java rename src/main/java/org/ow2/petals/deployer/utils/exceptions/{ModelDeployerException.java => ModelDeploymentException.java} (85%) create mode 100644 src/main/java/org/ow2/petals/deployer/utils/exceptions/ModelParsingException.java create mode 100644 src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponentTest.java create mode 100644 src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainerTest.java create mode 100644 src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeModelTest.java create mode 100644 src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnitTest.java create mode 100644 src/test/java/org/ow2/petals/deployer/utils/ModelDeployerTest.java delete mode 100644 src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java create mode 100644 src/test/java/org/ow2/petals/deployer/utils/XmlModelBuilderTest.java create mode 100644 src/test/resources/model.xml diff --git a/pom.xml b/pom.xml index 30b190d..58992fe 100644 --- a/pom.xml +++ b/pom.xml @@ -40,6 +40,23 @@ 2.1.1-SNAPSHOT + + org.ow2.petals + petals-jbi-descriptor + 2.4.0 + + + + commons-io + commons-io + 2.6 + + + + org.jvnet.jaxb2_commons + jaxb2-basics-runtime + + junit junit @@ -54,20 +71,16 @@ - org.ow2.petals - petals-jbi-descriptor - 2.4.0 - - - - commons-io - commons-io - 2.6 + org.mockito + mockito-core + test - org.jvnet.jaxb2_commons - jaxb2-basics-runtime + xmlunit + xmlunit + 1.6 + test diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java index 4cd929b..c36c299 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponent.java @@ -26,6 +26,7 @@ * @author Alexandre Lagane - Linagora */ public class RuntimeComponent implements Similar { + private final String id; private URL url; @@ -62,16 +63,6 @@ public void setUrl(final URL url) { this.url = url; } - @Override - public boolean equals(final Object obj) { - return obj instanceof RuntimeComponent && id.equals(((RuntimeComponent) obj).id); - } - - @Override - public int hashCode() { - return id.hashCode(); - } - @Override public boolean isSimilarTo(Object o) { return o instanceof RuntimeComponent && this.getId().equals(((RuntimeComponent) o).getId()); diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java index c878a27..1bf059f 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainer.java @@ -30,6 +30,7 @@ * @author Alexandre Lagane - Linagora */ public class RuntimeContainer implements Similar { + private final String id; private int port; @@ -143,16 +144,6 @@ public Collection getComponents() { return components.values(); } - @Override - public boolean equals(final Object obj) { - return obj instanceof RuntimeContainer && id.equals(((RuntimeContainer) obj).id); - } - - @Override - public int hashCode() { - return id.hashCode(); - } - @Override public boolean isSimilarTo(Object o) { if (!(o instanceof RuntimeContainer)) { diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java index c5ffe3c..3e998dd 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeModel.java @@ -29,6 +29,7 @@ * @author Alexandre Lagane - Linagora */ public class RuntimeModel implements Similar { + private final Map containers = new HashMap<>(); /** @@ -42,6 +43,12 @@ public void addContainer(final RuntimeContainer container) throws DuplicatedCont } } + /** + * Return the RuntimeContainer with identifier id, or {code null} if not in the model. + * + * @param id + * @return RuntimeContainer or null + */ public RuntimeContainer getContainer(final String id) { return containers.get(id); } diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java index 5c86348..c2c9b44 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnit.java @@ -26,6 +26,7 @@ * @author Alexandre Lagane - Linagora */ public class RuntimeServiceUnit implements Similar { + private final String id; private URL url; @@ -61,16 +62,6 @@ public void setUrl(final URL url) { this.url = url; } - @Override - public boolean equals(final Object obj) { - return obj instanceof RuntimeServiceUnit && id.equals(((RuntimeServiceUnit) obj).id); - } - - @Override - public int hashCode() { - return id.hashCode(); - } - @Override public boolean isSimilarTo(Object o) { return o instanceof RuntimeServiceUnit && this.getId().equals(((RuntimeServiceUnit) o).getId()); diff --git a/src/main/java/org/ow2/petals/deployer/runtimemodel/interfaces/Similar.java b/src/main/java/org/ow2/petals/deployer/runtimemodel/interfaces/Similar.java index 5eb00a0..a918041 100644 --- a/src/main/java/org/ow2/petals/deployer/runtimemodel/interfaces/Similar.java +++ b/src/main/java/org/ow2/petals/deployer/runtimemodel/interfaces/Similar.java @@ -22,11 +22,16 @@ * @author Alexandre Lagane - Linagora */ public interface Similar { + /** * Return true if current object and o are similar. * + * RuntimeModel deployed to Petals, and RuntimeModel exported from the deployed Petals will return {code true} when + * compared using isSimilarTo method. {code o1.isSimilarTo(o2)} will always yield the same result as {code + * o2.isSimilarTo(o1)}. + * * @param o - * object compared with current object + * object compared to current object * @return true if similar */ public boolean isSimilarTo(Object o); diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java b/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java index 908aede..94b51a3 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java +++ b/src/main/java/org/ow2/petals/deployer/utils/ModelConverter.java @@ -41,9 +41,15 @@ import org.ow2.petals.deployer.runtimemodel.exceptions.RuntimeModelException; /** + * This is an utility class and should not be instanciated. + * * @author Alexandre Lagane - Linagora */ public class ModelConverter { + + private ModelConverter() { + } + public static RuntimeModel convertModelToRuntimeModel(final Model model) throws MalformedURLException, RuntimeModelException { final RuntimeModel runtimeModel = new RuntimeModel(); diff --git a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java index d324f1a..af87f19 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java +++ b/src/main/java/org/ow2/petals/deployer/utils/ModelDeployer.java @@ -18,20 +18,12 @@ package org.ow2.petals.deployer.utils; -import java.io.File; import java.net.URL; -import java.nio.file.Files; import java.util.logging.Logger; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.Unmarshaller; -import javax.xml.transform.stream.StreamSource; - -import org.apache.commons.io.FileUtils; import org.ow2.petals.deployer.model.xml._1.Model; import org.ow2.petals.deployer.runtimemodel.RuntimeModel; -import org.ow2.petals.deployer.utils.exceptions.ModelDeployerException; -import org.ow2.petals.deployer.utils.exceptions.UncheckedException; +import org.ow2.petals.deployer.utils.exceptions.ModelDeploymentException; /** * The main class used for deploying XML models. @@ -50,25 +42,24 @@ public class ModelDeployer { */ public static final int READ_TIMEOUT = 5000; - private static final Logger LOG = Logger.getLogger(ModelDeployer.class.getName()); + private final static Logger LOG = Logger.getLogger(ModelDeployer.class.getName()); - private static final Unmarshaller UNMARSHALLER; - static { - try { - final JAXBContext jaxbContext = JAXBContext.newInstance(Model.class); - UNMARSHALLER = jaxbContext.createUnmarshaller(); - } catch (final Exception e) { - throw new UncheckedException(e); - } + private final RuntimeModelDeployer runtimeModelDeployer; + + private static ModelDeployer instance; + + public ModelDeployer() { + this(null); } - private static final RuntimeModelDeployer DEPLOYER; - static { - try { - DEPLOYER = new RuntimeModelDeployer(); - } catch (final Exception e) { - throw new UncheckedException(e); - } + /** + * Used only for testing purposes, to mock runtimeModelDeployer. + * + * @param runtimeModelDeployer + */ + protected ModelDeployer(RuntimeModelDeployer runtimeModelDeployer) { + this.runtimeModelDeployer = runtimeModelDeployer != null ? runtimeModelDeployer : new RuntimeModelDeployer(); + instance = this; } /** @@ -76,26 +67,27 @@ public class ModelDeployer { * directory. * * @param url - * @throws ModelDeployerException + * @throws ModelDeploymentException */ - public static void deployModel(final URL url) throws ModelDeployerException { - final File modelFile; - try { - LOG.fine("Downloadind XML model"); + public void deployModel(final URL url) throws ModelDeploymentException { + final Model model = XmlModelBuilder.readModelFromUrl(url); - modelFile = Files.createTempFile("model", ".xml").toFile(); - FileUtils.copyURLToFile(url, modelFile, CONNECTION_TIMEOUT, READ_TIMEOUT); - - LOG.fine("Parsing XML model"); + deployModel(model); + } - final Model model = UNMARSHALLER.unmarshal(new StreamSource(modelFile), Model.class).getValue(); + public void deployModel(Model model) throws ModelDeploymentException { + RuntimeModel runtimeModel; + try { + runtimeModel = ModelConverter.convertModelToRuntimeModel(model); - final RuntimeModel runtimeModel = ModelConverter.convertModelToRuntimeModel(model); + runtimeModelDeployer.deployRuntimeModel(runtimeModel); + } catch (Exception e) { + throw new ModelDeploymentException(e); + } - DEPLOYER.deployRuntimeModel(runtimeModel); + } - } catch (final Exception e) { - throw new ModelDeployerException(e); - } + public static ModelDeployer getInstance() { + return instance != null ? instance : new ModelDeployer(); } } diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java index dbbf819..f8a2ead 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelDeployer.java @@ -40,14 +40,13 @@ import org.ow2.petals.admin.api.exception.ArtifactStartedException; import org.ow2.petals.admin.api.exception.ConnectionFailedException; import org.ow2.petals.admin.api.exception.ContainerAdministrationException; -import org.ow2.petals.admin.api.exception.DuplicatedServiceException; -import org.ow2.petals.admin.api.exception.MissingServiceException; import org.ow2.petals.deployer.runtimemodel.RuntimeComponent; import org.ow2.petals.deployer.runtimemodel.RuntimeContainer; import org.ow2.petals.deployer.runtimemodel.RuntimeModel; import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit; import org.ow2.petals.deployer.utils.exceptions.ComponentDeploymentException; import org.ow2.petals.deployer.utils.exceptions.RuntimeModelDeployerException; +import org.ow2.petals.deployer.utils.exceptions.UncheckedException; import org.ow2.petals.jbi.descriptor.JBIDescriptorException; import org.ow2.petals.jbi.descriptor.original.JBIDescriptorBuilder; import org.ow2.petals.jbi.descriptor.original.generated.Jbi; @@ -58,7 +57,7 @@ */ public class RuntimeModelDeployer { - private static final Logger LOG = Logger.getLogger(RuntimeModelDeployer.class.getName()); + private final static Logger LOG = Logger.getLogger(RuntimeModelDeployer.class.getName()); private final PetalsAdministration petalsAdmin; @@ -66,18 +65,27 @@ public class RuntimeModelDeployer { private final JBIDescriptorBuilder jdb; - public RuntimeModelDeployer() throws DuplicatedServiceException, MissingServiceException, JBIDescriptorException { - this(PetalsAdministrationFactory.getInstance().newPetalsAdministrationAPI(), null, - JBIDescriptorBuilder.getInstance()); - + public RuntimeModelDeployer() { + this(null, null); } - public RuntimeModelDeployer(final PetalsAdministration petalsAdmin, - final ArtifactLifecycleFactory artifactLifecycleFactory, final JBIDescriptorBuilder jdb) { - this.petalsAdmin = petalsAdmin; - this.artifactLifecycleFactory = artifactLifecycleFactory != null ? artifactLifecycleFactory - : petalsAdmin.newArtifactLifecycleFactory(); - this.jdb = jdb; + /** + * Used only for testing purposes, to mock petalsAdmin and artifactLifecycleFactory. + * + * @param petalsAdmin + * @param artifactLifecycleFactory + */ + protected RuntimeModelDeployer(final PetalsAdministration petalsAdmin, + final ArtifactLifecycleFactory artifactLifecycleFactory) { + try { + this.petalsAdmin = petalsAdmin != null ? petalsAdmin + : PetalsAdministrationFactory.getInstance().newPetalsAdministrationAPI(); + this.artifactLifecycleFactory = artifactLifecycleFactory != null ? artifactLifecycleFactory + : this.petalsAdmin.newArtifactLifecycleFactory(); + this.jdb = JBIDescriptorBuilder.getInstance(); + } catch (JBIDescriptorException e) { + throw new UncheckedException(e); + } } public void deployRuntimeModel(final RuntimeModel model) diff --git a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java index dbb9834..6f15b11 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java +++ b/src/main/java/org/ow2/petals/deployer/utils/RuntimeModelExporter.java @@ -47,12 +47,13 @@ public class RuntimeModelExporter { private final ArtifactAdministration artifactAdmin; public RuntimeModelExporter() throws DuplicatedServiceException, MissingServiceException, JBIDescriptorException { - this(PetalsAdministrationFactory.getInstance().newPetalsAdministrationAPI()); + this(null); } public RuntimeModelExporter(final PetalsAdministration petalsAdmin) { - this.petalsAdmin = petalsAdmin; - artifactAdmin = petalsAdmin.newArtifactAdministration(); + this.petalsAdmin = petalsAdmin != null ? petalsAdmin + : PetalsAdministrationFactory.getInstance().newPetalsAdministrationAPI(); + artifactAdmin = this.petalsAdmin.newArtifactAdministration(); } /** @@ -95,10 +96,9 @@ public RuntimeModel exportRuntimeModel(final String hostname, final int port, fi // already get service units in "SU" case break; case "SL": - throw new UnsupportedOperationException( - "Export model with shared libraries is not implemented yet"); default: - LOG.warning("Unknown artifact type " + artifact.getType()); + throw new UnsupportedOperationException( + "Export model with artifact of type " + artifact.getType() + " is not implemented yet"); } } diff --git a/src/main/java/org/ow2/petals/deployer/utils/XmlModelBuilder.java b/src/main/java/org/ow2/petals/deployer/utils/XmlModelBuilder.java new file mode 100644 index 0000000..e45656a --- /dev/null +++ b/src/main/java/org/ow2/petals/deployer/utils/XmlModelBuilder.java @@ -0,0 +1,108 @@ +/** + * Copyright (c) 2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.utils; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.nio.file.Files; +import java.util.logging.Logger; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import javax.xml.transform.stream.StreamSource; + +import org.apache.commons.io.FileUtils; +import org.ow2.petals.deployer.model.xml._1.Model; +import org.ow2.petals.deployer.model.xml._1.ObjectFactory; +import org.ow2.petals.deployer.utils.exceptions.ModelParsingException; +import org.ow2.petals.deployer.utils.exceptions.UncheckedException; + +/** + * @author Alexandre Lagane - Linagora + * + */ +public class XmlModelBuilder { + + private final static Logger LOG = Logger.getLogger(XmlModelBuilder.class.getName()); + + private final static Marshaller MARSHALLER; + + private final static Unmarshaller UNMARSHALLER; + + private final static ObjectFactory OF = new ObjectFactory(); + + static { + try { + final JAXBContext jaxbContext = JAXBContext.newInstance(Model.class); + MARSHALLER = jaxbContext.createMarshaller(); + MARSHALLER.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + UNMARSHALLER = jaxbContext.createUnmarshaller(); + } catch (JAXBException e) { + throw new UncheckedException(e); + } + } + + /** + * Read the model at the url. The model must be an XML model (with schema defined in {code model.xsd} in resources + * directory) + * + * @param url + * @return the read model + * @throws ModelParsingException + */ + public static Model readModelFromUrl(final URL url) throws ModelParsingException { + LOG.fine("Downloadind XML model"); + File modelFile; + try { + modelFile = Files.createTempFile("model", ".xml").toFile(); + } catch (IOException e) { + throw new UncheckedException(e); + } + try { + FileUtils.copyURLToFile(url, modelFile, ModelDeployer.CONNECTION_TIMEOUT, ModelDeployer.READ_TIMEOUT); + + LOG.fine("Parsing XML model"); + return UNMARSHALLER.unmarshal(new StreamSource(modelFile), Model.class).getValue(); + } catch (IOException | JAXBException e) { + throw new ModelParsingException(e); + } + + } + + /** + * Write model to file. The same file is returned if model is successfully written. + * + * @param model + * @param file + * @return file if successfully written else null + * @throws ModelParsingException + */ + public static File writeModelToFile(Model model, File file) throws ModelParsingException { + try { + MARSHALLER.marshal(OF.createModel(model), file); + return file; + } catch (JAXBException e) { + throw new ModelParsingException(e); + } + + } +} diff --git a/src/main/java/org/ow2/petals/deployer/utils/exceptions/ModelDeployerException.java b/src/main/java/org/ow2/petals/deployer/utils/exceptions/ModelDeploymentException.java similarity index 85% rename from src/main/java/org/ow2/petals/deployer/utils/exceptions/ModelDeployerException.java rename to src/main/java/org/ow2/petals/deployer/utils/exceptions/ModelDeploymentException.java index 7925ab7..4d63f9f 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/exceptions/ModelDeployerException.java +++ b/src/main/java/org/ow2/petals/deployer/utils/exceptions/ModelDeploymentException.java @@ -21,15 +21,15 @@ /** * @author Alexandre Lagane - Linagora */ -public class ModelDeployerException extends Exception { +public class ModelDeploymentException extends Exception { private static final long serialVersionUID = 7599724111843987402L; - public ModelDeployerException(final Throwable cause) { + public ModelDeploymentException(final Throwable cause) { super(cause); } - public ModelDeployerException(final String message) { + public ModelDeploymentException(final String message) { super(message); } } diff --git a/src/main/java/org/ow2/petals/deployer/utils/exceptions/ModelParsingException.java b/src/main/java/org/ow2/petals/deployer/utils/exceptions/ModelParsingException.java new file mode 100644 index 0000000..181bad6 --- /dev/null +++ b/src/main/java/org/ow2/petals/deployer/utils/exceptions/ModelParsingException.java @@ -0,0 +1,31 @@ +/** + * Copyright (c) 2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.utils.exceptions; + +/** + * @author Alexandre Lagane - Linagora + */ +public class ModelParsingException extends ModelDeploymentException { + + private static final long serialVersionUID = 6061886715747572320L; + + public ModelParsingException(final Throwable cause) { + super(cause); + } +} diff --git a/src/main/java/org/ow2/petals/deployer/utils/exceptions/UncheckedException.java b/src/main/java/org/ow2/petals/deployer/utils/exceptions/UncheckedException.java index 679e69d..909a767 100644 --- a/src/main/java/org/ow2/petals/deployer/utils/exceptions/UncheckedException.java +++ b/src/main/java/org/ow2/petals/deployer/utils/exceptions/UncheckedException.java @@ -19,9 +19,7 @@ package org.ow2.petals.deployer.utils.exceptions; /** - * * @author Alexandre Lagane - Linagora - * */ public class UncheckedException extends RuntimeException { @@ -30,12 +28,4 @@ public class UncheckedException extends RuntimeException { public UncheckedException(final Throwable cause) { super(cause); } - - public UncheckedException(final String message, final Throwable cause) { - super(message, cause); - } - - public UncheckedException(final String message) { - super(message); - } } diff --git a/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponentTest.java b/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponentTest.java new file mode 100644 index 0000000..b680028 --- /dev/null +++ b/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeComponentTest.java @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ +package org.ow2.petals.deployer.runtimemodel; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.net.URL; + +import org.junit.Test; + +/** + * @author Alexandre Lagane - Linagora + */ +public class RuntimeComponentTest { + + @Test + public void runtimeComponentGetters() throws Exception { + URL url = new URL("file:/comp.zip"); + + RuntimeComponent comp = new RuntimeComponent("comp"); + assertEquals("comp", comp.getId()); + assertNull(comp.getUrl()); + + comp.setUrl(url); + assertEquals(url, comp.getUrl()); + + comp = new RuntimeComponent("comp", url); + assertEquals("comp", comp.getId()); + assertEquals(url, comp.getUrl()); + } + + @Test + public void similarRuntimeComponents() throws Exception { + RuntimeComponent comp1 = new RuntimeComponent("comp", new URL("file:/comp.zip")); + RuntimeComponent comp2 = new RuntimeComponent("comp", new URL("file:/other-comp.zip")); + + assertTrue(comp1.isSimilarTo(comp2)); + assertTrue(comp2.isSimilarTo(comp1)); + } + + @Test + public void notSimilarRuntimeComponents() throws Exception { + RuntimeComponent comp = new RuntimeComponent("comp", new URL("file:/comp.zip")); + RuntimeComponent compWithDifferentId = new RuntimeComponent("differentId", new URL("file:/comp.zip")); + + assertFalse(comp.isSimilarTo(compWithDifferentId)); + assertFalse(compWithDifferentId.isSimilarTo(comp)); + } +} diff --git a/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainerTest.java b/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainerTest.java new file mode 100644 index 0000000..60235f9 --- /dev/null +++ b/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeContainerTest.java @@ -0,0 +1,244 @@ +/** + * Copyright (c) 2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.runtimemodel; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.Collection; + +import org.junit.Test; +import org.ow2.petals.deployer.runtimemodel.exceptions.DuplicatedComponentException; +import org.ow2.petals.deployer.runtimemodel.exceptions.DuplicatedServiceUnitException; + +/** + * @author Alexandre Lagane - Linagora + */ +public class RuntimeContainerTest { + + @Test + public void runtimeContainerGetters() throws Exception { + RuntimeContainer cont = new RuntimeContainer("cont", 7700, "user", "password", "localhost"); + + assertEquals("cont", cont.getId()); + assertEquals(7700, cont.getPort()); + assertEquals("user", cont.getUser()); + assertEquals("password", cont.getPassword()); + assertEquals("localhost", cont.getHostname()); + + cont.setHostname("192.168.1.42"); + assertEquals("192.168.1.42", cont.getHostname()); + + Collection components = cont.getComponents(); + + assertEquals(0, components.size()); + assertNull(cont.getComponent("comp1")); + assertNull(cont.getComponent("comp2")); + + RuntimeComponent mockComp1 = mock(RuntimeComponent.class); + when(mockComp1.getId()).thenReturn("comp1"); + cont.addComponent(mockComp1); + + assertEquals(1, components.size()); + assertSame(mockComp1, cont.getComponent("comp1")); + assertNull(cont.getComponent("comp2")); + + RuntimeComponent mockComp2 = mock(RuntimeComponent.class); + when(mockComp2.getId()).thenReturn("comp2"); + cont.addComponent(mockComp2); + + assertEquals(2, components.size()); + assertSame(mockComp1, cont.getComponent("comp1")); + assertSame(mockComp2, cont.getComponent("comp2")); + + Collection serviceUnits = cont.getServiceUnits(); + + assertEquals(0, serviceUnits.size()); + assertNull(cont.getServiceUnit("su1")); + assertNull(cont.getServiceUnit("su2")); + + RuntimeServiceUnit mockSu1 = mock(RuntimeServiceUnit.class); + when(mockSu1.getId()).thenReturn("su1"); + cont.addServiceUnit(mockSu1); + + assertEquals(1, serviceUnits.size()); + assertSame(mockSu1, cont.getServiceUnit("su1")); + assertNull(cont.getServiceUnit("su2")); + + RuntimeServiceUnit mockSu2 = mock(RuntimeServiceUnit.class); + when(mockSu2.getId()).thenReturn("su2"); + cont.addServiceUnit(mockSu2); + + assertEquals(2, serviceUnits.size()); + assertSame(mockSu1, cont.getServiceUnit("su1")); + assertSame(mockSu2, cont.getServiceUnit("su2")); + } + + @Test + public void duplicatedComponentException() throws Exception { + RuntimeContainer cont = new RuntimeContainer("cont", 7700, "user", "password", "localhost"); + + RuntimeComponent mockComp = mock(RuntimeComponent.class); + when(mockComp.getId()).thenReturn("comp"); + cont.addComponent(mockComp); + + RuntimeComponent mockCompWithSameId = mock(RuntimeComponent.class); + when(mockCompWithSameId.getId()).thenReturn("comp"); + try { + cont.addComponent(mockCompWithSameId); + fail("Should have caught DuplicatedComponentException"); + } catch (DuplicatedComponentException e) { + } + } + + @Test + public void duplicatedServiceUnitException() throws Exception { + RuntimeContainer cont = new RuntimeContainer("cont", 7700, "user", "password", "localhost"); + + RuntimeServiceUnit mockSu = mock(RuntimeServiceUnit.class); + when(mockSu.getId()).thenReturn("su"); + cont.addServiceUnit(mockSu); + + RuntimeServiceUnit mockSuWithSameId = mock(RuntimeServiceUnit.class); + when(mockSuWithSameId.getId()).thenReturn("su"); + try { + cont.addServiceUnit(mockSuWithSameId); + fail("Should have caught DuplicatedServiceUnitException"); + } catch (DuplicatedServiceUnitException e) { + } + } + + @Test + public void similarContainers() throws Exception { + RuntimeContainer cont1 = new RuntimeContainer("cont", 7700, "user", "password", "localhost"); + RuntimeContainer cont2 = new RuntimeContainer("cont", 7700, "user", "password", "localhost"); + + assertTrue(cont1.isSimilarTo(cont2)); + assertTrue(cont2.isSimilarTo(cont1)); + + RuntimeComponent mockComp1Cont1 = mock(RuntimeComponent.class); + RuntimeComponent mockComp2Cont1 = mock(RuntimeComponent.class); + RuntimeComponent mockComp1Cont2 = mock(RuntimeComponent.class); + RuntimeComponent mockComp2Cont2 = mock(RuntimeComponent.class); + + when(mockComp1Cont1.getId()).thenReturn("comp1"); + when(mockComp1Cont1.isSimilarTo(any())).thenReturn(false); + when(mockComp1Cont1.isSimilarTo(mockComp1Cont2)).thenReturn(true); + + when(mockComp2Cont1.getId()).thenReturn("comp2"); + when(mockComp2Cont1.isSimilarTo(any())).thenReturn(false); + when(mockComp2Cont1.isSimilarTo(mockComp2Cont2)).thenReturn(true); + + when(mockComp1Cont2.getId()).thenReturn("comp1"); + when(mockComp1Cont2.isSimilarTo(any())).thenReturn(false); + when(mockComp1Cont2.isSimilarTo(mockComp1Cont1)).thenReturn(true); + + when(mockComp2Cont2.getId()).thenReturn("comp2"); + when(mockComp2Cont2.isSimilarTo(any())).thenReturn(false); + when(mockComp2Cont2.isSimilarTo(mockComp2Cont1)).thenReturn(true); + + cont1.addComponent(mockComp1Cont1); + assertFalse(cont1.isSimilarTo(cont2)); + assertFalse(cont2.isSimilarTo(cont1)); + + cont1.addComponent(mockComp2Cont1); + assertFalse(cont1.isSimilarTo(cont2)); + assertFalse(cont2.isSimilarTo(cont1)); + + cont2.addComponent(mockComp2Cont2); + assertFalse(cont1.isSimilarTo(cont2)); + assertFalse(cont2.isSimilarTo(cont1)); + + cont2.addComponent(mockComp1Cont2); + assertTrue(cont1.isSimilarTo(cont2)); + assertTrue(cont2.isSimilarTo(cont1)); + + RuntimeServiceUnit mockSu1Cont1 = mock(RuntimeServiceUnit.class); + RuntimeServiceUnit mockSu2Cont1 = mock(RuntimeServiceUnit.class); + RuntimeServiceUnit mockSu1Cont2 = mock(RuntimeServiceUnit.class); + RuntimeServiceUnit mockSu2Cont2 = mock(RuntimeServiceUnit.class); + + when(mockSu1Cont1.getId()).thenReturn("su1"); + when(mockSu1Cont1.isSimilarTo(any())).thenReturn(false); + when(mockSu1Cont1.isSimilarTo(mockSu1Cont2)).thenReturn(true); + + when(mockSu2Cont1.getId()).thenReturn("su2"); + when(mockSu2Cont1.isSimilarTo(any())).thenReturn(false); + when(mockSu2Cont1.isSimilarTo(mockSu2Cont2)).thenReturn(true); + + when(mockSu1Cont2.getId()).thenReturn("su1"); + when(mockSu1Cont2.isSimilarTo(any())).thenReturn(false); + when(mockSu1Cont2.isSimilarTo(mockSu1Cont1)).thenReturn(true); + + when(mockSu2Cont2.getId()).thenReturn("su2"); + when(mockSu2Cont2.isSimilarTo(any())).thenReturn(false); + when(mockSu2Cont2.isSimilarTo(mockSu2Cont1)).thenReturn(true); + + cont1.addServiceUnit(mockSu1Cont1); + assertFalse(cont1.isSimilarTo(cont2)); + assertFalse(cont2.isSimilarTo(cont1)); + + cont1.addServiceUnit(mockSu2Cont1); + assertFalse(cont1.isSimilarTo(cont2)); + assertFalse(cont2.isSimilarTo(cont1)); + + cont2.addServiceUnit(mockSu2Cont2); + assertFalse(cont1.isSimilarTo(cont2)); + assertFalse(cont2.isSimilarTo(cont1)); + + cont2.addServiceUnit(mockSu1Cont2); + assertTrue(cont1.isSimilarTo(cont2)); + assertTrue(cont2.isSimilarTo(cont1)); + } + + @Test + public void notSimilarContainers() { + RuntimeContainer cont = new RuntimeContainer("cont", 7700, "user", "password", "localhost"); + + RuntimeContainer contWithDifferentId = new RuntimeContainer("otherId", 7700, "user", "password", "localhost"); + assertFalse(cont.isSimilarTo(contWithDifferentId)); + assertFalse(contWithDifferentId.isSimilarTo(cont)); + + RuntimeContainer contWithDifferentPort = new RuntimeContainer("cont", 9999, "user", "password", "localhost"); + assertFalse(cont.isSimilarTo(contWithDifferentPort)); + assertFalse(contWithDifferentPort.isSimilarTo(cont)); + + RuntimeContainer contWithDifferentUser = new RuntimeContainer("cont", 7700, "otherUser", "password", + "localhost"); + assertFalse(cont.isSimilarTo(contWithDifferentUser)); + assertFalse(contWithDifferentUser.isSimilarTo(cont)); + + RuntimeContainer contWithDifferentPassword = new RuntimeContainer("cont", 7700, "user", "otherPassword", + "localhost"); + assertFalse(cont.isSimilarTo(contWithDifferentPassword)); + assertFalse(contWithDifferentPassword.isSimilarTo(cont)); + + RuntimeContainer contWithDifferentHostname = new RuntimeContainer("cont", 7700, "user", "password", + "192.168.1.42"); + assertFalse(cont.isSimilarTo(contWithDifferentHostname)); + assertFalse(contWithDifferentHostname.isSimilarTo(cont)); + } +} diff --git a/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeModelTest.java b/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeModelTest.java new file mode 100644 index 0000000..f3ebdce --- /dev/null +++ b/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeModelTest.java @@ -0,0 +1,129 @@ +/** + * Copyright (c) 2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.runtimemodel; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.Collection; + +import org.junit.Test; +import org.ow2.petals.deployer.runtimemodel.exceptions.DuplicatedContainerException; + +/** + * @author Alexandre Lagane - Linagora + */ +public class RuntimeModelTest { + + @Test + public void runtimeModelGetters() throws Exception { + RuntimeModel model = new RuntimeModel(); + Collection containers = model.getContainers(); + + assertEquals(0, containers.size()); + assertNull(model.getContainer("cont1")); + assertNull(model.getContainer("cont2")); + + RuntimeContainer mockCont1 = mock(RuntimeContainer.class); + when(mockCont1.getId()).thenReturn("cont1"); + model.addContainer(mockCont1); + + assertEquals(1, containers.size()); + assertSame(mockCont1, model.getContainer("cont1")); + assertNull(model.getContainer("cont2")); + + RuntimeContainer mockCont2 = mock(RuntimeContainer.class); + when(mockCont2.getId()).thenReturn("cont2"); + model.addContainer(mockCont2); + + assertEquals(2, containers.size()); + assertSame(mockCont1, model.getContainer("cont1")); + assertSame(mockCont2, model.getContainer("cont2")); + } + + @Test + public void runtimeModelDuplicatedContainerException() throws Exception { + RuntimeModel model = new RuntimeModel(); + + RuntimeContainer mockCont = mock(RuntimeContainer.class); + when(mockCont.getId()).thenReturn("cont"); + model.addContainer(mockCont); + + RuntimeContainer mockContWithSameId = mock(RuntimeContainer.class); + when(mockContWithSameId.getId()).thenReturn("cont"); + try { + model.addContainer(mockContWithSameId); + fail("Should have caught DuplicatedContainerException"); + } catch (DuplicatedContainerException e) { + } + } + + @Test + public void similarRuntimeModels() throws Exception { + RuntimeModel model1 = new RuntimeModel(); + RuntimeModel model2 = new RuntimeModel(); + + assertTrue(model1.isSimilarTo(model2)); + assertTrue(model2.isSimilarTo(model1)); + + RuntimeContainer mockCont1Model1 = mock(RuntimeContainer.class); + RuntimeContainer mockCont2Model1 = mock(RuntimeContainer.class); + RuntimeContainer mockCont1Model2 = mock(RuntimeContainer.class); + RuntimeContainer mockCont2Model2 = mock(RuntimeContainer.class); + + when(mockCont1Model1.getId()).thenReturn("cont1"); + when(mockCont1Model1.isSimilarTo(any())).thenReturn(false); + when(mockCont1Model1.isSimilarTo(mockCont1Model2)).thenReturn(true); + + when(mockCont2Model1.getId()).thenReturn("cont2"); + when(mockCont2Model1.isSimilarTo(any())).thenReturn(false); + when(mockCont2Model1.isSimilarTo(mockCont2Model2)).thenReturn(true); + + when(mockCont1Model2.getId()).thenReturn("cont1"); + when(mockCont1Model2.isSimilarTo(any())).thenReturn(false); + when(mockCont1Model2.isSimilarTo(mockCont1Model1)).thenReturn(true); + + when(mockCont2Model2.getId()).thenReturn("cont2"); + when(mockCont2Model2.isSimilarTo(any())).thenReturn(false); + when(mockCont2Model2.isSimilarTo(mockCont2Model1)).thenReturn(true); + + model1.addContainer(mockCont1Model1); + assertFalse(model1.isSimilarTo(model2)); + assertFalse(model2.isSimilarTo(model1)); + + model1.addContainer(mockCont2Model1); + assertFalse(model1.isSimilarTo(model2)); + assertFalse(model2.isSimilarTo(model1)); + + model2.addContainer(mockCont1Model2); + assertFalse(model1.isSimilarTo(model2)); + assertFalse(model2.isSimilarTo(model1)); + + model2.addContainer(mockCont2Model2); + assertTrue(model1.isSimilarTo(model2)); + assertTrue(model2.isSimilarTo(model1)); + } +} diff --git a/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnitTest.java b/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnitTest.java new file mode 100644 index 0000000..1bfaeb4 --- /dev/null +++ b/src/test/java/org/ow2/petals/deployer/runtimemodel/RuntimeServiceUnitTest.java @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ +package org.ow2.petals.deployer.runtimemodel; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.net.URL; + +import org.junit.Test; + +/** + * @author Alexandre Lagane - Linagora + */ +public class RuntimeServiceUnitTest { + + @Test + public void runtimeServiceUnitGetters() throws Exception { + URL url = new URL("file:/su.zip"); + + RuntimeServiceUnit su = new RuntimeServiceUnit("su"); + assertEquals("su", su.getId()); + assertNull(su.getUrl()); + + su.setUrl(url); + assertEquals(url, su.getUrl()); + + su = new RuntimeServiceUnit("su", url); + assertEquals("su", su.getId()); + assertEquals(url, su.getUrl()); + } + + @Test + public void similarRuntimeComponents() throws Exception { + RuntimeServiceUnit su = new RuntimeServiceUnit("su", new URL("file:/su.zip")); + RuntimeServiceUnit suWithDifferentUrl = new RuntimeServiceUnit("su", new URL("file:/other-url.zip")); + + assertTrue(su.isSimilarTo(suWithDifferentUrl)); + assertTrue(suWithDifferentUrl.isSimilarTo(su)); + } + + @Test + public void notSimilarRuntimeComponents() throws Exception { + RuntimeServiceUnit su = new RuntimeServiceUnit("su", new URL("file:/su.zip")); + RuntimeServiceUnit suWithDifferentId = new RuntimeServiceUnit("differentId", new URL("file:/su.zip")); + + assertFalse(su.isSimilarTo(suWithDifferentId)); + assertFalse(suWithDifferentId.isSimilarTo(su)); + } +} diff --git a/src/test/java/org/ow2/petals/deployer/utils/ModelDeployerTest.java b/src/test/java/org/ow2/petals/deployer/utils/ModelDeployerTest.java new file mode 100644 index 0000000..88e4120 --- /dev/null +++ b/src/test/java/org/ow2/petals/deployer/utils/ModelDeployerTest.java @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ + +package org.ow2.petals.deployer.utils; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; + +import java.net.URL; + +import org.junit.Test; +import org.ow2.petals.deployer.runtimemodel.RuntimeModel; + +public class ModelDeployerTest { + + private RuntimeModelDeployer runtimeModelDeployerMock = mock(RuntimeModelDeployer.class); + + private ModelDeployer modelDeployer = new ModelDeployer(runtimeModelDeployerMock); + + @Test + public void deployModelFile() throws Exception { + URL modelUrl = Thread.currentThread().getContextClassLoader().getResource("model.xml").toURI().toURL(); + modelDeployer.deployModel(modelUrl); + + verify(runtimeModelDeployerMock).deployRuntimeModel(any(RuntimeModel.class)); + } + + @Test + public void deployModel() throws Exception { + modelDeployer.deployModel(ModelUtils.generateTestModel()); + + verify(runtimeModelDeployerMock).deployRuntimeModel(any(RuntimeModel.class)); + } +} diff --git a/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java b/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java deleted file mode 100644 index 9a4f14d..0000000 --- a/src/test/java/org/ow2/petals/deployer/utils/ParseModelTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Copyright (c) 2018-2019 Linagora - * - * This program/library is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 2.1 of the License, or (at your - * option) any later version. - * - * This program/library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program/library; If not, see http://www.gnu.org/licenses/ - * for the GNU Lesser General Public License version 2.1. - */ - -package org.ow2.petals.deployer.utils; - -import static org.junit.Assert.assertEquals; - -import java.io.StringReader; -import java.io.StringWriter; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; -import javax.xml.transform.stream.StreamSource; - -import org.junit.Test; -import org.ow2.petals.deployer.model.xml._1.Model; -import org.ow2.petals.deployer.model.xml._1.ObjectFactory; - -/** - * @author Alexandre Lagane - Linagora - */ -public class ParseModelTest { - - @Test - public void parseModel() throws Exception { - final ObjectFactory of = new ObjectFactory(); - - final Model model = ModelUtils.generateTestModel(); - - final StringWriter marshalledModelWriter = new StringWriter(); - final StringWriter unmarshalledModelWriter = new StringWriter(); - - final JAXBContext jaxbContext = JAXBContext.newInstance(Model.class); - - final Marshaller marshaller = jaxbContext.createMarshaller(); - final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); - - marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); - - marshaller.marshal(of.createModel(model), marshalledModelWriter); - - final Model unmarshalledModel = unmarshaller - .unmarshal(new StreamSource(new StringReader(marshalledModelWriter.toString())), Model.class) - .getValue(); - - marshaller.marshal(of.createModel(unmarshalledModel), unmarshalledModelWriter); - - assertEquals(marshalledModelWriter.toString(), unmarshalledModelWriter.toString()); - } -} diff --git a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java index d8259c0..c717ffd 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java +++ b/src/test/java/org/ow2/petals/deployer/utils/RuntimeModelDeployerTest.java @@ -39,7 +39,6 @@ import org.ow2.petals.deployer.runtimemodel.RuntimeContainer; import org.ow2.petals.deployer.runtimemodel.RuntimeModel; import org.ow2.petals.deployer.runtimemodel.RuntimeServiceUnit; -import org.ow2.petals.jbi.descriptor.original.JBIDescriptorBuilder; /** * @author Alexandre Lagane - Linagora @@ -66,36 +65,36 @@ public String format(final LogRecord record) { } @Test - public void deployDemoSoap() throws Exception { - final RuntimeModel model = new RuntimeModel(); - initializeRuntimeModel(model); - + public void deployRuntimeModel() throws Exception { petalsAdminApiRule.registerDomain(); org.ow2.petals.admin.topology.Container cont = createContainerSample(); petalsAdminApiRule.registerContainer(cont); final ArtifactLifecycleFactoryMock artifactLifecycleFactoryMock = new ArtifactLifecycleFactoryMock(cont); final RuntimeModelDeployer modelDeployer = new RuntimeModelDeployer(petalsAdminApiRule.getSingleton(), - artifactLifecycleFactoryMock, JBIDescriptorBuilder.getInstance()); + artifactLifecycleFactoryMock); + + final RuntimeModel model = generateRuntimeModel(); modelDeployer.deployRuntimeModel(model); - final RuntimeModelExporter modelExporter = new RuntimeModelExporter(); + final RuntimeModelExporter modelExporter = new RuntimeModelExporter(petalsAdminApiRule.getSingleton()); final RuntimeModel exportedModel = modelExporter.exportRuntimeModel(ModelUtils.CONTAINER_HOST, ModelUtils.CONTAINER_JMX_PORT, ModelUtils.CONTAINER_USER, ModelUtils.CONTAINER_PWD, null); assertTrue(model.isSimilarTo(exportedModel)); } - private org.ow2.petals.admin.topology.Container createContainerSample() { + public static org.ow2.petals.admin.topology.Container createContainerSample() { final Map ports = new HashMap<>(); ports.put(PortType.JMX, ModelUtils.CONTAINER_JMX_PORT); return new org.ow2.petals.admin.topology.Container(ModelUtils.CONTAINER_NAME, ModelUtils.CONTAINER_HOST, ports, ModelUtils.CONTAINER_USER, ModelUtils.CONTAINER_PWD, ModelUtils.CONTAINER_STATE); } - private void initializeRuntimeModel(final RuntimeModel model) throws Exception { - + public RuntimeModel generateRuntimeModel() throws Exception { + final RuntimeModel model = new RuntimeModel(); final RuntimeContainer cont = new RuntimeContainer(ModelUtils.CONTAINER_NAME, ModelUtils.CONTAINER_JMX_PORT, ModelUtils.CONTAINER_USER, ModelUtils.CONTAINER_PWD, "localhost"); + model.addContainer(cont); cont.addComponent(new RuntimeComponent("petals-bc-soap", ZipUtils.createZipFromResourceDirectory("artifacts/petals-bc-soap-5.0.0").toURI().toURL())); cont.addServiceUnit(new RuntimeServiceUnit("su-SOAP-Hello_Service1-provide", @@ -105,6 +104,6 @@ private void initializeRuntimeModel(final RuntimeModel model) throws Exception { cont.addServiceUnit(new RuntimeServiceUnit("su-SOAP-Hello_PortType-consume", ZipUtils.createZipFromResourceDirectory("artifacts/sa-SOAP-Hello_PortType-consume").toURI().toURL())); - model.addContainer(cont); + return model; } } diff --git a/src/test/java/org/ow2/petals/deployer/utils/XmlModelBuilderTest.java b/src/test/java/org/ow2/petals/deployer/utils/XmlModelBuilderTest.java new file mode 100644 index 0000000..c608673 --- /dev/null +++ b/src/test/java/org/ow2/petals/deployer/utils/XmlModelBuilderTest.java @@ -0,0 +1,50 @@ +/** + * Copyright (c) 2019 Linagora + * + * This program/library is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 2.1 of the License, or (at your + * option) any later version. + * + * This program/library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program/library; If not, see http://www.gnu.org/licenses/ + * for the GNU Lesser General Public License version 2.1. + */ +package org.ow2.petals.deployer.utils; + +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.FileReader; +import java.net.URL; +import java.nio.file.Files; + +import org.custommonkey.xmlunit.XMLUnit; +import org.junit.Test; +import org.ow2.petals.deployer.model.xml._1.Model; +import org.xml.sax.InputSource; + +/** + * @author Alexandre Lagane - Linagora + * + */ +public class XmlModelBuilderTest { + + @Test + public void test() throws Exception { + URL initialModelUrl = Thread.currentThread().getContextClassLoader().getResource("model.xml"); + File initialModelFile = new File(initialModelUrl.getFile()); + Model model = XmlModelBuilder.readModelFromUrl(initialModelUrl); + File marshalledModelFile = Files.createTempFile("marshalled-model", ".xml").toFile(); + XmlModelBuilder.writeModelToFile(model, marshalledModelFile); + + assertTrue(XMLUnit.compareXML(new InputSource(new FileReader(initialModelFile)), + new InputSource(new FileReader(marshalledModelFile))).similar()); + } + +} diff --git a/src/test/java/org/ow2/petals/deployer/utils/ZipUtils.java b/src/test/java/org/ow2/petals/deployer/utils/ZipUtils.java index ee18efa..e09d81b 100644 --- a/src/test/java/org/ow2/petals/deployer/utils/ZipUtils.java +++ b/src/test/java/org/ow2/petals/deployer/utils/ZipUtils.java @@ -31,6 +31,7 @@ * @author Alexandre Lagane - Linagora */ public class ZipUtils { + private static final int DEFAULT_BUFFER_SIZE = 1024; /** diff --git a/src/test/resources/model.xml b/src/test/resources/model.xml new file mode 100644 index 0000000..1802395 --- /dev/null +++ b/src/test/resources/model.xml @@ -0,0 +1,54 @@ + + + + + + file:/artifacts/sa-SOAP-Hello_Service1-provide + + + file:/artifacts/sa-SOAP-Hello_Service2-provide + + + file:/artifacts/sa-SOAP-Hello_PortType-consume + + + + + file:/artifacts/petals-bc-soap-5.0.0 + + + + + + + + + + localhost + + + + + + + + + + + \ No newline at end of file