From 40b398553ff4e00b68548e219aa58c3a8fec2232 Mon Sep 17 00:00:00 2001 From: Mikhail Antonov Date: Mon, 3 Feb 2014 15:19:21 -0800 Subject: BIGTOP-1192. Add utilities to facilitate cluster failure testing into bigtop-test-framework --- .../itest/failures/ServiceKilledFailure.groovy | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/failures/ServiceKilledFailure.groovy (limited to 'bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/failures/ServiceKilledFailure.groovy') diff --git a/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/failures/ServiceKilledFailure.groovy b/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/failures/ServiceKilledFailure.groovy new file mode 100644 index 00000000..413f1713 --- /dev/null +++ b/bigtop-test-framework/src/main/groovy/org/apache/bigtop/itest/failures/ServiceKilledFailure.groovy @@ -0,0 +1,69 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.bigtop.itest.failures + +/** + * Can kill (with kill -9) specified service on specified hosts during tests run. + */ +public class ServiceKilledFailure extends AbstractFailure { + + private static final String KILL_SERVICE_TEMPLATE = "sudo pkill -9 -f %s" + private static final String START_SERVICE_TEMPLATE = "sudo service %s start" + + /** + * Can kill specified service on specified hosts during tests run. + * + * @param hosts list of hosts on which specified service will be killed + * @param serviceName name of service to be killed. + */ + public ServiceKilledFailure(List hosts, String serviceName) { + super(hosts) + populateCommandsList(hosts, serviceName) + } + + /** + * Can kill specified service on specified hosts during tests run. + * + * @param hosts list of hosts on which specified service will be killed + * @param serviceName name of service to be killed + * @param startDelay time in milliseconds) the failures will wait before start + */ + public ServiceKilledFailure(List hosts, + String serviceName, + long startDelay) { + + super(hosts, startDelay) + populateCommandsList(hosts, serviceName) + } + + /* + * Populate commands list, making choice between local execution and remote one. + */ + private void populateCommandsList(List hosts, String serviceName){ + if (hosts.size() == 1 && "localhost".equalsIgnoreCase(hosts[0])) { + failCommands.add(String.format(KILL_SERVICE_TEMPLATE, serviceName)) + restoreCommands.add(String.format(START_SERVICE_TEMPLATE, serviceName)) + } else { + hosts.each { host -> + failCommands.add(getSshWrappedCommand(String.format(KILL_SERVICE_TEMPLATE, serviceName), host)) + restoreCommands.add(getSshWrappedCommand(String.format(START_SERVICE_TEMPLATE, serviceName), host)) + } + } + } +} -- cgit v1.2.3