Thomas Vachuska

Removed STC as it has been moved to a separate repository.

Change-Id: I419079b4ce539e5c082dd3f9dcf2bf8a91e2e45a
Showing 43 changed files with 0 additions and 2745 deletions
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
37 <module>yangutils</module> 37 <module>yangutils</module>
38 <module>osgi</module> 38 <module>osgi</module>
39 <module>rest</module> 39 <module>rest</module>
40 - <module>stc</module>
41 <module>jdvue</module> 40 <module>jdvue</module>
42 <module>osgiwrap</module> 41 <module>osgiwrap</module>
43 </modules> 42 </modules>
......
1 -#!/bin/bash
2 -#-------------------------------------------------------------------------------
3 -# System Test Coordinator
4 -#-------------------------------------------------------------------------------
5 -
6 -STC_ROOT=${STC_ROOT:-$(dirname $0)/..}
7 -cd $STC_ROOT
8 -VER=1.6.0-SNAPSHOT
9 -
10 -PATH=$PWD/bin:$PATH
11 -
12 -java -jar target/onlab-stc-$VER.jar "$@"
1 -#!/bin/bash
2 -#-------------------------------------------------------------------------------
3 -# System Test Coordinator process launcher
4 -#-------------------------------------------------------------------------------
5 -
6 -env=$1 && shift
7 -cwd=$1 && shift
8 -
9 -if [ $env != "-" ]; then
10 - [ ! -f $env ] && echo "$env file not found" && exit 1
11 - source $env
12 -fi
13 -
14 -if [ $cwd != "-" ]; then
15 - [ ! -d $cwd ] && echo "$cwd directory not found" && exit 1
16 - cd $cwd
17 -fi
18 -
19 -"$@" 2>&1
1 -<?xml version="1.0" encoding="UTF-8"?>
2 -<!--
3 - ~ Copyright 2015-present Open Networking Laboratory
4 - ~
5 - ~ Licensed under the Apache License, Version 2.0 (the "License");
6 - ~ you may not use this file except in compliance with the License.
7 - ~ You may obtain a copy of the License at
8 - ~
9 - ~ http://www.apache.org/licenses/LICENSE-2.0
10 - ~
11 - ~ Unless required by applicable law or agreed to in writing, software
12 - ~ distributed under the License is distributed on an "AS IS" BASIS,
13 - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 - ~ See the License for the specific language governing permissions and
15 - ~ limitations under the License.
16 - -->
17 -<project xmlns="http://maven.apache.org/POM/4.0.0"
18 - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19 - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20 - <modelVersion>4.0.0</modelVersion>
21 -
22 - <parent>
23 - <groupId>org.onosproject</groupId>
24 - <artifactId>onlab-utils</artifactId>
25 - <version>1.6.0-SNAPSHOT</version>
26 - </parent>
27 -
28 - <artifactId>onlab-stc</artifactId>
29 - <packaging>jar</packaging>
30 -
31 - <description>System Test Coordinator</description>
32 -
33 - <dependencies>
34 - <dependency>
35 - <groupId>org.onosproject</groupId>
36 - <artifactId>onlab-misc</artifactId>
37 - </dependency>
38 - <dependency>
39 - <groupId>org.onosproject</groupId>
40 - <artifactId>onlab-junit</artifactId>
41 - <scope>test</scope>
42 - </dependency>
43 -
44 - <dependency>
45 - <groupId>commons-configuration</groupId>
46 - <artifactId>commons-configuration</artifactId>
47 - </dependency>
48 -
49 - <dependency>
50 - <groupId>commons-collections</groupId>
51 - <artifactId>commons-collections</artifactId>
52 - </dependency>
53 -
54 - <dependency>
55 - <groupId>com.fasterxml.jackson.core</groupId>
56 - <artifactId>jackson-databind</artifactId>
57 - <version>2.7.3</version>
58 - <scope>compile</scope>
59 - </dependency>
60 - <dependency>
61 - <groupId>com.fasterxml.jackson.core</groupId>
62 - <artifactId>jackson-annotations</artifactId>
63 - <version>2.7.3</version>
64 - <scope>compile</scope>
65 - </dependency>
66 -
67 - <dependency>
68 - <groupId>org.eclipse.jetty</groupId>
69 - <artifactId>jetty-server</artifactId>
70 - <version>8.1.19.v20160209</version>
71 - </dependency>
72 - <dependency>
73 - <groupId>org.eclipse.jetty</groupId>
74 - <artifactId>jetty-servlet</artifactId>
75 - <version>8.1.19.v20160209</version>
76 - </dependency>
77 - <dependency>
78 - <groupId>org.eclipse.jetty</groupId>
79 - <artifactId>jetty-websocket</artifactId>
80 - <version>8.1.19.v20160209</version>
81 - </dependency>
82 - </dependencies>
83 -
84 - <build>
85 - <plugins>
86 - <plugin>
87 - <groupId>org.apache.maven.plugins</groupId>
88 - <artifactId>maven-shade-plugin</artifactId>
89 - <version>2.4.2</version>
90 - <configuration>
91 - <transformers>
92 - <transformer
93 - implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
94 - <mainClass>org.onlab.stc.Main
95 - </mainClass>
96 - </transformer>
97 - </transformers>
98 - <filters>
99 - <filter>
100 - <artifact>*:*</artifact>
101 - <excludes>
102 - <exclude>META-INF/*.SF</exclude>
103 - <exclude>META-INF/*.DSA</exclude>
104 - <exclude>META-INF/*.RSA</exclude>
105 - </excludes>
106 - </filter>
107 - </filters>
108 - </configuration>
109 - <executions>
110 - <execution>
111 - <phase>package</phase>
112 - <goals>
113 - <goal>shade</goal>
114 - </goals>
115 - </execution>
116 - </executions>
117 - </plugin>
118 - </plugins>
119 - </build>
120 -
121 -</project>
1 -<!--
2 - ~ Copyright 2015-present Open Networking Laboratory
3 - ~
4 - ~ Licensed under the Apache License, Version 2.0 (the "License");
5 - ~ you may not use this file except in compliance with the License.
6 - ~ You may obtain a copy of the License at
7 - ~
8 - ~ http://www.apache.org/licenses/LICENSE-2.0
9 - ~
10 - ~ Unless required by applicable law or agreed to in writing, software
11 - ~ distributed under the License is distributed on an "AS IS" BASIS,
12 - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - ~ See the License for the specific language governing permissions and
14 - ~ limitations under the License.
15 - -->
16 -<scenario name="sample" description="Sample Test Scenario">
17 - <step name="alpha" exec="/bin/ls -l"/>
18 - <step name="beta" exec="/bin/ls -lF"/>
19 - <step name="gamma" exec="/bin/ls" requires="alpha,beta"/>
20 -</scenario>
...\ No newline at end of file ...\ No newline at end of file
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.stc;
17 -
18 -import com.google.common.base.MoreObjects;
19 -import org.onlab.graph.AbstractEdge;
20 -
21 -import java.util.Objects;
22 -
23 -/**
24 - * Representation of a dependency from one step on completion of another.
25 - */
26 -public class Dependency extends AbstractEdge<Step> {
27 -
28 - private boolean isSoft;
29 -
30 - /**
31 - * Creates a new edge between the specified source and destination vertexes.
32 - *
33 - * @param src source vertex
34 - * @param dst destination vertex
35 - * @param isSoft indicates whether this is a hard or soft dependency
36 - */
37 - public Dependency(Step src, Step dst, boolean isSoft) {
38 - super(src, dst);
39 - this.isSoft = isSoft;
40 - }
41 -
42 - /**
43 - * Indicates whether this is a soft or hard dependency, i.e. one that
44 - * requires successful completion of the dependency or just any completion.
45 - *
46 - * @return true if dependency is a soft one
47 - */
48 - public boolean isSoft() {
49 - return isSoft;
50 - }
51 -
52 - @Override
53 - public int hashCode() {
54 - return 31 * super.hashCode() + Objects.hash(isSoft);
55 - }
56 -
57 - @Override
58 - public boolean equals(Object obj) {
59 - if (this == obj) {
60 - return true;
61 - }
62 - if (obj instanceof Dependency) {
63 - final Dependency other = (Dependency) obj;
64 - return super.equals(other) && Objects.equals(this.isSoft, other.isSoft);
65 - }
66 - return false;
67 - }
68 -
69 - @Override
70 - public String toString() {
71 - return MoreObjects.toStringHelper(this)
72 - .add("name", src().name())
73 - .add("requires", dst().name())
74 - .add("isSoft", isSoft)
75 - .toString();
76 - }
77 -}
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.stc;
17 -
18 -import com.google.common.collect.ImmutableSet;
19 -import com.google.common.collect.Sets;
20 -
21 -import java.util.Set;
22 -
23 -/**
24 - * Represenation of a related group of steps.
25 - */
26 -public class Group extends Step {
27 -
28 - private final Set<Step> children = Sets.newHashSet();
29 -
30 - /**
31 - * Creates a new test step.
32 - *
33 - * @param name group name
34 - * @param command default command
35 - * @param env default path to file to be sourced into the environment
36 - * @param cwd default path to current working directory for the step
37 - * @param group optional group to which this step belongs
38 - * @param delay seconds to delay before executing
39 - */
40 - public Group(String name, String command, String env, String cwd, Group group, int delay) {
41 - super(name, command, env, cwd, group, delay);
42 - }
43 -
44 - /**
45 - * Returns the set of child steps and groups contained within this group.
46 - *
47 - * @return set of children
48 - */
49 - public Set<Step> children() {
50 - return ImmutableSet.copyOf(children);
51 - }
52 -
53 - /**
54 - * Adds the specified step or group as a child of this group.
55 - *
56 - * @param child child step or group to add
57 - */
58 - public void addChild(Step child) {
59 - children.add(child);
60 - }
61 -}
This diff is collapsed. Click to expand it.
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.stc;
17 -
18 -import com.fasterxml.jackson.databind.ObjectMapper;
19 -import com.fasterxml.jackson.databind.node.ArrayNode;
20 -import com.fasterxml.jackson.databind.node.ObjectNode;
21 -import com.google.common.collect.Maps;
22 -import org.onlab.stc.MonitorLayout.Box;
23 -
24 -import java.io.FileWriter;
25 -import java.io.IOException;
26 -import java.io.PrintWriter;
27 -import java.util.Map;
28 -
29 -import static org.onlab.stc.Coordinator.Status.IN_PROGRESS;
30 -
31 -/**
32 - * Scenario test monitor.
33 - */
34 -public class Monitor implements StepProcessListener {
35 -
36 - private final ObjectMapper mapper = new ObjectMapper();
37 -
38 - private final Coordinator coordinator;
39 - private final Compiler compiler;
40 - private final MonitorLayout layout;
41 -
42 - private MonitorDelegate delegate;
43 -
44 - private Map<Step, Box> boxes = Maps.newHashMap();
45 -
46 - /**
47 - * Creates a new shared process flow monitor.
48 - *
49 - * @param coordinator process flow coordinator
50 - * @param compiler scenario compiler
51 - */
52 - Monitor(Coordinator coordinator, Compiler compiler) {
53 - this.coordinator = coordinator;
54 - this.compiler = compiler;
55 - this.layout = new MonitorLayout(compiler);
56 - coordinator.addListener(this);
57 - }
58 -
59 - /**
60 - * Sets the process monitor delegate.
61 - *
62 - * @param delegate process monitor delegate
63 - */
64 - void setDelegate(MonitorDelegate delegate) {
65 - this.delegate = delegate;
66 - }
67 -
68 - /**
69 - * Notifies the process monitor delegate with the specified event.
70 - *
71 - * @param event JSON event data
72 - */
73 - public void notify(ObjectNode event) {
74 - if (delegate != null) {
75 - delegate.notify(event);
76 - }
77 - }
78 -
79 - /**
80 - * Returns the scenario process flow as JSON data.
81 - *
82 - * @return scenario process flow data
83 - */
84 - ObjectNode scenarioData() {
85 - ObjectNode root = mapper.createObjectNode();
86 - ArrayNode steps = mapper.createArrayNode();
87 - ArrayNode requirements = mapper.createArrayNode();
88 -
89 - ProcessFlow pf = compiler.processFlow();
90 - pf.getVertexes().forEach(step -> add(step, steps));
91 - pf.getEdges().forEach(requirement -> add(requirement, requirements));
92 -
93 - root.set("steps", steps);
94 - root.set("requirements", requirements);
95 -
96 - try (FileWriter fw = new FileWriter("/tmp/data.json");
97 - PrintWriter pw = new PrintWriter(fw)) {
98 - pw.println(root.toString());
99 - } catch (IOException e) {
100 - e.printStackTrace();
101 - }
102 - return root;
103 - }
104 -
105 -
106 - private void add(Step step, ArrayNode steps) {
107 - Box box = layout.get(step);
108 - ObjectNode sn = mapper.createObjectNode()
109 - .put("name", step.name())
110 - .put("isGroup", step instanceof Group)
111 - .put("status", status(coordinator.getStatus(step)))
112 - .put("tier", box.tier())
113 - .put("depth", box.depth());
114 - if (step.group() != null) {
115 - sn.put("group", step.group().name());
116 - }
117 - steps.add(sn);
118 - }
119 -
120 - private String status(Coordinator.Status status) {
121 - return status.toString().toLowerCase();
122 - }
123 -
124 - private void add(Dependency requirement, ArrayNode requirements) {
125 - ObjectNode rn = mapper.createObjectNode();
126 - rn.put("src", requirement.src().name())
127 - .put("dst", requirement.dst().name())
128 - .put("isSoft", requirement.isSoft());
129 - requirements.add(rn);
130 - }
131 -
132 - @Override
133 - public void onStart(Step step, String command) {
134 - notify(event(step, status(IN_PROGRESS)));
135 - }
136 -
137 - @Override
138 - public void onCompletion(Step step, Coordinator.Status status) {
139 - notify(event(step, status(status)));
140 - }
141 -
142 - @Override
143 - public void onOutput(Step step, String line) {
144 -
145 - }
146 -
147 - private ObjectNode event(Step step, String status) {
148 - ObjectNode event = mapper.createObjectNode()
149 - .put("name", step.name())
150 - .put("status", status);
151 - return event;
152 - }
153 -
154 -}
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.stc;
17 -
18 -import com.fasterxml.jackson.databind.node.ObjectNode;
19 -
20 -/**
21 - * Delegate to which monitor can send notifications.
22 - */
23 -public interface MonitorDelegate {
24 -
25 - /**
26 - * Issues JSON event to be sent to any connected monitor clients.
27 - *
28 - * @param event JSON event data
29 - */
30 - void notify(ObjectNode event);
31 -}
This diff is collapsed. Click to expand it.
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.stc;
17 -
18 -import com.fasterxml.jackson.databind.ObjectMapper;
19 -import com.fasterxml.jackson.databind.node.ObjectNode;
20 -import org.eclipse.jetty.websocket.WebSocket;
21 -
22 -import java.io.IOException;
23 -
24 -import static org.onlab.stc.Coordinator.print;
25 -
26 -/**
27 - * Web socket capable of interacting with the STC monitor GUI.
28 - */
29 -public class MonitorWebSocket implements WebSocket.OnTextMessage, WebSocket.OnControl {
30 -
31 - private static final long MAX_AGE_MS = 30_000;
32 -
33 - private static final byte PING = 0x9;
34 - private static final byte PONG = 0xA;
35 - private static final byte[] PING_DATA = new byte[]{(byte) 0xde, (byte) 0xad};
36 -
37 - private final Monitor monitor;
38 -
39 - private Connection connection;
40 - private FrameConnection control;
41 -
42 - private final ObjectMapper mapper = new ObjectMapper();
43 -
44 - private long lastActive = System.currentTimeMillis();
45 -
46 - /**
47 - * Creates a new monitor client GUI web-socket.
48 - *
49 - * @param monitor shared process flow monitor
50 - */
51 - MonitorWebSocket(Monitor monitor) {
52 - this.monitor = monitor;
53 - }
54 -
55 - /**
56 - * Issues a close on the connection.
57 - */
58 - synchronized void close() {
59 - destroyHandlers();
60 - if (connection.isOpen()) {
61 - connection.close();
62 - }
63 - }
64 -
65 - /**
66 - * Indicates if this connection is idle.
67 - *
68 - * @return true if idle or closed
69 - */
70 - synchronized boolean isIdle() {
71 - long quietFor = System.currentTimeMillis() - lastActive;
72 - boolean idle = quietFor > MAX_AGE_MS;
73 - if (idle || (connection != null && !connection.isOpen())) {
74 - return true;
75 - } else if (connection != null) {
76 - try {
77 - control.sendControl(PING, PING_DATA, 0, PING_DATA.length);
78 - } catch (IOException e) {
79 - print("Unable to send ping message due to: %s", e);
80 - }
81 - }
82 - return false;
83 - }
84 -
85 - @Override
86 - public void onOpen(Connection connection) {
87 - this.connection = connection;
88 - this.control = (FrameConnection) connection;
89 - try {
90 - createHandlers();
91 - sendMessage(message("flow", monitor.scenarioData()));
92 -
93 - } catch (Exception e) {
94 - print("Unable to open monitor connection: %s", e);
95 - this.connection.close();
96 - this.connection = null;
97 - this.control = null;
98 - }
99 - }
100 -
101 - @Override
102 - public synchronized void onClose(int closeCode, String message) {
103 - destroyHandlers();
104 - }
105 -
106 - @Override
107 - public boolean onControl(byte controlCode, byte[] data, int offset, int length) {
108 - lastActive = System.currentTimeMillis();
109 - return true;
110 - }
111 -
112 - @Override
113 - public void onMessage(String data) {
114 - lastActive = System.currentTimeMillis();
115 - try {
116 - ObjectNode message = (ObjectNode) mapper.reader().readTree(data);
117 - // TODO:
118 - print("Got message: %s", message);
119 - } catch (Exception e) {
120 - print("Unable to parse GUI message %s due to %s", data, e);
121 - }
122 - }
123 -
124 - public synchronized void sendMessage(ObjectNode message) {
125 - try {
126 - if (connection.isOpen()) {
127 - connection.sendMessage(message.toString());
128 - }
129 - } catch (IOException e) {
130 - print("Unable to send message %s to GUI due to %s", message, e);
131 - }
132 - }
133 -
134 - public ObjectNode message(String type, ObjectNode payload) {
135 - ObjectNode message = mapper.createObjectNode().put("event", type);
136 - message.set("payload", payload);
137 - return message;
138 - }
139 -
140 - // Creates new message handlers.
141 - private synchronized void createHandlers() {
142 - }
143 -
144 - // Destroys message handlers.
145 - private synchronized void destroyHandlers() {
146 - }
147 -
148 -}
149 -
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.stc;
17 -
18 -import com.fasterxml.jackson.databind.node.ObjectNode;
19 -import com.google.common.io.ByteStreams;
20 -import com.google.common.net.MediaType;
21 -import org.eclipse.jetty.websocket.WebSocket;
22 -import org.eclipse.jetty.websocket.WebSocketServlet;
23 -
24 -import javax.servlet.ServletException;
25 -import javax.servlet.http.HttpServletRequest;
26 -import javax.servlet.http.HttpServletResponse;
27 -import java.io.IOException;
28 -import java.io.InputStream;
29 -import java.util.HashSet;
30 -import java.util.Iterator;
31 -import java.util.Set;
32 -import java.util.Timer;
33 -import java.util.TimerTask;
34 -
35 -/**
36 - * Web socket servlet capable of creating web sockets for the STC monitor.
37 - */
38 -public class MonitorWebSocketServlet extends WebSocketServlet
39 - implements MonitorDelegate {
40 -
41 - private static final long PING_DELAY_MS = 5000;
42 - private static final String DOT = ".";
43 -
44 - private static Monitor monitor;
45 - private static MonitorWebSocketServlet instance;
46 -
47 - private final Set<MonitorWebSocket> sockets = new HashSet<>();
48 - private final Timer timer = new Timer();
49 - private final TimerTask pruner = new Pruner();
50 -
51 - /**
52 - * Binds the shared process flow monitor.
53 - *
54 - * @param m process monitor reference
55 - */
56 - public static void setMonitor(Monitor m) {
57 - monitor = m;
58 - }
59 -
60 - /**
61 - * Closes all currently open monitor web-sockets.
62 - */
63 - public static void closeAll() {
64 - if (instance != null) {
65 - instance.sockets.forEach(MonitorWebSocket::close);
66 - instance.sockets.clear();
67 - }
68 - }
69 -
70 - @Override
71 - public void init() throws ServletException {
72 - super.init();
73 - instance = this;
74 - monitor.setDelegate(this);
75 - timer.schedule(pruner, PING_DELAY_MS, PING_DELAY_MS);
76 - }
77 -
78 - @Override
79 - protected void doGet(HttpServletRequest req, HttpServletResponse resp)
80 - throws ServletException, IOException {
81 - String uri = req.getRequestURI();
82 - uri = uri.length() <= 1 ? "/index.html" : uri;
83 - InputStream resource = getClass().getResourceAsStream(uri);
84 - if (resource == null) {
85 - resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
86 - } else {
87 - byte[] entity = ByteStreams.toByteArray(resource);
88 - resp.setStatus(HttpServletResponse.SC_OK);
89 - resp.setContentType(contentType(uri).toString());
90 - resp.setContentLength(entity.length);
91 - resp.getOutputStream().write(entity);
92 - }
93 - }
94 -
95 - private MediaType contentType(String uri) {
96 - int sep = uri.lastIndexOf(DOT);
97 - String ext = sep > 0 ? uri.substring(sep + 1) : null;
98 - return ext == null ? MediaType.APPLICATION_BINARY :
99 - ext.equals("html") ? MediaType.HTML_UTF_8 :
100 - ext.equals("js") ? MediaType.JAVASCRIPT_UTF_8 :
101 - ext.equals("css") ? MediaType.CSS_UTF_8 :
102 - MediaType.APPLICATION_BINARY;
103 - }
104 -
105 - @Override
106 - public WebSocket doWebSocketConnect(HttpServletRequest request, String protocol) {
107 - MonitorWebSocket socket = new MonitorWebSocket(monitor);
108 - synchronized (sockets) {
109 - sockets.add(socket);
110 - }
111 - return socket;
112 - }
113 -
114 - @Override
115 - public void notify(ObjectNode event) {
116 - if (instance != null) {
117 - instance.sockets.forEach(ws -> ws.sendMessage(event));
118 - }
119 - }
120 -
121 - // Task for pruning web-sockets that are idle.
122 - private class Pruner extends TimerTask {
123 - @Override
124 - public void run() {
125 - synchronized (sockets) {
126 - Iterator<MonitorWebSocket> it = sockets.iterator();
127 - while (it.hasNext()) {
128 - MonitorWebSocket socket = it.next();
129 - if (socket.isIdle()) {
130 - it.remove();
131 - socket.close();
132 - }
133 - }
134 - }
135 - }
136 - }
137 -}
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.stc;
17 -
18 -import org.onlab.graph.MutableAdjacencyListsGraph;
19 -
20 -import java.util.Set;
21 -
22 -/**
23 - * Graph representation of a test process flow.
24 - */
25 -public class ProcessFlow extends MutableAdjacencyListsGraph<Step, Dependency> {
26 -
27 - /**
28 - * Creates a graph comprising of the specified vertexes and edges.
29 - *
30 - * @param vertexes set of graph vertexes
31 - * @param edges set of graph edges
32 - */
33 - public ProcessFlow(Set<Step> vertexes, Set<Dependency> edges) {
34 - super(vertexes, edges);
35 - }
36 -
37 -}
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.stc;
17 -
18 -import org.apache.commons.configuration.ConfigurationException;
19 -import org.apache.commons.configuration.HierarchicalConfiguration;
20 -import org.apache.commons.configuration.XMLConfiguration;
21 -
22 -import java.io.InputStream;
23 -
24 -import static com.google.common.base.Preconditions.checkNotNull;
25 -import static com.google.common.base.Preconditions.checkState;
26 -
27 -/**
28 - * Representation of a re-usable test scenario.
29 - */
30 -public final class Scenario {
31 -
32 - private static final String SCENARIO = "scenario";
33 - private static final String NAME = "[@name]";
34 - private static final String DESCRIPTION = "[@description]";
35 -
36 - private final String name;
37 - private final String description;
38 - private final HierarchicalConfiguration definition;
39 -
40 - // Creates a new scenario from the specified definition.
41 - private Scenario(String name, String description, HierarchicalConfiguration definition) {
42 - this.name = checkNotNull(name, "Name cannot be null");
43 - this.description = checkNotNull(description, "Description cannot be null");
44 - this.definition = checkNotNull(definition, "Definition cannot be null");
45 - }
46 -
47 - /**
48 - * Loads a new scenario from the specified hierarchical configuration.
49 - *
50 - * @param definition scenario definition
51 - * @return loaded scenario
52 - */
53 - public static Scenario loadScenario(HierarchicalConfiguration definition) {
54 - String name = definition.getString(NAME);
55 - String description = definition.getString(DESCRIPTION, "");
56 - checkState(name != null, "Scenario name must be specified");
57 - return new Scenario(name, description, definition);
58 - }
59 -
60 - /**
61 - * Loads a new scenario from the specified input stream.
62 - *
63 - * @param stream scenario definition stream
64 - * @return loaded scenario
65 - */
66 - public static Scenario loadScenario(InputStream stream) {
67 - XMLConfiguration cfg = new XMLConfiguration();
68 - cfg.setAttributeSplittingDisabled(true);
69 - cfg.setDelimiterParsingDisabled(true);
70 - cfg.setRootElementName(SCENARIO);
71 - try {
72 - cfg.load(stream);
73 - return loadScenario(cfg);
74 - } catch (ConfigurationException e) {
75 - throw new IllegalArgumentException("Unable to load scenario from the stream", e);
76 - }
77 - }
78 -
79 - /**
80 - * Returns the scenario name.
81 - *
82 - * @return scenario name
83 - */
84 - public String name() {
85 - return name;
86 - }
87 -
88 - /**
89 - * Returns the scenario description.
90 - *
91 - * @return scenario description
92 - */
93 - public String description() {
94 - return description;
95 - }
96 -
97 - /**
98 - * Returns the scenario definition.
99 - *
100 - * @return scenario definition
101 - */
102 - public HierarchicalConfiguration definition() {
103 - return definition;
104 - }
105 -
106 -}
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.stc;
17 -
18 -import com.google.common.collect.ImmutableList;
19 -import com.google.common.collect.Lists;
20 -import com.google.common.collect.Maps;
21 -import org.apache.commons.configuration.ConfigurationException;
22 -import org.apache.commons.configuration.PropertiesConfiguration;
23 -import org.onlab.stc.Coordinator.Status;
24 -
25 -import java.io.File;
26 -import java.util.List;
27 -import java.util.Map;
28 -import java.util.Set;
29 -
30 -import static com.google.common.base.Preconditions.checkNotNull;
31 -import static org.onlab.stc.Coordinator.Status.*;
32 -import static org.onlab.stc.Coordinator.print;
33 -
34 -/**
35 - * Maintains state of scenario execution.
36 - */
37 -class ScenarioStore {
38 -
39 - private final ProcessFlow processFlow;
40 - private final File storeFile;
41 - private final File logDir;
42 -
43 - private final List<StepEvent> events = Lists.newArrayList();
44 - private final Map<String, Status> statusMap = Maps.newConcurrentMap();
45 -
46 - private long startTime = Long.MAX_VALUE;
47 - private long endTime = Long.MIN_VALUE;
48 -
49 - /**
50 - * Creates a new scenario store for the specified process flow.
51 - *
52 - * @param processFlow scenario process flow
53 - * @param logDir scenario log directory
54 - * @param name scenario name
55 - */
56 - ScenarioStore(ProcessFlow processFlow, File logDir, String name) {
57 - this.processFlow = processFlow;
58 - this.logDir = logDir;
59 - this.storeFile = new File(logDir, name + ".stc");
60 - load();
61 - }
62 -
63 - /**
64 - * Resets status of all steps to waiting and clears all events.
65 - */
66 - void reset() {
67 - events.clear();
68 - statusMap.clear();
69 - processFlow.getVertexes().forEach(step -> statusMap.put(step.name(), WAITING));
70 - try {
71 - removeLogs();
72 - PropertiesConfiguration cfg = new PropertiesConfiguration(storeFile);
73 - cfg.clear();
74 - cfg.save();
75 - startTime = Long.MAX_VALUE;
76 - endTime = Long.MIN_VALUE;
77 - } catch (ConfigurationException e) {
78 - print("Unable to store file %s", storeFile);
79 - }
80 -
81 - }
82 -
83 - /**
84 - * Returns set of all test steps.
85 - *
86 - * @return set of steps
87 - */
88 - Set<Step> getSteps() {
89 - return processFlow.getVertexes();
90 - }
91 -
92 - /**
93 - * Returns a chronological list of step or group records.
94 - *
95 - * @return list of events
96 - */
97 - synchronized List<StepEvent> getEvents() {
98 - return ImmutableList.copyOf(events);
99 - }
100 -
101 - /**
102 - * Returns the status record of the specified test step.
103 - *
104 - * @param step test step or group
105 - * @return step status record
106 - */
107 - Status getStatus(Step step) {
108 - return checkNotNull(statusMap.get(step.name()), "Step %s not found", step.name());
109 - }
110 -
111 - /**
112 - * Marks the specified test step as being in progress.
113 - *
114 - * @param step test step or group
115 - */
116 - synchronized void markStarted(Step step) {
117 - add(new StepEvent(step.name(), IN_PROGRESS, step.command()));
118 - save();
119 - }
120 -
121 - /**
122 - * Marks the specified test step as being complete.
123 - *
124 - * @param step test step or group
125 - * @param status new step status
126 - */
127 - synchronized void markComplete(Step step, Status status) {
128 - add(new StepEvent(step.name(), status, null));
129 - save();
130 - }
131 -
132 - /**
133 - * Returns true if all steps in the store have been marked as completed
134 - * regardless of the completion status.
135 - *
136 - * @return true if all steps completed one way or another
137 - */
138 - synchronized boolean isComplete() {
139 - return !statusMap.values().stream().anyMatch(s -> s == WAITING || s == IN_PROGRESS);
140 - }
141 -
142 - /**
143 - * Indicates whether there are any failures.
144 - *
145 - * @return true if there are failed steps
146 - */
147 - boolean hasFailures() {
148 - for (Status status : statusMap.values()) {
149 - if (status == FAILED) {
150 - return true;
151 - }
152 - }
153 - return false;
154 - }
155 -
156 - /**
157 - * Registers a new step record.
158 - *
159 - * @param event step event
160 - */
161 - private synchronized void add(StepEvent event) {
162 - events.add(event);
163 - statusMap.put(event.name(), event.status());
164 - startTime = Math.min(startTime, event.time());
165 - endTime = Math.max(endTime, event.time());
166 - }
167 -
168 - /**
169 - * Loads the states from disk.
170 - */
171 - private void load() {
172 - try {
173 - PropertiesConfiguration cfg = new PropertiesConfiguration(storeFile);
174 - cfg.getKeys().forEachRemaining(prop -> add(StepEvent.fromString(cfg.getString(prop))));
175 - cfg.save();
176 - } catch (ConfigurationException e) {
177 - print("Unable to load file %s", storeFile);
178 - }
179 - }
180 -
181 - /**
182 - * Saves the states to disk.
183 - */
184 - private void save() {
185 - try {
186 - PropertiesConfiguration cfg = new PropertiesConfiguration(storeFile);
187 - events.forEach(event -> cfg.setProperty("T" + event.time(), event.toString()));
188 - cfg.save();
189 - } catch (ConfigurationException e) {
190 - print("Unable to store file %s", storeFile);
191 - }
192 - }
193 -
194 - /**
195 - * Removes all scenario log files.
196 - */
197 - private void removeLogs() {
198 - File[] logFiles = logDir.listFiles();
199 - if (logFiles != null && logFiles.length > 0) {
200 - for (File file : logFiles) {
201 - if (!file.delete()) {
202 - print("Unable to delete log file %s", file);
203 - }
204 - }
205 - }
206 - }
207 -
208 - /**
209 - * Returns the scenario run start time.
210 - *
211 - * @return start time in mills since start of epoch
212 - */
213 - public long startTime() {
214 - return startTime;
215 - }
216 -
217 - /**
218 - * Returns the scenario run end time or current time if the scenario
219 - * is still running.
220 - *
221 - * @return end time (or current time) in mills since start of epoch
222 - */
223 - public long endTime() {
224 - return endTime > 0 ? endTime : System.currentTimeMillis();
225 - }
226 -}
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.stc;
17 -
18 -import com.google.common.base.MoreObjects;
19 -import org.onlab.graph.Vertex;
20 -
21 -import java.util.Objects;
22 -
23 -import static com.google.common.base.Preconditions.checkNotNull;
24 -
25 -/**
26 - * Representation of a test step.
27 - */
28 -public class Step implements Vertex {
29 -
30 - protected final String name;
31 - protected final String command;
32 - protected final String env;
33 - protected final String cwd;
34 - protected final Group group;
35 - protected final int delay;
36 -
37 - /**
38 - * Creates a new test step.
39 - *
40 - * @param name step name
41 - * @param command step command to execute
42 - * @param env path to file to be sourced into the environment
43 - * @param cwd path to current working directory for the step
44 - * @param group optional group to which this step belongs
45 - * @param delay seconds to delay before executing
46 - */
47 - public Step(String name, String command, String env, String cwd, Group group, int delay) {
48 - this.name = checkNotNull(name, "Name cannot be null");
49 - this.group = group;
50 - this.delay = delay;
51 -
52 - // Set the command, environment and cwd
53 - // If one is not given use the value from the enclosing group
54 - this.command = command != null ? command : group != null && group.command != null ? group.command : null;
55 - this.env = env != null ? env : group != null && group.env != null ? group.env : null;
56 - this.cwd = cwd != null ? cwd : group != null && group.cwd != null ? group.cwd : null;
57 - }
58 -
59 - /**
60 - * Returns the step name.
61 - *
62 - * @return step name
63 - */
64 - public String name() {
65 - return name;
66 - }
67 -
68 - /**
69 - * Returns the step command string.
70 - *
71 - * @return command string
72 - */
73 - public String command() {
74 - return command;
75 - }
76 -
77 - /**
78 - * Returns the step environment script path.
79 - *
80 - * @return env script path
81 - */
82 - public String env() {
83 - return env;
84 - }
85 -
86 - /**
87 - * Returns the step current working directory path.
88 - *
89 - * @return current working dir path
90 - */
91 - public String cwd() {
92 - return cwd;
93 - }
94 -
95 - /**
96 - * Returns the enclosing group; null if none.
97 - *
98 - * @return enclosing group or null
99 - */
100 - public Group group() {
101 - return group;
102 - }
103 -
104 - /**
105 - * Returns the start delay in seconds.
106 - *
107 - * @return number of seconds
108 - */
109 - public int delay() {
110 - return delay;
111 - }
112 -
113 - @Override
114 - public int hashCode() {
115 - return name.hashCode();
116 - }
117 -
118 - @Override
119 - public boolean equals(Object obj) {
120 - if (this == obj) {
121 - return true;
122 - }
123 - if (obj instanceof Step) {
124 - final Step other = (Step) obj;
125 - return Objects.equals(this.name, other.name);
126 - }
127 - return false;
128 - }
129 -
130 - @Override
131 - public String toString() {
132 - return MoreObjects.toStringHelper(this)
133 - .add("name", name)
134 - .add("command", command)
135 - .add("env", env)
136 - .add("cwd", cwd)
137 - .add("group", group)
138 - .add("delay", delay)
139 - .toString();
140 - }
141 -}
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.stc;
17 -
18 -import org.onlab.stc.Coordinator.Status;
19 -
20 -import static java.lang.Long.parseLong;
21 -import static org.onlab.stc.Coordinator.Status.valueOf;
22 -
23 -/**
24 - * Represents an event of execution of a scenario step or group.
25 - */
26 -public class StepEvent {
27 -
28 - private static final String SEP = "~";
29 -
30 - private final String name;
31 - private final long time;
32 - private final Status status;
33 - private final String command;
34 -
35 - /**
36 - * Creates a new step record.
37 - *
38 - * @param name test step or group name
39 - * @param time time in millis since start of epoch
40 - * @param status step completion status
41 - * @param command step command
42 - */
43 - public StepEvent(String name, long time, Status status, String command) {
44 - this.name = name;
45 - this.time = time;
46 - this.status = status;
47 - this.command = command;
48 - }
49 -
50 - /**
51 - * Creates a new step record for non-running status.
52 - *
53 - * @param name test step or group name
54 - * @param status status
55 - * @param command step command
56 - */
57 - public StepEvent(String name, Status status, String command) {
58 - this(name, System.currentTimeMillis(), status, command);
59 - }
60 -
61 - /**
62 - * Returns the test step or test group name.
63 - *
64 - * @return step or group name
65 - */
66 - public String name() {
67 - return name;
68 - }
69 -
70 - /**
71 - * Returns the step event time.
72 - *
73 - * @return time in millis since start of epoch
74 - */
75 - public long time() {
76 - return time;
77 - }
78 -
79 - /**
80 - * Returns the step completion status.
81 - *
82 - * @return completion status
83 - */
84 - public Status status() {
85 - return status;
86 - }
87 -
88 - /**
89 - * Returns the step command.
90 - *
91 - * @return step command
92 - */
93 - public String command() {
94 - return command;
95 - }
96 -
97 -
98 - @Override
99 - public String toString() {
100 - return name + SEP + time + SEP + status + SEP + command;
101 - }
102 -
103 - /**
104 - * Returns a record parsed from the specified string.
105 - *
106 - * @param string string encoding
107 - * @return step record
108 - */
109 - public static StepEvent fromString(String string) {
110 - String[] fields = string.split("~");
111 - return fields.length == 4 ?
112 - new StepEvent(fields[0], parseLong(fields[1]), valueOf(fields[2]),
113 - fields[3].equals("null") ? null : fields[3]) :
114 - new StepEvent(fields[0], 0, Status.WAITING, null);
115 - }
116 -}
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.stc;
17 -
18 -/**
19 - * Entity capable of receiving notifications of process step execution events.
20 - */
21 -public interface StepProcessListener {
22 -
23 - /**
24 - * Indicates that process step has started.
25 - *
26 - * @param step subject step
27 - * @param command actual command executed; includes run-time substitutions
28 - */
29 - default void onStart(Step step, String command) {
30 - }
31 -
32 - /**
33 - * Indicates that process step has completed.
34 - *
35 - * @param step subject step
36 - * @param status step completion status
37 - */
38 - default void onCompletion(Step step, Coordinator.Status status) {
39 - }
40 -
41 - /**
42 - * Notifies when a new line of output becomes available.
43 - *
44 - * @param step subject step
45 - * @param line line of output
46 - */
47 - default void onOutput(Step step, String line) {
48 - }
49 -
50 -}
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.stc;
17 -
18 -import org.onlab.stc.Coordinator.Status;
19 -
20 -import java.io.BufferedReader;
21 -import java.io.File;
22 -import java.io.IOException;
23 -import java.io.InputStream;
24 -import java.io.InputStreamReader;
25 -import java.io.PrintWriter;
26 -
27 -import static java.lang.String.format;
28 -import static org.onlab.stc.Coordinator.Status.FAILED;
29 -import static org.onlab.stc.Coordinator.Status.SUCCEEDED;
30 -import static org.onlab.stc.Coordinator.print;
31 -
32 -/**
33 - * Manages execution of the specified step or a group.
34 - */
35 -class StepProcessor implements Runnable {
36 -
37 - private static final String IGNORE_CODE = "~";
38 - private static final String NEGATE_CODE = "!";
39 -
40 - private static final int FAIL = -1;
41 - private static final int SECONDS = 1_000;
42 -
43 - static String launcher = "stc-launcher ";
44 -
45 - private final Step step;
46 - private final File logDir;
47 - private String command;
48 -
49 - private Process process;
50 - private StepProcessListener delegate;
51 -
52 - /**
53 - * Creates a process monitor.
54 - *
55 - * @param step step or group to be executed
56 - * @param logDir directory where step process log should be stored
57 - * @param delegate process lifecycle listener
58 - * @param command actual command to execute
59 - */
60 - StepProcessor(Step step, File logDir, StepProcessListener delegate,
61 - String command) {
62 - this.step = step;
63 - this.logDir = logDir;
64 - this.delegate = delegate;
65 - this.command = command;
66 - }
67 -
68 - @Override
69 - public void run() {
70 - delegate.onStart(step, command);
71 - delayIfNeeded();
72 - int code = execute();
73 - boolean ignoreCode = step.env() != null && step.env.equals(IGNORE_CODE);
74 - boolean negateCode = step.env() != null && step.env.equals(NEGATE_CODE);
75 - Status status = ignoreCode || code == 0 && !negateCode || code != 0 && negateCode ?
76 - SUCCEEDED : FAILED;
77 - delegate.onCompletion(step, status);
78 - }
79 -
80 - /**
81 - * Pauses if the step requires it.
82 - */
83 - private void delayIfNeeded() {
84 - if (step.delay() > 0) {
85 - try {
86 - Thread.sleep(step.delay() * SECONDS);
87 - } catch (InterruptedException e) {
88 - throw new RuntimeException("Interrupted", e);
89 - }
90 - }
91 - }
92 -
93 - /**
94 - * Executes the step process.
95 - *
96 - * @return exit code
97 - */
98 - private int execute() {
99 - try (PrintWriter pw = new PrintWriter(logFile())) {
100 - process = Runtime.getRuntime().exec(command());
101 - processOutput(pw);
102 -
103 - // Wait for the process to complete and get its exit code.
104 - if (process.isAlive()) {
105 - process.waitFor();
106 - }
107 - return process.exitValue();
108 -
109 - } catch (IOException e) {
110 - print("Unable to run step %s using command %s", step.name(), step.command());
111 - } catch (InterruptedException e) {
112 - print("Step %s interrupted", step.name());
113 - }
114 - return FAIL;
115 - }
116 -
117 - /**
118 - * Returns ready-to-run command for the step.
119 - *
120 - * @return command to execute
121 - */
122 - private String command() {
123 - return format("%s %s %s %s", launcher,
124 - step.env() != null ? step.env() : "-",
125 - step.cwd() != null ? step.cwd() : "-",
126 - command);
127 - }
128 -
129 - /**
130 - * Captures output of the step process.
131 - *
132 - * @param pw print writer to send output to
133 - * @throws IOException if unable to read output or write logs
134 - */
135 - private void processOutput(PrintWriter pw) throws IOException {
136 - InputStream out = process.getInputStream();
137 - BufferedReader br = new BufferedReader(new InputStreamReader(out));
138 -
139 - // Slurp its combined stderr/stdout
140 - String line;
141 - while ((line = br.readLine()) != null) {
142 - pw.println(line);
143 - delegate.onOutput(step, line);
144 - }
145 - }
146 -
147 - /**
148 - * Returns the log file for the step output.
149 - *
150 - * @return log file
151 - */
152 - private File logFile() {
153 - return new File(logDir, step.name() + ".log");
154 - }
155 -
156 -}
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -
17 -/**
18 - * System Test Coordinator tool for modular scenario-based testing.
19 - */
20 -package org.onlab.stc;
...\ No newline at end of file ...\ No newline at end of file
This diff is collapsed. Click to expand it.
1 -<!DOCTYPE html>
2 -<!--
3 - ~ Copyright 2015-present Open Networking Laboratory
4 - ~
5 - ~ Licensed under the Apache License, Version 2.0 (the "License");
6 - ~ you may not use this file except in compliance with the License.
7 - ~ You may obtain a copy of the License at
8 - ~
9 - ~ http://www.apache.org/licenses/LICENSE-2.0
10 - ~
11 - ~ Unless required by applicable law or agreed to in writing, software
12 - ~ distributed under the License is distributed on an "AS IS" BASIS,
13 - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 - ~ See the License for the specific language governing permissions and
15 - ~ limitations under the License.
16 - -->
17 -<html>
18 -<head lang="en">
19 - <meta charset="utf-8">
20 - <title>Scenario Test Coordinator</title>
21 -
22 - <link rel="stylesheet" href="stc.css">
23 -
24 - <script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
25 - <script src="stc.js"></script>
26 -</head>
27 -<body>
28 -</body>
29 -</html>
...\ No newline at end of file ...\ No newline at end of file
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -
17 -.body {
18 - font-family: Helvetica, Arial, sans-serif;
19 -}
20 -
21 -.node {
22 - stroke: #fff;
23 - stroke-width: 1.5px;
24 -}
25 -
26 -.link {
27 - stroke: #999;
28 - stroke-opacity: .6;
29 -}
30 -
31 -text {
32 - font-family: 'DejaVu Sans', Arial, Helvetica, sans-serif;
33 - stroke: #000;
34 - stroke-width: 0.2;
35 - font-weight: normal;
36 - font-size: 0.6em;
37 -}
...\ No newline at end of file ...\ No newline at end of file
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -(function () {
17 -
18 - var ws, flow,
19 - nodes = [],
20 - links = [],
21 - nodeIndexes = {};
22 -
23 - var width = 2400,
24 - height = 2400;
25 -
26 - var color = d3.scale.category20();
27 -
28 - var force = d3.layout.force()
29 - .charge(-820)
30 - .linkDistance(50)
31 - .size([width, height]);
32 -
33 - // Process flow graph layout
34 - function createNode(n) {
35 - nodeIndexes[n.name] = nodes.push(n) - 1;
36 - }
37 -
38 - function createLink(e) {
39 - e.source = nodeIndexes[e.src];
40 - e.target = nodeIndexes[e.dst];
41 - links.push(e);
42 - }
43 -
44 - // Returns the newly computed bounding box of the rectangle
45 - function adjustRectToFitText(n) {
46 - var text = n.select('text'),
47 - box = text.node().getBBox();
48 -
49 - text.attr('text-anchor', 'left')
50 - .attr('y', 2)
51 - .attr('x', 4);
52 -
53 - // add padding
54 - box.x -= 4;
55 - box.width += 8;
56 - box.y -= 2;
57 - box.height += 4;
58 -
59 - n.select("rect").attr(box);
60 - }
61 -
62 - function processFlow() {
63 - var svg = d3.select("body").append("svg")
64 - .attr("width", width)
65 - .attr("height", height);
66 -
67 - flow.steps.forEach(createNode);
68 - flow.requirements.forEach(createLink);
69 -
70 - force
71 - .nodes(nodes)
72 - .links(links)
73 - .start();
74 -
75 - var link = svg.selectAll(".link")
76 - .data(links)
77 - .enter().append("line")
78 - .attr("class", "link")
79 - .style("stroke-width", function(d) { return d.isSoft ? 1 : 2; });
80 -
81 - var node = svg.selectAll(".node")
82 - .data(nodes)
83 - .enter().append("g")
84 - .attr("class", "node")
85 - .call(force.drag);
86 -
87 - node.append("rect")
88 - .attr({ rx: 5, ry:5, width:180, height:18 })
89 - .style("fill", function(d) { return color(d.group); });
90 -
91 - node.append("text").text( function(d) { return d.name; })
92 - .attr({ dy:"1.1em", width:100, height:16, x:4, y:2 });
93 -
94 - node.append("title")
95 - .text(function(d) { return d.name; });
96 -
97 - force.on("tick", function() {
98 - link.attr("x1", function(d) { return d.source.x; })
99 - .attr("y1", function(d) { return d.source.y; })
100 - .attr("x2", function(d) { return d.target.x; })
101 - .attr("y2", function(d) { return d.target.y; });
102 -
103 - node.attr("transform", function(d) { return "translate(" + (d.x - 180/2) + "," + (d.y - 18/2) + ")"; });
104 - });
105 - }
106 -
107 -
108 - // Web socket callbacks
109 -
110 - function handleOpen() {
111 - console.log('WebSocket open');
112 - }
113 -
114 - // Handles the specified (incoming) message using handler bindings.
115 - function handleMessage(msg) {
116 - console.log('rx: ', msg);
117 - evt = JSON.parse(msg.data);
118 - if (evt.event === 'progress') {
119 -
120 - } else if (evt.event === 'log') {
121 -
122 - } else if (evt.event === 'flow') {
123 - flow = evt.payload;
124 - processFlow();
125 - }
126 - }
127 -
128 - function handleClose() {
129 - console.log('WebSocket closed');
130 - }
131 -
132 - if (false) {
133 - d3.json("data.json", function (error, data) {
134 - flow = data;
135 - processFlow();
136 - });
137 - return;
138 - }
139 -
140 - // Open the web-socket
141 - ws = new WebSocket(document.location.href.replace('http:', 'ws:'));
142 - if (ws) {
143 - ws.onopen = handleOpen;
144 - ws.onmessage = handleMessage;
145 - ws.onclose = handleClose;
146 - }
147 -
148 -})();
...\ No newline at end of file ...\ No newline at end of file
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.stc;
17 -
18 -import org.junit.AfterClass;
19 -import org.junit.BeforeClass;
20 -import org.junit.Test;
21 -import org.onlab.util.Tools;
22 -
23 -import com.google.common.io.Files;
24 -
25 -import java.io.File;
26 -import java.io.FileInputStream;
27 -import java.io.FileNotFoundException;
28 -import java.io.IOException;
29 -
30 -import static com.google.common.io.ByteStreams.toByteArray;
31 -import static com.google.common.io.Files.write;
32 -import static org.junit.Assert.assertEquals;
33 -import static org.junit.Assert.assertSame;
34 -import static org.onlab.stc.Scenario.loadScenario;
35 -
36 -/**
37 - * Test of the test scenario compiler.
38 - */
39 -public class CompilerTest {
40 -
41 -
42 - private static File testDir;
43 -
44 - @BeforeClass
45 - public static void setUpClass() throws IOException {
46 - testDir = Files.createTempDir();
47 - stageTestResource("scenario.xml");
48 - stageTestResource("simple-scenario.xml");
49 - stageTestResource("one-scenario.xml");
50 - stageTestResource("two-scenario.xml");
51 -
52 - System.setProperty("prop.foo", "Foobar");
53 - System.setProperty("prop.bar", "Barfoo");
54 - System.setProperty("TOC1", "1.2.3.1");
55 - System.setProperty("TOC2", "1.2.3.2");
56 - System.setProperty("TOC3", "1.2.3.3");
57 - System.setProperty("test.dir", testDir.getAbsolutePath());
58 - }
59 -
60 - @AfterClass
61 - public static void tearDownClass() throws IOException {
62 - Tools.removeDirectory(testDir.getPath());
63 - }
64 -
65 - static FileInputStream getStream(String name) throws FileNotFoundException {
66 - return new FileInputStream(new File(testDir, name));
67 - }
68 -
69 - static void stageTestResource(String name) throws IOException {
70 - byte[] bytes = toByteArray(CompilerTest.class.getResourceAsStream(name));
71 - write(bytes, new File(testDir, name));
72 - }
73 -
74 - @Test
75 - public void basics() throws Exception {
76 - Scenario scenario = loadScenario(getStream("scenario.xml"));
77 - Compiler compiler = new Compiler(scenario);
78 - compiler.compile();
79 - ProcessFlow flow = compiler.processFlow();
80 -
81 - assertSame("incorrect scenario", scenario, compiler.scenario());
82 - assertEquals("incorrect step count", 33, flow.getVertexes().size());
83 - assertEquals("incorrect dependency count", 26, flow.getEdges().size());
84 - assertEquals("incorrect logDir",
85 - new File(testDir.getAbsolutePath(), "foo"), compiler.logDir());
86 -
87 - Step step = compiler.getStep("there");
88 - assertEquals("incorrect edge count", 2, flow.getEdgesFrom(step).size());
89 - assertEquals("incorrect edge count", 0, flow.getEdgesTo(step).size());
90 -
91 - Step group = compiler.getStep("three");
92 - assertEquals("incorrect edge count", 2, flow.getEdgesFrom(group).size());
93 - assertEquals("incorrect edge count", 0, flow.getEdgesTo(group).size());
94 - }
95 -
96 -}
...\ No newline at end of file ...\ No newline at end of file
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.stc;
17 -
18 -import org.junit.AfterClass;
19 -import org.junit.BeforeClass;
20 -import org.junit.Test;
21 -import org.onlab.util.Tools;
22 -
23 -import java.io.IOException;
24 -
25 -import static org.onlab.stc.CompilerTest.getStream;
26 -import static org.onlab.stc.Coordinator.print;
27 -import static org.onlab.stc.Scenario.loadScenario;
28 -
29 -/**
30 - * Test of the test coordinator.
31 - */
32 -public class CoordinatorTest {
33 -
34 - private Coordinator coordinator;
35 - private StepProcessListener listener = new Listener();
36 -
37 - @BeforeClass
38 - public static void setUpClass() throws IOException {
39 - CompilerTest.setUpClass();
40 -
41 - StepProcessor.launcher = "true ";
42 - }
43 -
44 - @AfterClass
45 - public static void tearDownClass() throws IOException {
46 - CompilerTest.tearDownClass();
47 - }
48 -
49 - @Test
50 - public void simple() throws IOException, InterruptedException {
51 - executeTest("simple-scenario.xml");
52 - }
53 -
54 - @Test
55 - public void complex() throws IOException, InterruptedException {
56 - executeTest("scenario.xml");
57 - }
58 -
59 - private void executeTest(String name) throws IOException, InterruptedException {
60 - Scenario scenario = loadScenario(getStream(name));
61 - Compiler compiler = new Compiler(scenario);
62 - compiler.compile();
63 - Tools.removeDirectory(compiler.logDir());
64 - coordinator = new Coordinator(scenario, compiler.processFlow(), compiler.logDir());
65 - coordinator.addListener(listener);
66 - coordinator.reset();
67 - coordinator.start();
68 - coordinator.waitFor();
69 - coordinator.removeListener(listener);
70 - }
71 -
72 - private class Listener implements StepProcessListener {
73 - @Override
74 - public void onStart(Step step, String command) {
75 - print("> %s: started; %s", step.name(), command);
76 - }
77 -
78 - @Override
79 - public void onCompletion(Step step, Coordinator.Status status) {
80 - print("< %s: %s", step.name(), status == Coordinator.Status.SUCCEEDED ? "completed" : "failed");
81 - }
82 -
83 - @Override
84 - public void onOutput(Step step, String line) {
85 - print(" %s: %s", step.name(), line);
86 - }
87 - }
88 -}
...\ No newline at end of file ...\ No newline at end of file
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.stc;
17 -
18 -import com.google.common.testing.EqualsTester;
19 -import org.apache.commons.configuration.ConfigurationException;
20 -import org.junit.Before;
21 -import org.junit.Test;
22 -
23 -import static org.junit.Assert.*;
24 -
25 -/**
26 - * Test of the test step dependency.
27 - */
28 -public class DependencyTest extends StepTest {
29 -
30 - protected Step step1, step2;
31 -
32 - @Override
33 - @Before
34 - public void setUp() throws ConfigurationException {
35 - super.setUp();
36 - step1 = new Step("step1", CMD, null, null, null, 0);
37 - step2 = new Step("step2", CMD, null, null, null, 0);
38 - }
39 -
40 - @Test
41 - public void hard() {
42 - Dependency hard = new Dependency(step1, step2, false);
43 - assertSame("incorrect src", step1, hard.src());
44 - assertSame("incorrect dst", step2, hard.dst());
45 - assertFalse("incorrect isSoft", hard.isSoft());
46 - }
47 -
48 - @Test
49 - public void soft() {
50 - Dependency soft = new Dependency(step2, step1, true);
51 - assertSame("incorrect src", step2, soft.src());
52 - assertSame("incorrect dst", step1, soft.dst());
53 - assertTrue("incorrect isSoft", soft.isSoft());
54 - }
55 -
56 - @Override
57 - @Test
58 - public void equality() {
59 - Dependency d1 = new Dependency(step1, step2, false);
60 - Dependency d2 = new Dependency(step1, step2, false);
61 - Dependency d3 = new Dependency(step1, step2, true);
62 - Dependency d4 = new Dependency(step2, step1, true);
63 - new EqualsTester()
64 - .addEqualityGroup(d1, d2)
65 - .addEqualityGroup(d3)
66 - .addEqualityGroup(d4)
67 - .testEquals();
68 - }
69 -
70 -}
...\ No newline at end of file ...\ No newline at end of file
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.stc;
17 -
18 -import com.google.common.testing.EqualsTester;
19 -import org.junit.Test;
20 -
21 -import static org.junit.Assert.assertEquals;
22 -import static org.junit.Assert.assertSame;
23 -
24 -/**
25 - * Test of the test scenario entity.
26 - */
27 -public class GroupTest extends StepTest {
28 -
29 - @Test
30 - public void basics() {
31 - Group group = new Group(NAME, CMD, ENV, CWD, parent, 1);
32 - assertEquals("incorrect name", NAME, group.name());
33 - assertEquals("incorrect command", CMD, group.command());
34 - assertEquals("incorrect env", ENV, group.env());
35 - assertEquals("incorrect cwd", CWD, group.cwd());
36 - assertSame("incorrect group", parent, group.group());
37 - assertEquals("incorrect delay", 1, group.delay());
38 -
39 - Step step = new Step("step", null, null, null, group, 0);
40 - group.addChild(step);
41 - assertSame("incorrect child", step, group.children().iterator().next());
42 - }
43 -
44 - @Test
45 - public void equality() {
46 - Group g1 = new Group(NAME, CMD, null, null, parent, 0);
47 - Group g2 = new Group(NAME, CMD, ENV, CWD, null, 0);
48 - Group g3 = new Group("foo", null, null, null, parent, 0);
49 - new EqualsTester()
50 - .addEqualityGroup(g1, g2)
51 - .addEqualityGroup(g3)
52 - .testEquals();
53 - }
54 -
55 -}
...\ No newline at end of file ...\ No newline at end of file
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.stc;
17 -
18 -import org.junit.AfterClass;
19 -import org.junit.BeforeClass;
20 -import org.junit.Test;
21 -import org.onlab.stc.MonitorLayout.Box;
22 -
23 -import java.io.IOException;
24 -
25 -import static org.junit.Assert.assertEquals;
26 -import static org.onlab.stc.CompilerTest.getStream;
27 -import static org.onlab.stc.CompilerTest.stageTestResource;
28 -import static org.onlab.stc.MonitorLayout.SLOT_WIDTH;
29 -import static org.onlab.stc.Scenario.loadScenario;
30 -
31 -/**
32 - * Tests of the monitor layout functionality.
33 - */
34 -public class MonitorLayoutTest {
35 -
36 - private MonitorLayout layout;
37 -
38 - @BeforeClass
39 - public static void setUpClass() throws IOException {
40 - CompilerTest.setUpClass();
41 - }
42 -
43 - @AfterClass
44 - public static void tearDownClass() throws IOException {
45 - CompilerTest.tearDownClass();
46 - }
47 -
48 - private Compiler getCompiler(String name) throws IOException {
49 - stageTestResource(name);
50 - Scenario scenario = loadScenario(getStream(name));
51 - Compiler compiler = new Compiler(scenario);
52 - compiler.compile();
53 - return compiler;
54 - }
55 -
56 - @Test
57 - public void basic() throws IOException {
58 - layout = new MonitorLayout(getCompiler("layout-basic.xml"));
59 - validate(layout, null, 0, 1, 5, 2);
60 - validate(layout, "a", 1, 1, 1, 1, 1, -SLOT_WIDTH / 2);
61 - validate(layout, "b", 2, 2, 1, 1, 0, 0);
62 - validate(layout, "f", 3, 3, 1);
63 -
64 - validate(layout, "g", 1, 1, 4, 1, 1, SLOT_WIDTH / 2);
65 - validate(layout, "c", 2, 1, 1);
66 - validate(layout, "d", 3, 2, 1);
67 - validate(layout, "e", 4, 3, 1);
68 - }
69 -
70 - @Test
71 - public void basicNest() throws IOException {
72 - layout = new MonitorLayout(getCompiler("layout-basic-nest.xml"));
73 - validate(layout, null, 0, 1, 6, 2);
74 - validate(layout, "a", 1, 1, 1, 1, 1, -SLOT_WIDTH / 2);
75 - validate(layout, "b", 2, 2, 1);
76 - validate(layout, "f", 3, 3, 1);
77 -
78 - validate(layout, "g", 1, 1, 5, 1);
79 - validate(layout, "c", 2, 1, 1);
80 -
81 - validate(layout, "gg", 3, 2, 3, 1);
82 - validate(layout, "d", 4, 1, 1);
83 - validate(layout, "e", 5, 2, 1);
84 - }
85 -
86 - @Test
87 - public void staggeredDependencies() throws IOException {
88 - layout = new MonitorLayout(getCompiler("layout-staggered-dependencies.xml"));
89 - validate(layout, null, 0, 1, 7, 4);
90 - validate(layout, "a", 1, 1, 1, 1, 1, -SLOT_WIDTH - SLOT_WIDTH / 2);
91 - validate(layout, "aa", 1, 1, 1, 1, 1, -SLOT_WIDTH / 2);
92 - validate(layout, "b", 2, 2, 1);
93 - validate(layout, "f", 3, 3, 1);
94 -
95 - validate(layout, "g", 1, 1, 5, 2, 1, +SLOT_WIDTH / 2);
96 - validate(layout, "c", 2, 1, 1);
97 -
98 - validate(layout, "gg", 3, 2, 3, 2);
99 - validate(layout, "d", 4, 1, 1);
100 - validate(layout, "dd", 4, 1, 1);
101 - validate(layout, "e", 5, 2, 1);
102 -
103 - validate(layout, "i", 6, 6, 1);
104 - }
105 -
106 - @Test
107 - public void deepNext() throws IOException {
108 - layout = new MonitorLayout(getCompiler("layout-deep-nest.xml"));
109 - validate(layout, null, 0, 1, 7, 6);
110 - validate(layout, "a", 1, 1, 1);
111 - validate(layout, "aa", 1, 1, 1);
112 - validate(layout, "b", 2, 2, 1);
113 - validate(layout, "f", 3, 3, 1);
114 -
115 - validate(layout, "g", 1, 1, 5, 2);
116 - validate(layout, "c", 2, 1, 1);
117 -
118 - validate(layout, "gg", 3, 2, 3, 2);
119 - validate(layout, "d", 4, 1, 1);
120 - validate(layout, "dd", 4, 1, 1);
121 - validate(layout, "e", 5, 2, 1);
122 -
123 - validate(layout, "i", 6, 6, 1);
124 -
125 - validate(layout, "g1", 1, 1, 6, 2);
126 - validate(layout, "g2", 2, 1, 5, 2);
127 - validate(layout, "g3", 3, 1, 4, 2);
128 - validate(layout, "u", 4, 1, 1);
129 - validate(layout, "v", 4, 1, 1);
130 - validate(layout, "w", 5, 2, 1);
131 - validate(layout, "z", 6, 3, 1);
132 - }
133 -
134 -
135 - private void validate(MonitorLayout layout, String name,
136 - int absoluteTier, int tier, int depth, int breadth) {
137 - Box b = layout.get(name);
138 - assertEquals("incorrect absolute tier", absoluteTier, b.absoluteTier());
139 - assertEquals("incorrect tier", tier, b.tier());
140 - assertEquals("incorrect depth", depth, b.depth());
141 - assertEquals("incorrect breadth", breadth, b.breadth());
142 - }
143 -
144 - private void validate(MonitorLayout layout, String name,
145 - int absoluteTier, int tier, int depth, int breadth,
146 - int top, int center) {
147 - validate(layout, name, absoluteTier, tier, depth, breadth);
148 - Box b = layout.get(name);
149 - assertEquals("incorrect top", top, b.top());
150 - assertEquals("incorrect center", center, b.center());
151 - }
152 -
153 - private void validate(MonitorLayout layout, String name,
154 - int absoluteTier, int tier, int depth) {
155 - validate(layout, name, absoluteTier, tier, depth, 1);
156 - }
157 -
158 -}
...\ No newline at end of file ...\ No newline at end of file
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.stc;
17 -
18 -import org.apache.commons.configuration.ConfigurationException;
19 -import org.junit.Test;
20 -
21 -import static org.junit.Assert.assertEquals;
22 -import static org.onlab.stc.Scenario.loadScenario;
23 -
24 -/**
25 - * Test of the test scenario entity.
26 - */
27 -public class ScenarioTest {
28 -
29 - @Test
30 - public void basics() throws ConfigurationException {
31 - Scenario scenario = loadScenario(getClass().getResourceAsStream("scenario.xml"));
32 - assertEquals("incorrect name", "foo", scenario.name());
33 - assertEquals("incorrect description", "Test Scenario", scenario.description());
34 - assertEquals("incorrect logDir", "Test Scenario", scenario.description());
35 - assertEquals("incorrect definition", "Test Scenario",
36 - scenario.definition().getString("[@description]"));
37 - }
38 -
39 - @Test(expected = IllegalArgumentException.class)
40 - public void badStream() throws ConfigurationException {
41 - loadScenario(getClass().getResourceAsStream("no.xml"));
42 - }
43 -
44 -}
...\ No newline at end of file ...\ No newline at end of file
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.stc;
17 -
18 -import org.junit.BeforeClass;
19 -import org.junit.ClassRule;
20 -import org.junit.Test;
21 -import org.junit.rules.TemporaryFolder;
22 -import java.io.File;
23 -import static com.google.common.base.Preconditions.checkState;
24 -import static org.junit.Assert.assertEquals;
25 -import static org.junit.Assert.assertTrue;
26 -import static org.onlab.stc.Coordinator.Status.SUCCEEDED;
27 -
28 -/**
29 - * Test of the step processor.
30 - */
31 -public class StepProcessorTest {
32 -
33 - @ClassRule
34 - public static TemporaryFolder testFolder = new TemporaryFolder();
35 -
36 - private static File dir;
37 - private final Listener delegate = new Listener();
38 -
39 - @BeforeClass
40 - public static void setUpClass() {
41 - dir = testFolder.getRoot();
42 - StepProcessor.launcher = "echo";
43 - checkState(dir.exists() || dir.mkdirs(), "Unable to create directory");
44 - }
45 -
46 - @Test
47 - public void basics() {
48 - Step step = new Step("foo", "ls " + dir.getAbsolutePath(), null, null, null, 0);
49 - StepProcessor processor = new StepProcessor(step, dir, delegate, step.command());
50 - processor.run();
51 - assertTrue("should be started", delegate.started);
52 - assertTrue("should be stopped", delegate.stopped);
53 - assertEquals("incorrect status", SUCCEEDED, delegate.status);
54 - assertTrue("should have output", delegate.output);
55 - }
56 -
57 - private class Listener implements StepProcessListener {
58 -
59 - private Coordinator.Status status;
60 - private boolean started, stopped, output;
61 -
62 - @Override
63 - public void onStart(Step step, String command) {
64 - started = true;
65 - }
66 -
67 - @Override
68 - public void onCompletion(Step step, Coordinator.Status status) {
69 - stopped = true;
70 - this.status = status;
71 - }
72 -
73 - @Override
74 - public void onOutput(Step step, String line) {
75 - output = true;
76 - }
77 - }
78 -
79 -}
...\ No newline at end of file ...\ No newline at end of file
1 -/*
2 - * Copyright 2015-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onlab.stc;
17 -
18 -import com.google.common.testing.EqualsTester;
19 -import org.apache.commons.configuration.ConfigurationException;
20 -import org.junit.Before;
21 -import org.junit.Test;
22 -
23 -import static org.junit.Assert.assertEquals;
24 -import static org.junit.Assert.assertSame;
25 -
26 -/**
27 - * Test of the test step entity.
28 - */
29 -public class StepTest {
30 -
31 - protected static final String NAME = "step";
32 - protected static final String CMD = "command";
33 - protected static final String ENV = "environment";
34 - protected static final String CWD = "directory";
35 - protected Group parent;
36 -
37 - @Before
38 - public void setUp() throws ConfigurationException {
39 - parent = new Group("parent", null, null, null, null, 0);
40 - }
41 -
42 - @Test
43 - public void basics() {
44 - Step step = new Step(NAME, CMD, ENV, CWD, parent, 1);
45 - assertEquals("incorrect name", NAME, step.name());
46 - assertEquals("incorrect command", CMD, step.command());
47 - assertEquals("incorrect env", ENV, step.env());
48 - assertEquals("incorrect cwd", CWD, step.cwd());
49 - assertSame("incorrect group", parent, step.group());
50 - assertEquals("incorrect delay", 1, step.delay());
51 - }
52 -
53 - @Test
54 - public void equality() {
55 - Step s1 = new Step(NAME, CMD, null, null, parent, 0);
56 - Step s2 = new Step(NAME, CMD, ENV, CWD, null, 0);
57 - Step s3 = new Step("foo", null, null, null, parent, 0);
58 - new EqualsTester()
59 - .addEqualityGroup(s1, s2)
60 - .addEqualityGroup(s3)
61 - .testEquals();
62 - }
63 -}
...\ No newline at end of file ...\ No newline at end of file
1 -<!--
2 - ~ Copyright 2015-present Open Networking Laboratory
3 - ~
4 - ~ Licensed under the Apache License, Version 2.0 (the "License");
5 - ~ you may not use this file except in compliance with the License.
6 - ~ You may obtain a copy of the License at
7 - ~
8 - ~ http://www.apache.org/licenses/LICENSE-2.0
9 - ~
10 - ~ Unless required by applicable law or agreed to in writing, software
11 - ~ distributed under the License is distributed on an "AS IS" BASIS,
12 - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - ~ See the License for the specific language governing permissions and
14 - ~ limitations under the License.
15 - -->
16 -<scenario name="basic-nest">
17 - <step name="a"/>
18 - <step name="b" requires="a"/>
19 - <step name="f" requires="b"/>
20 - <group name="g">
21 - <step name="c"/>
22 - <group name="gg" requires="c">
23 - <step name="d"/>
24 - <step name="e" requires="d"/>
25 - </group>
26 - </group>
27 -</scenario>
...\ No newline at end of file ...\ No newline at end of file
1 -<!--
2 - ~ Copyright 2015-present Open Networking Laboratory
3 - ~
4 - ~ Licensed under the Apache License, Version 2.0 (the "License");
5 - ~ you may not use this file except in compliance with the License.
6 - ~ You may obtain a copy of the License at
7 - ~
8 - ~ http://www.apache.org/licenses/LICENSE-2.0
9 - ~
10 - ~ Unless required by applicable law or agreed to in writing, software
11 - ~ distributed under the License is distributed on an "AS IS" BASIS,
12 - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - ~ See the License for the specific language governing permissions and
14 - ~ limitations under the License.
15 - -->
16 -<scenario name="basic">
17 - <step name="a"/>
18 - <step name="b" requires="a"/>
19 - <step name="f" requires="b"/>
20 - <group name="g">
21 - <step name="c"/>
22 - <step name="d" requires="c"/>
23 - <step name="e" requires="d"/>
24 - </group>
25 -</scenario>
...\ No newline at end of file ...\ No newline at end of file
1 -<!--
2 - ~ Copyright 2015-present Open Networking Laboratory
3 - ~
4 - ~ Licensed under the Apache License, Version 2.0 (the "License");
5 - ~ you may not use this file except in compliance with the License.
6 - ~ You may obtain a copy of the License at
7 - ~
8 - ~ http://www.apache.org/licenses/LICENSE-2.0
9 - ~
10 - ~ Unless required by applicable law or agreed to in writing, software
11 - ~ distributed under the License is distributed on an "AS IS" BASIS,
12 - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - ~ See the License for the specific language governing permissions and
14 - ~ limitations under the License.
15 - -->
16 -<scenario name="basic-nest">
17 - <step name="a"/>
18 - <step name="aa"/>
19 - <step name="b" requires="a"/>
20 - <step name="f" requires="b,aa"/>
21 - <group name="g">
22 - <step name="c"/>
23 - <group name="gg" requires="c">
24 - <step name="d"/>
25 - <step name="dd" requires="c"/>
26 - <step name="e" requires="d"/>
27 - </group>
28 - </group>
29 - <step name="i" requires="f,g"/>
30 -
31 - <group name="g1">
32 - <group name="g2">
33 - <group name="g3">
34 - <step name="u"/>
35 - <step name="v"/>
36 - <step name="w" requires="u,v"/>
37 - <step name="z" requires="u,w"/>
38 - </group>
39 - </group>
40 - </group>
41 -</scenario>
...\ No newline at end of file ...\ No newline at end of file
1 -<!--
2 - ~ Copyright 2015-present Open Networking Laboratory
3 - ~
4 - ~ Licensed under the Apache License, Version 2.0 (the "License");
5 - ~ you may not use this file except in compliance with the License.
6 - ~ You may obtain a copy of the License at
7 - ~
8 - ~ http://www.apache.org/licenses/LICENSE-2.0
9 - ~
10 - ~ Unless required by applicable law or agreed to in writing, software
11 - ~ distributed under the License is distributed on an "AS IS" BASIS,
12 - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - ~ See the License for the specific language governing permissions and
14 - ~ limitations under the License.
15 - -->
16 -<scenario name="basic-nest">
17 - <step name="a"/>
18 - <step name="aa"/>
19 - <step name="b" requires="a"/>
20 - <step name="f" requires="b,aa"/>
21 - <group name="g">
22 - <step name="c"/>
23 - <group name="gg" requires="c">
24 - <step name="d"/>
25 - <step name="dd" requires="c"/>
26 - <step name="e" requires="d"/>
27 - </group>
28 - </group>
29 - <step name="i" requires="f,g"/>
30 -</scenario>
...\ No newline at end of file ...\ No newline at end of file
1 -<!--
2 - ~ Copyright 2015-present Open Networking Laboratory
3 - ~
4 - ~ Licensed under the Apache License, Version 2.0 (the "License");
5 - ~ you may not use this file except in compliance with the License.
6 - ~ You may obtain a copy of the License at
7 - ~
8 - ~ http://www.apache.org/licenses/LICENSE-2.0
9 - ~
10 - ~ Unless required by applicable law or agreed to in writing, software
11 - ~ distributed under the License is distributed on an "AS IS" BASIS,
12 - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - ~ See the License for the specific language governing permissions and
14 - ~ limitations under the License.
15 - -->
16 -
17 -<scenario name="one" description="" logDir="${test.dir}/junit-stc/one">
18 - <step name="yolo" exec="some-command args"/>
19 - <step name="hello" exec="some-command other args" requires="yolo"/>
20 -</scenario>
...\ No newline at end of file ...\ No newline at end of file
1 -<!--
2 - ~ Copyright 2015-present Open Networking Laboratory
3 - ~
4 - ~ Licensed under the Apache License, Version 2.0 (the "License");
5 - ~ you may not use this file except in compliance with the License.
6 - ~ You may obtain a copy of the License at
7 - ~
8 - ~ http://www.apache.org/licenses/LICENSE-2.0
9 - ~
10 - ~ Unless required by applicable law or agreed to in writing, software
11 - ~ distributed under the License is distributed on an "AS IS" BASIS,
12 - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - ~ See the License for the specific language governing permissions and
14 - ~ limitations under the License.
15 - -->
16 -<scenario name="foo" description="Test Scenario" logDir="${test.dir}/foo">
17 - <import file="${test.dir}/one-scenario.xml" namespace="foo"/>
18 -
19 - <import file="${test.dir}/two-scenario.xml"/>
20 -
21 - <dependency name="dude" requires="~yolo"/>
22 -
23 - <step name="yo" exec="some-command ${HOME} and ${prop.foo} args" if="${prop.foo}"/>
24 - <step name="hi" exec="some-command ${prop.bar} or ${HOME} other args"/>
25 - <step name="there" exec="another-command" requires="yo,hi"/>
26 -
27 - <step name="maybe" exec="another-command" requires="~hi" unless="${prop.foo}"/>
28 -
29 - <group name="alpha" exec="same-command args" requires="yo">
30 - <step name="one" exec="asdads"/>
31 - <step name="two" exec="asdads"/>
32 - <group name="three" exec="asdads" requires="one,two">
33 - <step name="three.a"/>
34 - <step name="three.b" requires="three.a"/>
35 - <step name="three.c" requires="three.b"/>
36 - </group>
37 - </group>
38 -
39 - <dependency name="maybe" requires="yo"/>
40 -
41 - <parallel var="${TOC#}" requires="alpha">
42 - <step name="ping-${#}" exec="asdads ${TOC#}"/>
43 - <step name="pong-${#}" exec="asdads"/>
44 - <step name="ding-${#}" exec="asdads" requires="ping-${#},pong-${#}"/>
45 - <dependency name="maybe" requires="ding-${#}"/>
46 - </parallel>
47 -
48 - <sequential var="${TOC#}" requires="alpha" starts="fifi-${#},gigi-${#}" ends="gaga-${#-1}">
49 - <step name="fifi-${#}" exec="asdads ${TOC#}"/>
50 - <step name="gigi-${#}" exec="asdads"/>
51 - <step name="gaga-${#}" exec="asdads" requires="fifi-${#},gigi-${#}"/>
52 - <dependency name="maybe" requires="gaga-${#}"/>
53 - </sequential>
54 -</scenario>
...\ No newline at end of file ...\ No newline at end of file
1 -<!--
2 - ~ Copyright 2015-present Open Networking Laboratory
3 - ~
4 - ~ Licensed under the Apache License, Version 2.0 (the "License");
5 - ~ you may not use this file except in compliance with the License.
6 - ~ You may obtain a copy of the License at
7 - ~
8 - ~ http://www.apache.org/licenses/LICENSE-2.0
9 - ~
10 - ~ Unless required by applicable law or agreed to in writing, software
11 - ~ distributed under the License is distributed on an "AS IS" BASIS,
12 - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - ~ See the License for the specific language governing permissions and
14 - ~ limitations under the License.
15 - -->
16 -<scenario name="foo" description="Simple Test Scenario" logDir="${test.dir}/junit-stc/foo">
17 - <group name="alpha" exec="same-command args">
18 - <step name="one" exec="asdads"/>
19 - <step name="two" exec="asdads"/>
20 - <group name="three" exec="asdads" requires="one,two">
21 - <step name="three.a"/>
22 - <step name="three.b" requires="three.a"/>
23 - <step name="three.c" requires="three.b"/>
24 - </group>
25 - </group>
26 -</scenario>
...\ No newline at end of file ...\ No newline at end of file
1 -<!--
2 - ~ Copyright 2015-present Open Networking Laboratory
3 - ~
4 - ~ Licensed under the Apache License, Version 2.0 (the "License");
5 - ~ you may not use this file except in compliance with the License.
6 - ~ You may obtain a copy of the License at
7 - ~
8 - ~ http://www.apache.org/licenses/LICENSE-2.0
9 - ~
10 - ~ Unless required by applicable law or agreed to in writing, software
11 - ~ distributed under the License is distributed on an "AS IS" BASIS,
12 - ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - ~ See the License for the specific language governing permissions and
14 - ~ limitations under the License.
15 - -->
16 -
17 -<scenario name="two" description="" logDir="${test.dir}/junit-stc/two">
18 - <step name="dude" exec="some-command args"/>
19 - <step name="waz" exec="some-command other args"/>
20 - <step name="up" exec="another-command" requires="dude,waz"/>
21 -</scenario>
...\ No newline at end of file ...\ No newline at end of file