Commit 73a4bd8f authored by Alessio Carenini's avatar Alessio Carenini
Browse files

Merge branch 'Amber' of ssh://tuleap.ow2.org/chorevolution/enactment-engine into Amber

parents c8660e87 4cc893a9
/*
* Copyright 2016 The CHOReVOLUTION project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.chorevolution.chors;
import eu.chorevolution.datamodel.Choreography;
import eu.chorevolution.datamodel.ChoreographyService;
import eu.chorevolution.datamodel.DeployedService;
import eu.chorevolution.datamodel.ServiceDependency;
import eu.chorevolution.datamodel.ServiceType;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
public final class ChorSpecUtils {
public static String findSecurityFilterURL(final Choreography chorSpec, final ChoreographyService service) {
Set<ChoreographyService> candidates = new HashSet<>();
chorSpec.getServiceGroups().forEach((serviceGroup) -> {
candidates.addAll(serviceGroup.getServices().stream().
filter((ChoreographyService cs) -> cs instanceof DeployedService).
filter((ChoreographyService dep) -> ((DeployedService) dep).getDependencies() != null).
filter((ChoreographyService dep)
-> ((DeployedService) dep).getDependencies().stream().
anyMatch(
(ServiceDependency dependency)
-> dependency.getServiceSpecName().equals(service.getName()))).
collect(Collectors.toSet()));
});
String securityFilterURL = null;
Set<ChoreographyService> bcCandidates = new HashSet<>();
for (ChoreographyService candidate : candidates) {
switch (((DeployedService) candidate).getServiceType()) {
case SECURITY_FILTER:
securityFilterURL = ((DeployedService) candidate).getUrl();
break;
case BINDING_COMPONENT:
chorSpec.getServiceGroups().forEach((serviceGroup) -> {
bcCandidates.addAll(serviceGroup.getServices().stream().
filter((ChoreographyService cs) -> cs instanceof DeployedService).
filter((ChoreographyService dep)
-> ((DeployedService) dep).getServiceType() == ServiceType.SECURITY_FILTER).
filter((ChoreographyService dep)
-> ((DeployedService) dep).getDependencies() != null).
filter((ChoreographyService dep)
-> ((DeployedService) dep).getDependencies().stream().
anyMatch(
(ServiceDependency dependency)
-> dependency.getServiceSpecName().equals(candidate.getName()))).
collect(Collectors.toSet()));
});
break;
default:
}
}
if (securityFilterURL == null && !bcCandidates.isEmpty()) {
securityFilterURL = ((DeployedService) bcCandidates.iterator().next()).getUrl();
}
return securityFilterURL;
}
private ChorSpecUtils() {
// private constructor for static utility class
}
}
/*
* Copyright 2016 The CHOReVOLUTION project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.chorevolution.chors;
import eu.chorevolution.datamodel.Choreography;
public interface EnactmentEngine {
/**
* Creates a new choreography that still have to be deployed.
*
* @param chor specification of choreography services
* @return the id of the just created choreography
*/
String createChoreography(Choreography chor);
/**
* Retrieve choreography information.
*
* @param chorId
* the choreography id
* @return the choreography representation
* @throws ChoreographyNotFoundException
* if <code>chorId</code> does not exist
*/
Choreography getChoreography(String chorId) throws ChoreographyNotFoundException;
/**
* Deploys a choreography
*
* @param chorId
* the choreography id
* @return choreography representation, including information about deployed
* services
* @throws ChoreographyNotFoundException
* if <code>chorId</code> does not exist
* @throws DeploymentException
* if something goes wrong
*/
Choreography deployChoreography(String chorId) throws DeploymentException, ChoreographyNotFoundException;
/**
* Updates a choreography
*
* @param chorId
* the choreography id
* @param spec the choreography specification
* @throws ChoreographyNotFoundException
* if <code>chorId</code> does not exist
* @throws DeploymentException
* if something goes wrong
*/
void updateChoreography(String chorId, Choreography spec) throws DeploymentException, ChoreographyNotFoundException;
}
/*
* Copyright 2016 The CHOReVOLUTION project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.chorevolution.datamodel;
import java.util.List;
public abstract class AbstractTest {
protected ChoreographyService findService(final List<ChoreographyService> services, final String name) {
return services.stream().filter(
(ChoreographyService s) -> name.equals(s.getName())).
findFirst().get();
}
}
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package chorspec;
package eu.chorevolution.datamodel;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
......@@ -22,26 +22,11 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import eu.chorevolution.datamodel.Choreography;
import eu.chorevolution.datamodel.ChoreographyService;
import eu.chorevolution.datamodel.DeployableService;
import eu.chorevolution.datamodel.DeployedService;
import eu.chorevolution.datamodel.ExistingService;
import eu.chorevolution.datamodel.PackageType;
import eu.chorevolution.datamodel.ServiceDependency;
import eu.chorevolution.datamodel.ServiceGroup;
import eu.chorevolution.datamodel.ServiceType;
import eu.chorevolution.datamodel.deployment.CloudNode;
import eu.chorevolution.datamodel.deployment.DeploymentInfo;
import java.util.List;
public class DeserializationTest {
private ChoreographyService findService(final List<ChoreographyService> services, final String name) {
return services.stream().filter(
(ChoreographyService s) -> name.equals(s.getName())).
findFirst().get();
}
public class DeserializationTest extends AbstractTest {
@Test
public void wp5Before() throws Exception {
......
/*
* Copyright 2016 The CHOReVOLUTION project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package eu.chorevolution.datamodel;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import eu.chorevolution.chors.ChorSpecUtils;
import org.junit.Test;
public class LookupTest extends AbstractTest {
@Test
public void securityFilterLookup() throws Exception {
Choreography chorSpec = Choreography.fromXML(getClass().getResourceAsStream("/after_wp5.choreospec"));
assertNotNull(chorSpec);
ChoreographyService poi =
findService(chorSpec.getServiceGroups().get(0).getServices(), "Poi");
assertNotNull(poi);
assertEquals(
"http://192.168.150.142/sfpoi",
ChorSpecUtils.findSecurityFilterURL(chorSpec, poi));
ChoreographyService trafficInformation =
findService(chorSpec.getServiceGroups().get(0).getServices(), "TrafficInformation");
assertNotNull(trafficInformation);
assertEquals(
"http://192.168.150.142/sftrafficinformation",
ChorSpecUtils.findSecurityFilterURL(chorSpec, trafficInformation));
}
}
......@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package chorspec;
package eu.chorevolution.datamodel;
import static org.junit.Assert.assertNotNull;
......
......@@ -106,6 +106,35 @@ limitations under the License.
</node>
</deploymentInfo>
</service>
<service xsi:type="deployedService" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>sftrafficinformation</name>
<role>SF Traffic Information</role>
<dependency>
<serviceSpecName>TrafficInformation</serviceSpecName>
<serviceSpecRole>Traffic Information</serviceSpecRole>
</dependency>
<instances>1</instances>
<packageType>WAR</packageType>
<packageUrl>http://localhost:8080/TrafficInformation/SF_TrafficInformation.war</packageUrl>
<serviceType>SECURITY_FILTER</serviceType>
<url>http://192.168.150.142/sftrafficinformation</url>
<deploymentInfo>
<endpoint>http://192.168.150.130:8080/sftrafficinformation</endpoint>
<node>
<cpus>2</cpus>
<hostname>chornode1</hostname>
<image>af036b89-0ef4-48e9-99ac-51b0cf9c314e</image>
<ip>192.168.150.130</ip>
<os>Ubuntu</os>
<privateKeyFile>/etc/enactment-engine/eekey.pem</privateKeyFile>
<ram>1024</ram>
<state>1</state>
<storage>10000</storage>
<user>ubuntu</user>
<zone>RegionOne</zone>
</node>
</deploymentInfo>
</service>
<service xsi:type="deployedService" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>cdtripplanner</name>
<role>Trip Planner</role>
......@@ -114,7 +143,7 @@ limitations under the License.
<serviceSpecRole>Consumer Trip Planner</serviceSpecRole>
</dependency>
<dependency>
<serviceSpecName>TrafficInformation</serviceSpecName>
<serviceSpecName>sftrafficinformation</serviceSpecName>
<serviceSpecRole>Traffic Information</serviceSpecRole>
</dependency>
<dependency>
......@@ -159,6 +188,35 @@ limitations under the License.
</node>
</deploymentInfo>
</service>
<service xsi:type="deployedService" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>sfpoi</name>
<role>SF Poi</role>
<dependency>
<serviceSpecName>Poi</serviceSpecName>
<serviceSpecRole>Poi</serviceSpecRole>
</dependency>
<instances>1</instances>
<packageType>WAR</packageType>
<packageUrl>http://localhost:8080/TrafficInformation/SF_Poi.war</packageUrl>
<serviceType>SECURITY_FILTER</serviceType>
<url>http://192.168.150.142/sfpoi</url>
<deploymentInfo>
<endpoint>http://192.168.150.130:8080/sfpoi</endpoint>
<node>
<cpus>2</cpus>
<hostname>chornode1</hostname>
<image>af036b89-0ef4-48e9-99ac-51b0cf9c314e</image>
<ip>192.168.150.130</ip>
<os>Ubuntu</os>
<privateKeyFile>/etc/enactment-engine/eekey.pem</privateKeyFile>
<ram>1024</ram>
<state>1</state>
<storage>10000</storage>
<user>ubuntu</user>
<zone>RegionOne</zone>
</node>
</deploymentInfo>
</service>
<service xsi:type="deployedService" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>cdtouristagent</name>
<role>Tourist Agent</role>
......@@ -167,7 +225,7 @@ limitations under the License.
<serviceSpecRole>Consumer Tourist Agent</serviceSpecRole>
</dependency>
<dependency>
<serviceSpecName>Poi</serviceSpecName>
<serviceSpecName>sfpoi</serviceSpecName>
<serviceSpecRole>Poi</serviceSpecRole>
</dependency>
<dependency>
......
......@@ -21,6 +21,18 @@ limitations under the License.
<role>Traffic Information</role>
<url>http://localhost:8080/TrafficInformation/TrafficInformation</url>
</service>
<service xsi:type="deployableService" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>sftrafficinformation</name>
<role>SF Traffic Information</role>
<dependency>
<serviceSpecName>TrafficInformation</serviceSpecName>
<serviceSpecRole>Traffic Information</serviceSpecRole>
</dependency>
<instances>1</instances>
<packageType>WAR</packageType>
<packageUrl>http://localhost:8080/TrafficInformation/SF_TrafficInformation.war</packageUrl>
<serviceType>SECURITY_FILTER</serviceType>
</service>
<service xsi:type="deployableService" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>consumercdtripplanner</name>
<role>Consumer Trip Planner</role>
......@@ -44,6 +56,18 @@ limitations under the License.
<role>Poi</role>
<url>http://localhost:8080/Poi/Poi</url>
</service>
<service xsi:type="deployableService" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>sfpoi</name>
<role>SF Poi</role>
<dependency>
<serviceSpecName>Poi</serviceSpecName>
<serviceSpecRole>Poi</serviceSpecRole>
</dependency>
<instances>1</instances>
<packageType>WAR</packageType>
<packageUrl>http://localhost:8080/TrafficInformation/SF_Poi.war</packageUrl>
<serviceType>SECURITY_FILTER</serviceType>
</service>
<service xsi:type="deployableService" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<name>consumercdtouristagent</name>
<role>Consumer Tourist Agent</role>
......@@ -80,7 +104,7 @@ limitations under the License.
<serviceSpecRole>Consumer Trip Planner</serviceSpecRole>
</dependency>
<dependency>
<serviceSpecName>TrafficInformation</serviceSpecName>
<serviceSpecName>sftrafficinformation</serviceSpecName>
<serviceSpecRole>Traffic Information</serviceSpecRole>
</dependency>
<dependency>
......@@ -116,7 +140,7 @@ limitations under the License.
<serviceSpecRole>Consumer Tourist Agent</serviceSpecRole>
</dependency>
<dependency>
<serviceSpecName>Poi</serviceSpecName>
<serviceSpecName>sfpoi</serviceSpecName>
<serviceSpecRole>Poi</serviceSpecRole>
</dependency>
<dependency>
......
/*
* Copyright 2016 The CHOReVOLUTION project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.brooklyn.entity.webapp.chorevolution;
import org.apache.brooklyn.api.entity.ImplementedBy;
......
/*
* Copyright 2016 The CHOReVOLUTION project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.brooklyn.entity.webapp.chorevolution;
import java.io.BufferedReader;
......
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* Copyright 2016 The CHOReVOLUTION project
*
* http://www.apache.org/licenses/LICENSE-2.0
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.brooklyn.rest.api;
import java.io.InputStream;
......@@ -24,8 +20,10 @@ import java.io.InputStream;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
......@@ -103,8 +101,8 @@ public interface ChoreographyApi {
@ApiParam(name = "chorSpec", value = "Choreography specifications", required = true)
InputStream chorSpec);
@POST
@Path("/update/{choreography_id}")
@PUT
@Path("/update/{choreographyId}")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
value = "Deploy a choreography onto a cloud environment.",
......@@ -114,12 +112,13 @@ public interface ChoreographyApi {
@ApiResponse(code = 404, message = "Undefined entity or location"),
@ApiResponse(code = 412, message = "Choreography already registered")
})
public Response update(
@ApiParam(name = "choreography_id", value = "Choreography ID", required = true)
@PathParam("choreography_name") String choreography_name,
@ApiParam(name = "choreography", value = "Choreography specifications", required = true)
String choreography);
Response update(
@ApiParam(name = "choreographyId", value = "Choreography ID", required = true)
@PathParam("choreographyId") String choreographyId,
@ApiParam(name = "choreographyName", value = "Choreography name", required = true)
@QueryParam("choreographyName") String choreographyName,
@ApiParam(name = "chorSpec", value = "Choreography specifications", required = true)
InputStream chorSpec);
@POST
@Path("/resize/{choreographyId}")
......
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* Copyright 2016 The CHOReVOLUTION project
*
* http://www.apache.org/licenses/LICENSE-2.0
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.brooklyn.rest.resources;
import static javax.ws.rs.core.Response.status;
......@@ -30,7 +24,6 @@ import java.io.StringReader;
import java.util.Collection;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
......@@ -207,10 +200,8 @@ public class ChoreographyResource extends AbstractBrooklynRestResource implement
}
@Override
public Response update(String choreography_name, String choreography) {
// TODO Auto-generated method stub
return null;
}