Return-Path: X-Original-To: apmail-provisionr-commits-archive@minotaur.apache.org Delivered-To: apmail-provisionr-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C9725F18B for ; Mon, 1 Apr 2013 08:53:02 +0000 (UTC) Received: (qmail 5913 invoked by uid 500); 1 Apr 2013 08:53:02 -0000 Delivered-To: apmail-provisionr-commits-archive@provisionr.apache.org Received: (qmail 5879 invoked by uid 500); 1 Apr 2013 08:53:02 -0000 Mailing-List: contact commits-help@provisionr.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@provisionr.apache.org Delivered-To: mailing list commits@provisionr.apache.org Received: (qmail 5858 invoked by uid 99); 1 Apr 2013 08:53:02 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Apr 2013 08:53:02 +0000 X-ASF-Spam-Status: No, hits=-2002.3 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 01 Apr 2013 08:52:46 +0000 Received: (qmail 4194 invoked by uid 99); 1 Apr 2013 08:52:25 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 01 Apr 2013 08:52:25 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id A6861834F8D; Mon, 1 Apr 2013 08:52:24 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: asavu@apache.org To: commits@provisionr.incubator.apache.org Date: Mon, 01 Apr 2013 08:52:35 -0000 Message-Id: <26cc53b92e054fc89bdabc181bad493e@git.apache.org> In-Reply-To: <87783f7120954fc28ba08d7ec2dced3b@git.apache.org> References: <87783f7120954fc28ba08d7ec2dced3b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [12/21] PROVISIONR-20. Change groupId from com.axemblr.provisionr to org.apache.provisionr X-Virus-Checked: Checked by ClamAV on apache.org http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/integration/rundeck/src/main/java/com/axemblr/provisionr/rundeck/Project.java ---------------------------------------------------------------------- diff --git a/integration/rundeck/src/main/java/com/axemblr/provisionr/rundeck/Project.java b/integration/rundeck/src/main/java/com/axemblr/provisionr/rundeck/Project.java deleted file mode 100644 index a568ce2..0000000 --- a/integration/rundeck/src/main/java/com/axemblr/provisionr/rundeck/Project.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2013 S.C. Axemblr Software Solutions S.R.L - * - * 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 com.axemblr.provisionr.rundeck; - -import static com.google.common.base.Preconditions.checkNotNull; -import com.google.common.collect.Lists; -import java.util.Collections; -import java.util.List; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; - -/** - * Rundeck Resource Model Project definition - * - * @see - */ -@XmlRootElement(name = "project") -public class Project { - - private List nodes = Lists.newArrayList(); - - public Project() { - } - - public Project(List nodes) { - this.nodes = checkNotNull(nodes, "nodes is null"); - } - - @XmlElement(name = "node") - public List getNodes() { - return nodes; - } - - public void setNodes(List nodes) { - this.nodes = checkNotNull(nodes, "nodes is null"); - } - - public void addNodes(Node... nodes) { - Collections.addAll(this.nodes, nodes); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Project project = (Project) o; - - return !(nodes != null ? !nodes.equals(project.nodes) : project.nodes != null); - - } - - @Override - public int hashCode() { - return nodes != null ? nodes.hashCode() : 0; - } - - @Override - public String toString() { - return "Project{" + - "nodes=" + nodes + - '}'; - } -} http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/integration/rundeck/src/main/java/com/axemblr/provisionr/rundeck/RundeckServlet.java ---------------------------------------------------------------------- diff --git a/integration/rundeck/src/main/java/com/axemblr/provisionr/rundeck/RundeckServlet.java b/integration/rundeck/src/main/java/com/axemblr/provisionr/rundeck/RundeckServlet.java deleted file mode 100644 index 1767298..0000000 --- a/integration/rundeck/src/main/java/com/axemblr/provisionr/rundeck/RundeckServlet.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2013 S.C. Axemblr Software Solutions S.R.L - * - * 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 com.axemblr.provisionr.rundeck; - -import com.axemblr.provisionr.api.pool.Machine; -import com.axemblr.provisionr.api.pool.Pool; -import com.axemblr.provisionr.core.CoreProcessVariables; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Objects; -import static com.google.common.base.Preconditions.checkNotNull; -import com.google.common.base.Throwables; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Lists; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.List; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import org.activiti.engine.ProcessEngine; -import org.activiti.engine.runtime.ProcessInstance; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class RundeckServlet extends HttpServlet { - - private static final Logger LOG = LoggerFactory.getLogger(RundeckServlet.class); - - private final ProcessEngine processEngine; - private final Marshaller marshaller; - - public RundeckServlet(ProcessEngine processEngine) throws JAXBException { - this.processEngine = checkNotNull(processEngine, "processEngine is null"); - - this.marshaller = JAXBContext.newInstance(Project.class).createMarshaller(); - this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - response.setContentType("application/xml;charset=UTF-8"); - writeRundeckResourceModelXmlTo(response.getWriter()); - } - - @VisibleForTesting - void writeRundeckResourceModelXmlTo(PrintWriter writer) { - final List processes = processEngine.getRuntimeService() - .createProcessInstanceQuery().list(); - - Project project = new Project(); - for (ProcessInstance instance : processes) { - final Pool pool = (Pool) processEngine.getRuntimeService() - .getVariable(instance.getId(), CoreProcessVariables.POOL); - if (pool == null) { - continue; /* skip - this process is not a provisionr process */ - } - - final String businessKey = (String) processEngine.getRuntimeService() - .getVariable(instance.getId(), CoreProcessVariables.POOL_BUSINESS_KEY); - if (!Objects.equal(instance.getBusinessKey(), businessKey)) { - continue; /* ignore - this is a process started by the main pool management process */ - } - - @SuppressWarnings("unchecked") - List machines = (List) processEngine.getRuntimeService() - .getVariable(instance.getId(), CoreProcessVariables.MACHINES); - if (machines == null) { - continue; /* the list of machines is not yet available */ - } - - project.setNodes(transformMachinesToRundeckNodes(businessKey, pool, machines)); - } - - try { - marshaller.marshal(project, writer); - - } catch (JAXBException e) { - throw Throwables.propagate(e); - } - } - - @VisibleForTesting - List transformMachinesToRundeckNodes(String businessKey, Pool pool, List machines) { - List nodes = Lists.newArrayList(); - - for (Machine machine : machines) { - Node node = new Node(machine.getExternalId(), machine.getPublicDnsName(), - pool.getAdminAccess().getUsername()); - - node.setTags(pool.getSoftware().getPackages()); - - node.setAttributes(ImmutableMap.builder() - .put("provider", pool.getProvider().getId()) - .put("key", businessKey) - .put("publicIp", machine.getPublicIp()) - .put("privateHostname", machine.getPrivateDnsName()) - .put("privateIp", machine.getPrivateIp()) - .put("hardwareType", pool.getHardware().getType()) - .build()); - - if (pool.getProvider().getOptions().containsKey("region")) { - node.addAttribute("region", pool.getProvider().getOption("region")); - } - - nodes.add(node); - } - - return nodes; - } -} http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/integration/rundeck/src/main/java/org/apache/provisionr/rundeck/Attribute.java ---------------------------------------------------------------------- diff --git a/integration/rundeck/src/main/java/org/apache/provisionr/rundeck/Attribute.java b/integration/rundeck/src/main/java/org/apache/provisionr/rundeck/Attribute.java new file mode 100644 index 0000000..4d00077 --- /dev/null +++ b/integration/rundeck/src/main/java/org/apache/provisionr/rundeck/Attribute.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2013 S.C. Axemblr Software Solutions S.R.L + * + * 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.provisionr.rundeck; + +import static com.google.common.base.Preconditions.checkNotNull; +import javax.xml.bind.annotation.XmlAttribute; + +/** + * An attribute allows you to add user-defined metadata + * + * @see + */ +public class Attribute { + + private String name; + + private String value; + + public Attribute() { + } + + public Attribute(String name, String value) { + this.name = checkNotNull(name, "name is null"); + this.value = checkNotNull(value, "value is null"); + } + + @XmlAttribute(name = "name") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = checkNotNull(name, "name is null"); + } + + @XmlAttribute(name = "value") + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = checkNotNull(value, "value is null"); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Attribute attribute = (Attribute) o; + + if (name != null ? !name.equals(attribute.name) : attribute.name != null) return false; + if (value != null ? !value.equals(attribute.value) : attribute.value != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + (value != null ? value.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "Attribute{" + + "name='" + name + '\'' + + ", value='" + value + '\'' + + '}'; + } +} http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/integration/rundeck/src/main/java/org/apache/provisionr/rundeck/Node.java ---------------------------------------------------------------------- diff --git a/integration/rundeck/src/main/java/org/apache/provisionr/rundeck/Node.java b/integration/rundeck/src/main/java/org/apache/provisionr/rundeck/Node.java new file mode 100644 index 0000000..0fc6aa3 --- /dev/null +++ b/integration/rundeck/src/main/java/org/apache/provisionr/rundeck/Node.java @@ -0,0 +1,169 @@ +/* + * Copyright (c) 2013 S.C. Axemblr Software Solutions S.R.L + * + * 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.provisionr.rundeck; + +import com.google.common.base.Joiner; +import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.collect.Lists; +import java.util.List; +import java.util.Map; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; + +/** + * A Rundeck Resource Model is nothing more than just a list of nodes + * with a predefined set of properties and an optional list of user defined attributes + * + * @see + */ +public class Node { + + /** + * The node name. This is a logical identifier from the node. (required) + */ + private String name; + + /** + * The hostname or IP address of the remote host. (required) + */ + private String hostname; + + /** + * Comma separated list of filtering tags. (optional) + */ + private String tags; + + /** + * The username used for the remote connection. (required) + */ + private String username; + + /** + * User defined attributes + */ + private List attributes; + + public Node() { + } + + public Node(String name, String hostname, String username) { + this.name = checkNotNull(name, "name is null"); + this.hostname = checkNotNull(hostname, "hostname is null"); + this.username = checkNotNull(username, "username is null"); + } + + @XmlAttribute + public String getName() { + return name; + } + + public void setName(String name) { + this.name = checkNotNull(name, "name is null"); + } + + @XmlAttribute + public String getHostname() { + return hostname; + } + + public void setHostname(String hostname) { + this.hostname = checkNotNull(hostname, "hostname is null"); + } + + @XmlAttribute + public String getTags() { + return tags; + } + + public void setTags(String tags) { + this.tags = checkNotNull(tags, "tags is null"); + } + + public void setTags(Iterable tags) { + setTags(Joiner.on(",").join(tags)); + } + + public void setTags(String[] tags) { + setTags(Joiner.on(",").join(tags)); + } + + @XmlAttribute + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = checkNotNull(username, "username is null"); + } + + @XmlElement(name = "attribute") + public List getAttributes() { + return attributes; + } + + public void setAttributes(List attributes) { + this.attributes = checkNotNull(attributes, "attributes is null"); + } + + public void setAttributes(Map values) { + this.attributes = Lists.newArrayList(); + for (Map.Entry entry : values.entrySet()) { + this.attributes.add(new Attribute(entry.getKey(), entry.getValue())); + } + } + + public void addAttribute(String name, String value) { + this.attributes.add(new Attribute(name, value)); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Node node = (Node) o; + + if (attributes != null ? !attributes.equals(node.attributes) : node.attributes != null) return false; + if (hostname != null ? !hostname.equals(node.hostname) : node.hostname != null) return false; + if (name != null ? !name.equals(node.name) : node.name != null) return false; + if (tags != null ? !tags.equals(node.tags) : node.tags != null) return false; + if (username != null ? !username.equals(node.username) : node.username != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = name != null ? name.hashCode() : 0; + result = 31 * result + (hostname != null ? hostname.hashCode() : 0); + result = 31 * result + (tags != null ? tags.hashCode() : 0); + result = 31 * result + (username != null ? username.hashCode() : 0); + result = 31 * result + (attributes != null ? attributes.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "Node{" + + "name='" + name + '\'' + + ", hostname='" + hostname + '\'' + + ", tags='" + tags + '\'' + + ", username='" + username + '\'' + + ", attributes=" + attributes + + '}'; + } +} http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/integration/rundeck/src/main/java/org/apache/provisionr/rundeck/Project.java ---------------------------------------------------------------------- diff --git a/integration/rundeck/src/main/java/org/apache/provisionr/rundeck/Project.java b/integration/rundeck/src/main/java/org/apache/provisionr/rundeck/Project.java new file mode 100644 index 0000000..2fd9a61 --- /dev/null +++ b/integration/rundeck/src/main/java/org/apache/provisionr/rundeck/Project.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2013 S.C. Axemblr Software Solutions S.R.L + * + * 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.provisionr.rundeck; + +import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.collect.Lists; +import java.util.Collections; +import java.util.List; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * Rundeck Resource Model Project definition + * + * @see + */ +@XmlRootElement(name = "project") +public class Project { + + private List nodes = Lists.newArrayList(); + + public Project() { + } + + public Project(List nodes) { + this.nodes = checkNotNull(nodes, "nodes is null"); + } + + @XmlElement(name = "node") + public List getNodes() { + return nodes; + } + + public void setNodes(List nodes) { + this.nodes = checkNotNull(nodes, "nodes is null"); + } + + public void addNodes(Node... nodes) { + Collections.addAll(this.nodes, nodes); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Project project = (Project) o; + + return !(nodes != null ? !nodes.equals(project.nodes) : project.nodes != null); + + } + + @Override + public int hashCode() { + return nodes != null ? nodes.hashCode() : 0; + } + + @Override + public String toString() { + return "Project{" + + "nodes=" + nodes + + '}'; + } +} http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/integration/rundeck/src/main/java/org/apache/provisionr/rundeck/RundeckServlet.java ---------------------------------------------------------------------- diff --git a/integration/rundeck/src/main/java/org/apache/provisionr/rundeck/RundeckServlet.java b/integration/rundeck/src/main/java/org/apache/provisionr/rundeck/RundeckServlet.java new file mode 100644 index 0000000..c0f7753 --- /dev/null +++ b/integration/rundeck/src/main/java/org/apache/provisionr/rundeck/RundeckServlet.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2013 S.C. Axemblr Software Solutions S.R.L + * + * 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.provisionr.rundeck; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Objects; +import static com.google.common.base.Preconditions.checkNotNull; +import com.google.common.base.Throwables; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Lists; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.List; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import org.activiti.engine.ProcessEngine; +import org.activiti.engine.runtime.ProcessInstance; +import org.apache.provisionr.api.pool.Machine; +import org.apache.provisionr.api.pool.Pool; +import org.apache.provisionr.core.CoreProcessVariables; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RundeckServlet extends HttpServlet { + + private static final Logger LOG = LoggerFactory.getLogger(RundeckServlet.class); + + private final ProcessEngine processEngine; + private final Marshaller marshaller; + + public RundeckServlet(ProcessEngine processEngine) throws JAXBException { + this.processEngine = checkNotNull(processEngine, "processEngine is null"); + + this.marshaller = JAXBContext.newInstance(Project.class).createMarshaller(); + this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + } + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + response.setContentType("application/xml;charset=UTF-8"); + writeRundeckResourceModelXmlTo(response.getWriter()); + } + + @VisibleForTesting + void writeRundeckResourceModelXmlTo(PrintWriter writer) { + final List processes = processEngine.getRuntimeService() + .createProcessInstanceQuery().list(); + + Project project = new Project(); + for (ProcessInstance instance : processes) { + final Pool pool = (Pool) processEngine.getRuntimeService() + .getVariable(instance.getId(), CoreProcessVariables.POOL); + if (pool == null) { + continue; /* skip - this process is not a provisionr process */ + } + + final String businessKey = (String) processEngine.getRuntimeService() + .getVariable(instance.getId(), CoreProcessVariables.POOL_BUSINESS_KEY); + if (!Objects.equal(instance.getBusinessKey(), businessKey)) { + continue; /* ignore - this is a process started by the main pool management process */ + } + + @SuppressWarnings("unchecked") + List machines = (List) processEngine.getRuntimeService() + .getVariable(instance.getId(), CoreProcessVariables.MACHINES); + if (machines == null) { + continue; /* the list of machines is not yet available */ + } + + project.setNodes(transformMachinesToRundeckNodes(businessKey, pool, machines)); + } + + try { + marshaller.marshal(project, writer); + + } catch (JAXBException e) { + throw Throwables.propagate(e); + } + } + + @VisibleForTesting + List transformMachinesToRundeckNodes(String businessKey, Pool pool, List machines) { + List nodes = Lists.newArrayList(); + + for (Machine machine : machines) { + Node node = new Node(machine.getExternalId(), machine.getPublicDnsName(), + pool.getAdminAccess().getUsername()); + + node.setTags(pool.getSoftware().getPackages()); + + node.setAttributes(ImmutableMap.builder() + .put("provider", pool.getProvider().getId()) + .put("key", businessKey) + .put("publicIp", machine.getPublicIp()) + .put("privateHostname", machine.getPrivateDnsName()) + .put("privateIp", machine.getPrivateIp()) + .put("hardwareType", pool.getHardware().getType()) + .build()); + + if (pool.getProvider().getOptions().containsKey("region")) { + node.addAttribute("region", pool.getProvider().getOption("region")); + } + + nodes.add(node); + } + + return nodes; + } +} http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/integration/rundeck/src/main/resources/OSGI-INF/blueprint/context.xml ---------------------------------------------------------------------- diff --git a/integration/rundeck/src/main/resources/OSGI-INF/blueprint/context.xml b/integration/rundeck/src/main/resources/OSGI-INF/blueprint/context.xml index 76ef884..1d16a6d 100644 --- a/integration/rundeck/src/main/resources/OSGI-INF/blueprint/context.xml +++ b/integration/rundeck/src/main/resources/OSGI-INF/blueprint/context.xml @@ -22,7 +22,7 @@ - + http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/integration/rundeck/src/main/resources/features.xml ---------------------------------------------------------------------- diff --git a/integration/rundeck/src/main/resources/features.xml b/integration/rundeck/src/main/resources/features.xml index cb7cb37..3a66fab 100644 --- a/integration/rundeck/src/main/resources/features.xml +++ b/integration/rundeck/src/main/resources/features.xml @@ -16,17 +16,17 @@ ~ limitations under the License. --> - - mvn:com.axemblr.provisionr/provisionr-core/${project.version}/xml/features + mvn:org.apache.provisionr/provisionr-core/${project.version}/xml/features - + http - axemblr-provisionr-core + provisionr-core - mvn:com.axemblr.provisionr/provisionr-rundeck/${project.version} + mvn:org.apache.provisionr/provisionr-rundeck/${project.version} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/integration/rundeck/src/test/java/com/axemblr/provisionr/rundeck/BaseJaxbTest.java ---------------------------------------------------------------------- diff --git a/integration/rundeck/src/test/java/com/axemblr/provisionr/rundeck/BaseJaxbTest.java b/integration/rundeck/src/test/java/com/axemblr/provisionr/rundeck/BaseJaxbTest.java deleted file mode 100644 index 6d98dff..0000000 --- a/integration/rundeck/src/test/java/com/axemblr/provisionr/rundeck/BaseJaxbTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2013 S.C. Axemblr Software Solutions S.R.L - * - * 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 com.axemblr.provisionr.rundeck; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import org.custommonkey.xmlunit.XMLUnit; -import org.junit.Before; - -public abstract class BaseJaxbTest { - - protected JAXBContext jaxb; - - static { - XMLUnit.setIgnoreWhitespace(true); - XMLUnit.setIgnoreComments(true); - XMLUnit.setIgnoreAttributeOrder(true); - } - - @Before - public void setUp() throws JAXBException { - jaxb = JAXBContext.newInstance(getContextClasses()); - } - - public abstract Class[] getContextClasses(); - - /** - * Marshal an object as XML using a standard JAXB Context - */ - protected String asXml(Object obj) throws Exception { - ByteArrayOutputStream outBytes = new ByteArrayOutputStream(); - PrintStream out = new PrintStream(outBytes); - - Marshaller marshaller = jaxb.createMarshaller(); - marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); - - marshaller.marshal(obj, out); - return outBytes.toString(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/integration/rundeck/src/test/java/com/axemblr/provisionr/rundeck/ProjectTest.java ---------------------------------------------------------------------- diff --git a/integration/rundeck/src/test/java/com/axemblr/provisionr/rundeck/ProjectTest.java b/integration/rundeck/src/test/java/com/axemblr/provisionr/rundeck/ProjectTest.java deleted file mode 100644 index 430874c..0000000 --- a/integration/rundeck/src/test/java/com/axemblr/provisionr/rundeck/ProjectTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2013 S.C. Axemblr Software Solutions S.R.L - * - * 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 com.axemblr.provisionr.rundeck; - -import com.google.common.base.Charsets; -import com.google.common.collect.ImmutableMap; -import com.google.common.io.Resources; -import java.io.IOException; -import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual; -import org.junit.Test; - -/** - * A test to make sure the JAXB serialization works as expected - */ -public class ProjectTest extends BaseJaxbTest { - - @Test - public void testEmptyProject() throws Exception { - String actual = asXml(new Project()); - assertXMLEqual(actual, "", actual); - } - - @Test - public void testSimpleProject() throws Exception { - Project project = new Project(); - - Node node = new Node("db-1", "db-1.example.com", "psql"); - node.setTags(new String[]{"a", "b"}); - node.setAttributes(ImmutableMap.of("key1", "val1", "key2", "val2")); - - project.addNodes(node); - project.addNodes(new Node("web-1", "web-1.example.com", "django")); - - String actual = asXml(project); - assertXMLEqual(actual, readResource("fixtures/project.xml"), actual); - } - - private String readResource(String resource) throws IOException { - return Resources.toString(Resources.getResource(resource), Charsets.UTF_8); - } - - @Override - public Class[] getContextClasses() { - return new Class[]{Project.class}; - } -} http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/integration/rundeck/src/test/java/com/axemblr/provisionr/rundeck/RundeckServletTest.java ---------------------------------------------------------------------- diff --git a/integration/rundeck/src/test/java/com/axemblr/provisionr/rundeck/RundeckServletTest.java b/integration/rundeck/src/test/java/com/axemblr/provisionr/rundeck/RundeckServletTest.java deleted file mode 100644 index 15b9f64..0000000 --- a/integration/rundeck/src/test/java/com/axemblr/provisionr/rundeck/RundeckServletTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2013 S.C. Axemblr Software Solutions S.R.L - * - * 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 com.axemblr.provisionr.rundeck; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.PrintWriter; -import javax.xml.bind.JAXBException; -import org.activiti.engine.ProcessEngine; -import org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration; -import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.xml.sax.SAXException; - -public class RundeckServletTest { - - private ByteArrayOutputStream output; - private PrintWriter writer; - - @Before - public void setUp() { - output = new ByteArrayOutputStream(); - writer = new PrintWriter(output); - } - - @After - public void tearDown() throws IOException { - writer.close(); - output.close(); - } - - @Test - public void testEmptyListOfMachines() throws JAXBException, IOException, SAXException { - ProcessEngine processEngine = new StandaloneInMemProcessEngineConfiguration().buildProcessEngine(); - try { - RundeckServlet servlet = new RundeckServlet(processEngine); - servlet.writeRundeckResourceModelXmlTo(writer); - - writer.flush(); - assertXMLEqual(output.toString(), ""); - - } finally { - processEngine.close(); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/integration/rundeck/src/test/java/org/apache/provisionr/rundeck/BaseJaxbTest.java ---------------------------------------------------------------------- diff --git a/integration/rundeck/src/test/java/org/apache/provisionr/rundeck/BaseJaxbTest.java b/integration/rundeck/src/test/java/org/apache/provisionr/rundeck/BaseJaxbTest.java new file mode 100644 index 0000000..67acbe9 --- /dev/null +++ b/integration/rundeck/src/test/java/org/apache/provisionr/rundeck/BaseJaxbTest.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2013 S.C. Axemblr Software Solutions S.R.L + * + * 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.provisionr.rundeck; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import org.custommonkey.xmlunit.XMLUnit; +import org.junit.Before; + +public abstract class BaseJaxbTest { + + protected JAXBContext jaxb; + + static { + XMLUnit.setIgnoreWhitespace(true); + XMLUnit.setIgnoreComments(true); + XMLUnit.setIgnoreAttributeOrder(true); + } + + @Before + public void setUp() throws JAXBException { + jaxb = JAXBContext.newInstance(getContextClasses()); + } + + public abstract Class[] getContextClasses(); + + /** + * Marshal an object as XML using a standard JAXB Context + */ + protected String asXml(Object obj) throws Exception { + ByteArrayOutputStream outBytes = new ByteArrayOutputStream(); + PrintStream out = new PrintStream(outBytes); + + Marshaller marshaller = jaxb.createMarshaller(); + marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); + + marshaller.marshal(obj, out); + return outBytes.toString(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/integration/rundeck/src/test/java/org/apache/provisionr/rundeck/ProjectTest.java ---------------------------------------------------------------------- diff --git a/integration/rundeck/src/test/java/org/apache/provisionr/rundeck/ProjectTest.java b/integration/rundeck/src/test/java/org/apache/provisionr/rundeck/ProjectTest.java new file mode 100644 index 0000000..b313858 --- /dev/null +++ b/integration/rundeck/src/test/java/org/apache/provisionr/rundeck/ProjectTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2013 S.C. Axemblr Software Solutions S.R.L + * + * 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.provisionr.rundeck; + +import com.google.common.base.Charsets; +import com.google.common.collect.ImmutableMap; +import com.google.common.io.Resources; +import java.io.IOException; +import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual; +import org.junit.Test; + +/** + * A test to make sure the JAXB serialization works as expected + */ +public class ProjectTest extends BaseJaxbTest { + + @Test + public void testEmptyProject() throws Exception { + String actual = asXml(new Project()); + assertXMLEqual(actual, "", actual); + } + + @Test + public void testSimpleProject() throws Exception { + Project project = new Project(); + + Node node = new Node("db-1", "db-1.example.com", "psql"); + node.setTags(new String[]{"a", "b"}); + node.setAttributes(ImmutableMap.of("key1", "val1", "key2", "val2")); + + project.addNodes(node); + project.addNodes(new Node("web-1", "web-1.example.com", "django")); + + String actual = asXml(project); + assertXMLEqual(actual, readResource("fixtures/project.xml"), actual); + } + + private String readResource(String resource) throws IOException { + return Resources.toString(Resources.getResource(resource), Charsets.UTF_8); + } + + @Override + public Class[] getContextClasses() { + return new Class[]{Project.class}; + } +} http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/integration/rundeck/src/test/java/org/apache/provisionr/rundeck/RundeckServletTest.java ---------------------------------------------------------------------- diff --git a/integration/rundeck/src/test/java/org/apache/provisionr/rundeck/RundeckServletTest.java b/integration/rundeck/src/test/java/org/apache/provisionr/rundeck/RundeckServletTest.java new file mode 100644 index 0000000..f087434 --- /dev/null +++ b/integration/rundeck/src/test/java/org/apache/provisionr/rundeck/RundeckServletTest.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2013 S.C. Axemblr Software Solutions S.R.L + * + * 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.provisionr.rundeck; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import javax.xml.bind.JAXBException; +import org.activiti.engine.ProcessEngine; +import org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration; +import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.xml.sax.SAXException; + +public class RundeckServletTest { + + private ByteArrayOutputStream output; + private PrintWriter writer; + + @Before + public void setUp() { + output = new ByteArrayOutputStream(); + writer = new PrintWriter(output); + } + + @After + public void tearDown() throws IOException { + writer.close(); + output.close(); + } + + @Test + public void testEmptyListOfMachines() throws JAXBException, IOException, SAXException { + ProcessEngine processEngine = new StandaloneInMemProcessEngineConfiguration().buildProcessEngine(); + try { + RundeckServlet servlet = new RundeckServlet(processEngine); + servlet.writeRundeckResourceModelXmlTo(writer); + + writer.flush(); + assertXMLEqual(output.toString(), ""); + + } finally { + processEngine.close(); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/karaf/assembly-tests/pom.xml ---------------------------------------------------------------------- diff --git a/karaf/assembly-tests/pom.xml b/karaf/assembly-tests/pom.xml index 73f44d8..fa87017 100644 --- a/karaf/assembly-tests/pom.xml +++ b/karaf/assembly-tests/pom.xml @@ -18,31 +18,31 @@ provisionr-parent - com.axemblr.provisionr + org.apache.provisionr 0.4.0-SNAPSHOT ../../parent 4.0.0 - Axemblr Provisionr :: Custom Karaf Distribution Tests + Apache Provisionr :: Custom Karaf Distribution Tests provisionr-assembly-tests jar - com.axemblr.provisionr + org.apache.provisionr provisionr-core ${project.version} test - com.axemblr.provisionr + org.apache.provisionr provisionr-assembly ${project.version} test - com.axemblr.provisionr + org.apache.provisionr provisionr-test-support test http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/karaf/assembly-tests/src/test/java/com/axemblr/provisionr/karaf/CustomKarafDistributionTest.java ---------------------------------------------------------------------- diff --git a/karaf/assembly-tests/src/test/java/com/axemblr/provisionr/karaf/CustomKarafDistributionTest.java b/karaf/assembly-tests/src/test/java/com/axemblr/provisionr/karaf/CustomKarafDistributionTest.java deleted file mode 100644 index f1fca5e..0000000 --- a/karaf/assembly-tests/src/test/java/com/axemblr/provisionr/karaf/CustomKarafDistributionTest.java +++ /dev/null @@ -1,248 +0,0 @@ -/* - * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L - * - * 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 com.axemblr.provisionr.karaf; - -import com.axemblr.provisionr.api.Provisionr; -import com.axemblr.provisionr.core.templates.PoolTemplate; -import static com.axemblr.provisionr.test.KarafTests.getKarafVersionAsInProject; -import com.google.common.base.Stopwatch; -import com.google.common.io.CharStreams; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.net.URL; -import java.util.concurrent.TimeUnit; -import javax.inject.Inject; -import org.apache.karaf.features.Feature; -import org.apache.karaf.features.FeaturesService; -import static org.apache.karaf.tooling.exam.options.KarafDistributionOption.karafDistributionConfiguration; -import static org.apache.karaf.tooling.exam.options.KarafDistributionOption.keepRuntimeFolder; -import static org.apache.karaf.tooling.exam.options.KarafDistributionOption.logLevel; -import org.apache.karaf.tooling.exam.options.LogLevelOption; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import org.junit.Test; -import org.junit.runner.RunWith; -import static org.ops4j.pax.exam.CoreOptions.junitBundles; -import static org.ops4j.pax.exam.CoreOptions.maven; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.Configuration; -import org.ops4j.pax.exam.junit.ExamReactorStrategy; -import org.ops4j.pax.exam.junit.JUnit4TestRunner; -import org.ops4j.pax.exam.options.MavenArtifactUrlReference; -import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; -import org.osgi.framework.Constants; -import org.osgi.util.tracker.ServiceTracker; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Run a set of tests on the custom Karaf distribution - */ -@RunWith(JUnit4TestRunner.class) -@ExamReactorStrategy(AllConfinedStagedReactorFactory.class) -public class CustomKarafDistributionTest { - - private static final Logger LOG = LoggerFactory.getLogger(CustomKarafDistributionTest.class); - - public static final String ACTIVITI_EXPLORER_URL = "http://localhost:8181/activiti-explorer/"; - - public static final String RUNDECK_RESOURCE_URL = "http://localhost:8181/rundeck/machines.xml"; - - public static final String LOCALHOST = "localhost"; - - public static final int DEFAULT_JETTY_PORT = 8181; - public static final int TIMEOUT_IN_MILLISECONDS = 1000; - - /** - * We are only starting Amazon by default. The support for cloudstack is not ready yet. - */ - public static final int EXPECTED_NUMBER_OF_PROVISIONR_SERVICES = 1; - - /** - * We only register two pool templates by default through the provisionr-core bundle - */ - public static final int EXPECTED_NUMBER_OF_POOL_TEMPLATES = 3; - - @Inject - private FeaturesService features; - - @Inject - private BundleContext bundleContext; - - @Configuration - public Option[] configuration() throws Exception { - MavenArtifactUrlReference distributionUrl = maven().groupId("com.axemblr.provisionr") - .artifactId("provisionr-assembly").versionAsInProject().type("tar.gz"); - - return new Option[]{ - karafDistributionConfiguration() - .frameworkUrl(distributionUrl) - .karafVersion(getKarafVersionAsInProject()) - .name("Axemblr Provisionr") - .unpackDirectory(new File("target/exam")), - keepRuntimeFolder(), - junitBundles(), - logLevel(LogLevelOption.LogLevel.INFO) - }; - } - - @Test - public void testAllFeaturesStartAsExpected() throws Exception { - assertFeatureInstalled("axemblr-provisionr-all"); - - assertAllBundlesAreActive(); - - assertJettyStartsInLessThan(5000 /* milliseconds */); - - assertProvisionrServicesAreStartedInLessThan(5000 /* milliseconds */); - assertPoolTemplatesAreRegisteredInLessThan(5000 /* milliseconds */); - - assertUrlContainsInLessThan(ACTIVITI_EXPLORER_URL, "Vaadin", 10000 /* milliseconds */); - assertUrlContainsInLessThan(RUNDECK_RESOURCE_URL, " timeoutInMilliseconds) { - fail(String.format("Unable to fetch url '%s' in less than %d milliseconds", - url, timeoutInMilliseconds)); - } - - try { - String content = CharStreams.toString(new InputStreamReader(new URL(url).openStream())); - assertTrue(String.format("Expected to find '%s' in: %s", expectedContent, content), - content.contains(expectedContent)); - - break; /* test completed as expected */ - - } catch (Exception e) { - LOG.info(String.format("Unable to fetch %s (%s). Trying again in 5s.", url, e.getMessage())); - TimeUnit.SECONDS.sleep(5); - } - } - } - - private void assertProvisionrServicesAreStartedInLessThan(int timeoutInMilliseconds) throws Exception { - assertServicesAreStartedInLessThan(Provisionr.class, - EXPECTED_NUMBER_OF_PROVISIONR_SERVICES, timeoutInMilliseconds); - } - - private void assertPoolTemplatesAreRegisteredInLessThan(int timeoutInMilliseconds) throws Exception { - assertServicesAreStartedInLessThan(PoolTemplate.class, - EXPECTED_NUMBER_OF_POOL_TEMPLATES, timeoutInMilliseconds); - - } - - private void assertServicesAreStartedInLessThan( - Class klass, int expectedCardinality, int timeoutInMilliseconds - ) throws Exception { - final ServiceTracker tracker = new ServiceTracker(bundleContext, klass.getName(), null); - tracker.open(true); - try { - final Stopwatch stopwatch = new Stopwatch().start(); - - while (true) { - Object[] services = tracker.getServices(); - if (services == null || services.length < expectedCardinality) { - final int actualCount = (services == null) ? 0 : services.length; - if (stopwatch.elapsedMillis() > timeoutInMilliseconds) { - fail(String.format("Expected to find %d %s services. Found only %d in %d milliseconds", - expectedCardinality, klass.getSimpleName(), actualCount, timeoutInMilliseconds)); - } - - LOG.info(String.format("Found %d services implementing %s. Trying again in 1s.", - actualCount, klass.getName())); - TimeUnit.SECONDS.sleep(1); - - } else if (services.length > expectedCardinality) { - fail(String.format("Expected to find %d services implementing %s. Found %d (more than expected).", - expectedCardinality, klass.getName(), services.length)); - - } else if (services.length == expectedCardinality) { - break; /* done - the test was successful */ - } - } - - } finally { - tracker.close(); - } - } - - private void assertAllBundlesAreActive() { - for (Bundle bundle : bundleContext.getBundles()) { - // skip fragments, they can't be started - if (bundle.getHeaders().get(Constants.FRAGMENT_HOST) == null) { - assertEquals("Bundle " + bundle.getSymbolicName() + " is not active", - Bundle.ACTIVE, bundle.getState()); - } - } - } - - private void assertFeatureInstalled(String featureName) throws Exception { - Feature feature = features.getFeature(featureName); - assertTrue("Feature " + featureName + " should be installed", features.isInstalled(feature)); - } - - private void assertJettyStartsInLessThan(int timeoutInMilliseconds) throws InterruptedException { - Stopwatch stopwatch = new Stopwatch().start(); - while (!isPortOpen(LOCALHOST, DEFAULT_JETTY_PORT)) { - if (stopwatch.elapsedMillis() > timeoutInMilliseconds) { - fail(String.format("Jetty did not start listening on port %d in less than %d milliseconds", - DEFAULT_JETTY_PORT, timeoutInMilliseconds)); - } - - LOG.info("Waiting 1s for Jetty to listen on port 8181."); - TimeUnit.SECONDS.sleep(1); - } - } - - private boolean isPortOpen(String hostname, int port) { - InetSocketAddress socketAddress = new InetSocketAddress(hostname, port); - - Socket socket = null; - try { - socket = new Socket(); - socket.setReuseAddress(false); - socket.setSoLinger(false, 1); - socket.setSoTimeout(TIMEOUT_IN_MILLISECONDS); - socket.connect(socketAddress, TIMEOUT_IN_MILLISECONDS); - - } catch (IOException e) { - return false; - - } finally { - if (socket != null) { - try { - socket.close(); - } catch (IOException ioe) { - // no work to do - } - } - } - return true; - } -} http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/karaf/assembly-tests/src/test/java/org/apache/provisionr/karaf/CustomKarafDistributionTest.java ---------------------------------------------------------------------- diff --git a/karaf/assembly-tests/src/test/java/org/apache/provisionr/karaf/CustomKarafDistributionTest.java b/karaf/assembly-tests/src/test/java/org/apache/provisionr/karaf/CustomKarafDistributionTest.java new file mode 100644 index 0000000..dc8b1e8 --- /dev/null +++ b/karaf/assembly-tests/src/test/java/org/apache/provisionr/karaf/CustomKarafDistributionTest.java @@ -0,0 +1,248 @@ +/* + * Copyright (c) 2012 S.C. Axemblr Software Solutions S.R.L + * + * 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.provisionr.karaf; + +import com.google.common.base.Stopwatch; +import com.google.common.io.CharStreams; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.net.URL; +import java.util.concurrent.TimeUnit; +import javax.inject.Inject; +import org.apache.karaf.features.Feature; +import org.apache.karaf.features.FeaturesService; +import static org.apache.karaf.tooling.exam.options.KarafDistributionOption.karafDistributionConfiguration; +import static org.apache.karaf.tooling.exam.options.KarafDistributionOption.keepRuntimeFolder; +import static org.apache.karaf.tooling.exam.options.KarafDistributionOption.logLevel; +import org.apache.karaf.tooling.exam.options.LogLevelOption; +import org.apache.provisionr.api.Provisionr; +import org.apache.provisionr.core.templates.PoolTemplate; +import static org.apache.provisionr.test.KarafTests.getKarafVersionAsInProject; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import org.junit.Test; +import org.junit.runner.RunWith; +import static org.ops4j.pax.exam.CoreOptions.junitBundles; +import static org.ops4j.pax.exam.CoreOptions.maven; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.junit.Configuration; +import org.ops4j.pax.exam.junit.ExamReactorStrategy; +import org.ops4j.pax.exam.junit.JUnit4TestRunner; +import org.ops4j.pax.exam.options.MavenArtifactUrlReference; +import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; +import org.osgi.util.tracker.ServiceTracker; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Run a set of tests on the custom Karaf distribution + */ +@RunWith(JUnit4TestRunner.class) +@ExamReactorStrategy(AllConfinedStagedReactorFactory.class) +public class CustomKarafDistributionTest { + + private static final Logger LOG = LoggerFactory.getLogger(CustomKarafDistributionTest.class); + + public static final String ACTIVITI_EXPLORER_URL = "http://localhost:8181/activiti-explorer/"; + + public static final String RUNDECK_RESOURCE_URL = "http://localhost:8181/rundeck/machines.xml"; + + public static final String LOCALHOST = "localhost"; + + public static final int DEFAULT_JETTY_PORT = 8181; + public static final int TIMEOUT_IN_MILLISECONDS = 1000; + + /** + * We are only starting Amazon by default. The support for cloudstack is not ready yet. + */ + public static final int EXPECTED_NUMBER_OF_PROVISIONR_SERVICES = 1; + + /** + * We only register two pool templates by default through the provisionr-core bundle + */ + public static final int EXPECTED_NUMBER_OF_POOL_TEMPLATES = 3; + + @Inject + private FeaturesService features; + + @Inject + private BundleContext bundleContext; + + @Configuration + public Option[] configuration() throws Exception { + MavenArtifactUrlReference distributionUrl = maven().groupId("org.apache.provisionr") + .artifactId("provisionr-assembly").versionAsInProject().type("tar.gz"); + + return new Option[]{ + karafDistributionConfiguration() + .frameworkUrl(distributionUrl) + .karafVersion(getKarafVersionAsInProject()) + .name("Apache Provisionr") + .unpackDirectory(new File("target/exam")), + keepRuntimeFolder(), + junitBundles(), + logLevel(LogLevelOption.LogLevel.INFO) + }; + } + + @Test + public void testAllFeaturesStartAsExpected() throws Exception { + assertFeatureInstalled("provisionr-all"); + + assertAllBundlesAreActive(); + + assertJettyStartsInLessThan(5000 /* milliseconds */); + + assertProvisionrServicesAreStartedInLessThan(5000 /* milliseconds */); + assertPoolTemplatesAreRegisteredInLessThan(5000 /* milliseconds */); + + assertUrlContainsInLessThan(ACTIVITI_EXPLORER_URL, "Vaadin", 10000 /* milliseconds */); + assertUrlContainsInLessThan(RUNDECK_RESOURCE_URL, " timeoutInMilliseconds) { + fail(String.format("Unable to fetch url '%s' in less than %d milliseconds", + url, timeoutInMilliseconds)); + } + + try { + String content = CharStreams.toString(new InputStreamReader(new URL(url).openStream())); + assertTrue(String.format("Expected to find '%s' in: %s", expectedContent, content), + content.contains(expectedContent)); + + break; /* test completed as expected */ + + } catch (Exception e) { + LOG.info(String.format("Unable to fetch %s (%s). Trying again in 5s.", url, e.getMessage())); + TimeUnit.SECONDS.sleep(5); + } + } + } + + private void assertProvisionrServicesAreStartedInLessThan(int timeoutInMilliseconds) throws Exception { + assertServicesAreStartedInLessThan(Provisionr.class, + EXPECTED_NUMBER_OF_PROVISIONR_SERVICES, timeoutInMilliseconds); + } + + private void assertPoolTemplatesAreRegisteredInLessThan(int timeoutInMilliseconds) throws Exception { + assertServicesAreStartedInLessThan(PoolTemplate.class, + EXPECTED_NUMBER_OF_POOL_TEMPLATES, timeoutInMilliseconds); + + } + + private void assertServicesAreStartedInLessThan( + Class klass, int expectedCardinality, int timeoutInMilliseconds + ) throws Exception { + final ServiceTracker tracker = new ServiceTracker(bundleContext, klass.getName(), null); + tracker.open(true); + try { + final Stopwatch stopwatch = new Stopwatch().start(); + + while (true) { + Object[] services = tracker.getServices(); + if (services == null || services.length < expectedCardinality) { + final int actualCount = (services == null) ? 0 : services.length; + if (stopwatch.elapsedMillis() > timeoutInMilliseconds) { + fail(String.format("Expected to find %d %s services. Found only %d in %d milliseconds", + expectedCardinality, klass.getSimpleName(), actualCount, timeoutInMilliseconds)); + } + + LOG.info(String.format("Found %d services implementing %s. Trying again in 1s.", + actualCount, klass.getName())); + TimeUnit.SECONDS.sleep(1); + + } else if (services.length > expectedCardinality) { + fail(String.format("Expected to find %d services implementing %s. Found %d (more than expected).", + expectedCardinality, klass.getName(), services.length)); + + } else if (services.length == expectedCardinality) { + break; /* done - the test was successful */ + } + } + + } finally { + tracker.close(); + } + } + + private void assertAllBundlesAreActive() { + for (Bundle bundle : bundleContext.getBundles()) { + // skip fragments, they can't be started + if (bundle.getHeaders().get(Constants.FRAGMENT_HOST) == null) { + assertEquals("Bundle " + bundle.getSymbolicName() + " is not active", + Bundle.ACTIVE, bundle.getState()); + } + } + } + + private void assertFeatureInstalled(String featureName) throws Exception { + Feature feature = features.getFeature(featureName); + assertTrue("Feature " + featureName + " should be installed", features.isInstalled(feature)); + } + + private void assertJettyStartsInLessThan(int timeoutInMilliseconds) throws InterruptedException { + Stopwatch stopwatch = new Stopwatch().start(); + while (!isPortOpen(LOCALHOST, DEFAULT_JETTY_PORT)) { + if (stopwatch.elapsedMillis() > timeoutInMilliseconds) { + fail(String.format("Jetty did not start listening on port %d in less than %d milliseconds", + DEFAULT_JETTY_PORT, timeoutInMilliseconds)); + } + + LOG.info("Waiting 1s for Jetty to listen on port 8181."); + TimeUnit.SECONDS.sleep(1); + } + } + + private boolean isPortOpen(String hostname, int port) { + InetSocketAddress socketAddress = new InetSocketAddress(hostname, port); + + Socket socket = null; + try { + socket = new Socket(); + socket.setReuseAddress(false); + socket.setSoLinger(false, 1); + socket.setSoTimeout(TIMEOUT_IN_MILLISECONDS); + socket.connect(socketAddress, TIMEOUT_IN_MILLISECONDS); + + } catch (IOException e) { + return false; + + } finally { + if (socket != null) { + try { + socket.close(); + } catch (IOException ioe) { + // no work to do + } + } + } + return true; + } +} http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/karaf/assembly/pom.xml ---------------------------------------------------------------------- diff --git a/karaf/assembly/pom.xml b/karaf/assembly/pom.xml index 831d199..50f6901 100644 --- a/karaf/assembly/pom.xml +++ b/karaf/assembly/pom.xml @@ -15,26 +15,27 @@ ~ limitations under the License. --> - + provisionr-parent - com.axemblr.provisionr + org.apache.provisionr 0.4.0-SNAPSHOT ../../parent 4.0.0 - Axemblr Provisionr :: Custom Karaf Distribution + Apache Provisionr :: Custom Karaf Distribution Install all the features as a custom Karaf distribution provisionr-assembly - com.axemblr.provisionr + org.apache.provisionr provisionr-branding - com.axemblr.provisionr + org.apache.provisionr provisionr-features provided @@ -124,14 +125,14 @@ mvn:org.apache.karaf.assemblies.features/enterprise/${karaf.version}/xml/features - mvn:com.axemblr.provisionr/provisionr-features/${project.version}/xml/features + mvn:org.apache.provisionr/provisionr-features/${project.version}/xml/features config management webconsole - axemblr-provisionr-all + provisionr-all true target/features-repo @@ -143,6 +144,7 @@ org.apache.maven.plugins maven-assembly-plugin + 2.4 unix-bin http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/karaf/assembly/src/main/assembly/unix.xml ---------------------------------------------------------------------- diff --git a/karaf/assembly/src/main/assembly/unix.xml b/karaf/assembly/src/main/assembly/unix.xml index 725264d..107b6a6 100644 --- a/karaf/assembly/src/main/assembly/unix.xml +++ b/karaf/assembly/src/main/assembly/unix.xml @@ -110,7 +110,7 @@ provisionr-version.jar 0644 - com.axemblr.provisionr:provisionr-branding + org.apache.provisionr:provisionr-branding false http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/karaf/assembly/src/main/filtered-resources/etc/org.apache.karaf.features.cfg ---------------------------------------------------------------------- diff --git a/karaf/assembly/src/main/filtered-resources/etc/org.apache.karaf.features.cfg b/karaf/assembly/src/main/filtered-resources/etc/org.apache.karaf.features.cfg index 4d20079..1349a71 100644 --- a/karaf/assembly/src/main/filtered-resources/etc/org.apache.karaf.features.cfg +++ b/karaf/assembly/src/main/filtered-resources/etc/org.apache.karaf.features.cfg @@ -20,9 +20,9 @@ # # Comma separated list of features repositories to register by default # -featuresRepositories=mvn:org.apache.karaf.assemblies.features/standard/${karaf.version}/xml/features,mvn:org.apache.karaf.assemblies.features/enterprise/${karaf.version}/xml/features,mvn:com.axemblr.provisionr/provisionr-features/${project.version}/xml/features +featuresRepositories=mvn:org.apache.karaf.assemblies.features/standard/${karaf.version}/xml/features,mvn:org.apache.karaf.assemblies.features/enterprise/${karaf.version}/xml/features,mvn:org.apache.provisionr/provisionr-features/${project.version}/xml/features # # Comma separated list of features to install at startup # -featuresBoot=config,management,webconsole,axemblr-provisionr-all +featuresBoot=config,management,webconsole,provisionr-all http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/karaf/branding/pom.xml ---------------------------------------------------------------------- diff --git a/karaf/branding/pom.xml b/karaf/branding/pom.xml index f411a24..bdac65e 100644 --- a/karaf/branding/pom.xml +++ b/karaf/branding/pom.xml @@ -15,16 +15,17 @@ ~ limitations under the License. --> - + provisionr-parent - com.axemblr.provisionr + org.apache.provisionr 0.4.0-SNAPSHOT ../../parent/pom.xml 4.0.0 - Axemblr Provisionr :: Karaf Branding + Apache Provisionr :: Karaf Branding provisionr-branding bundle http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/karaf/branding/src/main/resources/org/apache/karaf/branding/branding.properties ---------------------------------------------------------------------- diff --git a/karaf/branding/src/main/resources/org/apache/karaf/branding/branding.properties b/karaf/branding/src/main/resources/org/apache/karaf/branding/branding.properties index 022710a..0482ec0 100644 --- a/karaf/branding/src/main/resources/org/apache/karaf/branding/branding.properties +++ b/karaf/branding/src/main/resources/org/apache/karaf/branding/branding.properties @@ -16,16 +16,20 @@ # welcome = \ -\u001B[36m ___ __ __ \u001B[0m\n\ -\u001B[36m / _ | __ __ ___ __ _ / / / / ____ \u001B[0m\n\ -\u001B[36m / __ | \\ \\ / / -_) / ' \\ / _ \\ / / / __/ \u001B[0m\n\ -\u001B[36m /_/_|_| /_\\_\\ \\__/ /_/_/_/ /_.__/ /_/ /_/ \u001B[0m\n\ -\u001B[36m / _ \\ ____ ___ _ __ (_) ___ (_) ___ ___ ____ \u001B[0m\n\ -\u001B[36m / ___/ / __/ / _ \\ | |/ / / / (_-< / / / _ \\ / _ \\ / __/\u001B[0m\n\ -\u001B[36m /_/ /_/ \\___/ |___/ /_/ /___/ /_/ \\___/ /_//_/ /_/ \u001B[0m\n\ +\u001B[36m _ _ \u001B[0m\n\ +\u001B[36m /_\\ _ __ __ _ ___| |__ ___ \u001B[0m\n\ +\u001B[36m //_\\\\| '_ \\ / _` |/ __| '_ \\ / _ \\ \u001B[0m\n\ +\u001B[36m / _ \\ |_) | (_| | (__| | | | __/ \u001B[0m\n\ +\u001B[36m \\_/ \\_/ .__/ \\__,_|\\___|_| |_|\\___| \u001B[0m\n\ +\u001B[36m |_| \u001B[0m\n\ +\u001B[36m ___ _ _ \u001B[0m\n\ +\u001B[36m / _ \\_ __ _____ _(_)___(_) ___ _ __ _ __ \u001B[0m\n\ +\u001B[36m / /_)/ '__/ _ \\ \\ / / / __| |/ _ \\| '_ \\| '__|\u001B[0m\n\ +\u001B[36m / ___/| | | (_) \\ V /| \\__ \\ | (_) | | | | | \u001B[0m\n\ +\u001B[36m \\/ |_| \\___/ \\_/ |_|___/_|\\___/|_| |_|_| \u001B[0m\n\ \n\ -\u001B[1m Axemblr Provisionr \u001B[0m (${pom.version})\n\ -\u001B[36m http://axemblr.com\u001B[0m\n\ +\u001B[1m Apache Provisionr \u001B[0m (${pom.version})\n\ +\u001B[36m http://provisionr.incubator.apache.org/\u001B[0m\n\ \n\ Hit '\u001B[1m\u001B[0m' for a list of available commands\n\ and '\u001B[1m[cmd] --help\u001B[0m' for help on a specific command.\n\ http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/karaf/commands/pom.xml ---------------------------------------------------------------------- diff --git a/karaf/commands/pom.xml b/karaf/commands/pom.xml index 7e64413..87c1819 100644 --- a/karaf/commands/pom.xml +++ b/karaf/commands/pom.xml @@ -15,16 +15,17 @@ ~ limitations under the License. --> - + provisionr-parent - com.axemblr.provisionr + org.apache.provisionr 0.4.0-SNAPSHOT ../../parent/pom.xml 4.0.0 - Axemblr Provisionr :: Karaf Commands + Apache Provisionr :: Karaf Commands provisionr-commands bundle @@ -42,11 +43,11 @@ activiti-engine - com.axemblr.provisionr + org.apache.provisionr provisionr-api - com.axemblr.provisionr + org.apache.provisionr provisionr-core @@ -102,7 +103,7 @@ ${basedir}/target/classes - com.axemblr.provisionr.commands + org.apache.provisionr.commands org.apache.felix.gogo.commands, http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/karaf/commands/src/main/java/com/axemblr/provisionr/commands/CreateCommand.java ---------------------------------------------------------------------- diff --git a/karaf/commands/src/main/java/com/axemblr/provisionr/commands/CreateCommand.java b/karaf/commands/src/main/java/com/axemblr/provisionr/commands/CreateCommand.java deleted file mode 100644 index 5072703..0000000 --- a/karaf/commands/src/main/java/com/axemblr/provisionr/commands/CreateCommand.java +++ /dev/null @@ -1,130 +0,0 @@ -package com.axemblr.provisionr.commands; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.axemblr.provisionr.api.Provisionr; -import com.axemblr.provisionr.api.access.AdminAccess; -import com.axemblr.provisionr.api.network.Network; -import com.axemblr.provisionr.api.network.Rule; -import com.axemblr.provisionr.api.pool.Pool; -import com.axemblr.provisionr.api.provider.Provider; -import com.axemblr.provisionr.commands.predicates.ProvisionrPredicates; -import com.axemblr.provisionr.core.templates.PoolTemplate; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Charsets; -import com.google.common.base.Optional; -import com.google.common.base.Throwables; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; -import com.google.common.io.Files; -import com.google.common.util.concurrent.Service; - -import java.io.File; -import java.util.List; -import java.util.NoSuchElementException; -import java.util.Set; - -import org.apache.felix.gogo.commands.Option; -import org.apache.karaf.shell.console.OsgiCommandSupport; - -public abstract class CreateCommand extends OsgiCommandSupport { - - @Option(name = "--id", description = "Service ID (use provisionr:services)", required = true) - protected String id; - - @Option(name = "--package", description = "Package to install by default (multi-valued)", - multiValued = true) - protected List packages = Lists.newArrayList(); - - @Option(name = "-t", aliases = "--template", description = "Pre-configured template (packages, files)") - protected String template; - - @Option(name = "--timeout", description = "Timeout in seconds for the command's initialization steps. " + - "If not specified, defaults to 600 seconds.") - protected int bootstrapTimeout = 600; - - protected final List services; - - protected final List templates; - - public CreateCommand(List services, List templates) { - this.services = checkNotNull(services, "services is null"); - this.templates = checkNotNull(templates, "templates is null"); - } - - @VisibleForTesting - void setId(String id) { - this.id = checkNotNull(id, "id is null"); - } - - @VisibleForTesting - void setPackages(List packages) { - this.packages = ImmutableList.copyOf(packages); - } - - @VisibleForTesting - void setTemplate(String template) { - this.template = checkNotNull(template, "template is null"); - } - - @VisibleForTesting - AdminAccess collectCurrentUserCredentialsForAdminAccess() { - String userHome = System.getProperty("user.home"); - - try { - String publicKey = Files.toString(new File(userHome, ".ssh/id_rsa.pub"), Charsets.UTF_8); - String privateKey = Files.toString(new File(userHome, ".ssh/id_rsa"), Charsets.UTF_8); - - return AdminAccess.builder().username(System.getProperty("user.name")) - .publicKey(publicKey).privateKey(privateKey).createAdminAccess(); - } catch (Exception e) { - throw Throwables.propagate(e); - } - } - - @VisibleForTesting - Pool applyTemplate(Pool pool) { - for (PoolTemplate candidate : templates) { - if (candidate.getId().equalsIgnoreCase(template)) { - return candidate.apply(pool); - } - } - throw new NoSuchElementException("No pool template found with name: " + template); - } - - @VisibleForTesting - Network buildNetwork(List ports) { - /* Always allow ICMP and ssh traffic by default */ - return Network.builder().addRules( - Rule.builder().anySource().icmp().createRule(), - Rule.builder().anySource().tcp().port(22).createRule() - ).addRules( - formatPortsAsIngressRules(ports) - ).createNetwork(); - } - - Optional getDefaultProvider(Provisionr service) { - checkArgument(service.getDefaultProvider().isPresent(), String.format("please configure a default provider " + - "by editing etc/com.axemblr.provisionr.%s.cfg", id)); - return service.getDefaultProvider(); - } - - Provisionr getService() { - Optional service = Iterables.tryFind(services, ProvisionrPredicates.withId(id)); - if (!service.isPresent()) { - throw new NoSuchElementException("No provisioning service found with id: " + id); - } - return service.get(); - } - - private Set formatPortsAsIngressRules(List ports) { - ImmutableSet.Builder rules = ImmutableSet.builder(); - for (int port : ports) { - rules.add(Rule.builder().anySource().tcp().port(port).createRule()); - } - return rules.build(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-provisionr/blob/6ba40c4b/karaf/commands/src/main/java/com/axemblr/provisionr/commands/CreateImageCommand.java ---------------------------------------------------------------------- diff --git a/karaf/commands/src/main/java/com/axemblr/provisionr/commands/CreateImageCommand.java b/karaf/commands/src/main/java/com/axemblr/provisionr/commands/CreateImageCommand.java deleted file mode 100644 index e5ec778..0000000 --- a/karaf/commands/src/main/java/com/axemblr/provisionr/commands/CreateImageCommand.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.axemblr.provisionr.commands; - -import static com.google.common.base.Preconditions.checkNotNull; - -import com.axemblr.provisionr.api.Provisionr; -import com.axemblr.provisionr.api.hardware.Hardware; -import com.axemblr.provisionr.api.hardware.HardwareBuilder; -import com.axemblr.provisionr.api.pool.Pool; -import com.axemblr.provisionr.api.software.Software; -import com.axemblr.provisionr.commands.predicates.ProvisionrPredicates; -import com.axemblr.provisionr.core.templates.PoolTemplate; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Optional; -import com.google.common.collect.Iterables; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -import org.apache.felix.gogo.commands.Command; - -@Command(scope = "provisionr", name = "cache", description = "Create a cached golden image.") -public class CreateImageCommand extends CreateCommand { - - // TODO: remove this and use a provided parameter - private static final String HARDWARE_TYPE = "t1.micro"; - - public CreateImageCommand(List services, List templates) { - super(services, templates); - } - - @Override - protected Object doExecute() throws Exception { - Provisionr service = getService(); - final Pool pool = createPoolOfOne(service); - // TODO: create service.startCachingProcess(uuid, pool) in the Provisionr class - return null; - } - - @VisibleForTesting - Pool createPoolOfOne(Provisionr service) { - - final Software software = Software.builder().packages(packages).createSoftware(); - final Hardware hardware = Hardware.builder().type(HARDWARE_TYPE).createHardware(); - - final Pool pool = Pool.builder() - .provider(getDefaultProvider(service).get()) - .hardware(hardware) - .software(software) - .network(buildNetwork(new ArrayList())) - .adminAccess(collectCurrentUserCredentialsForAdminAccess()) - .minSize(1) - .expectedSize(1) - .bootstrapTimeInSeconds(bootstrapTimeout) - .createPool(); - - return template != null ? applyTemplate(pool) : pool; - - } - -}