001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.chaos.policies; 019 020import java.util.Properties; 021import org.apache.hadoop.hbase.IntegrationTestingUtility; 022import org.apache.hadoop.hbase.chaos.actions.Action; 023import org.apache.hadoop.hbase.util.StoppableImplementation; 024import org.slf4j.Logger; 025import org.slf4j.LoggerFactory; 026 027/** 028 * A policy to introduce chaos to the cluster 029 */ 030public abstract class Policy extends StoppableImplementation implements Runnable { 031 032 protected static final Logger LOG = LoggerFactory.getLogger(Policy.class); 033 034 protected PolicyContext context; 035 036 public void init(PolicyContext context) throws Exception { 037 this.context = context; 038 039 // Used to wire up stopping. 040 context.setPolicy(this); 041 } 042 043 /** 044 * A context for a Policy 045 */ 046 public static class PolicyContext extends Action.ActionContext { 047 048 Policy policy = null; 049 050 public PolicyContext(Properties monkeyProps, IntegrationTestingUtility util) { 051 super(monkeyProps, util); 052 } 053 054 @Override 055 public boolean isStopping() { 056 return policy.isStopped(); 057 } 058 059 public void setPolicy(Policy policy) { 060 this.policy = policy; 061 } 062 } 063}