Fixed netconf monitoring.
[controller.git] / opendaylight / commons / controller-maven-plugin / src / main / java / org / opendaylight / controller / maven / plugin / StopControllerMojo.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.controller.maven.plugin;
10
11 import java.util.ArrayList;
12 import java.util.List;
13
14 import org.apache.maven.plugin.MojoExecutionException;
15 import org.apache.maven.plugin.MojoFailureException;
16 import org.apache.maven.plugins.annotations.LifecyclePhase;
17 import org.apache.maven.plugins.annotations.Mojo;
18
19 /**
20  * Stop controller
21  */
22 @Mojo( name = "stop", defaultPhase = LifecyclePhase.POST_INTEGRATION_TEST )
23 public class StopControllerMojo extends AbstractControllerMojo {
24     private static final boolean SKIP_STOP = Boolean.getBoolean("skipControllerStop");
25
26     @Override
27     public void start() throws MojoExecutionException, MojoFailureException {
28         if (SKIP_STOP) {
29             getLog().info("Controller STOP is skipped per configuration " +
30                     "(-DskipControllerStop=true).");
31             return;
32         }
33         if (canConnect()) {
34             List<String> args = new ArrayList<String>();
35             args.add("-stop");
36             Process proc = invokeScript(args, null);
37             try {
38                 int status = proc.waitFor();
39                 if (status == 0) {
40                     getLog().info("Controller stopped.");
41                 } else {
42                     getLog().error("Error stopping controller. See stdout log for details.");
43                 }
44             } catch (InterruptedException ie) {
45                 throw new MojoExecutionException("Error stopping controller : " + ie.getMessage());
46             }
47         } else {
48             getLog().info("Controller not running.");
49         }
50         // cleanup for any hung processes
51         killControllers();
52     }
53
54 }