Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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.brooklyn.policy.ha;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.apache.brooklyn.api.catalog.Catalog;
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.entity.EntityLocal;
import org.apache.brooklyn.api.entity.Group;
import org.apache.brooklyn.api.mgmt.Task;
import org.apache.brooklyn.api.sensor.Sensor;
import org.apache.brooklyn.api.sensor.SensorEvent;
import org.apache.brooklyn.api.sensor.SensorEventListener;
import org.apache.brooklyn.config.ConfigKey;
import org.apache.brooklyn.core.config.BasicConfigKey;
import org.apache.brooklyn.core.config.ConfigKeys;
import org.apache.brooklyn.core.entity.Entities;
import org.apache.brooklyn.core.entity.EntityInternal;
import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic.ServiceProblemsLogic;
import org.apache.brooklyn.core.entity.trait.MemberReplaceable;
import org.apache.brooklyn.core.policy.AbstractPolicy;
import org.apache.brooklyn.core.sensor.BasicNotificationSensor;
import org.apache.brooklyn.entity.group.StopFailedRuntimeException;
import org.apache.brooklyn.policy.ha.HASensors.FailureDescriptor;
import org.apache.brooklyn.util.collections.MutableMap;
import org.apache.brooklyn.util.core.flags.SetFromFlag;
import org.apache.brooklyn.util.exceptions.Exceptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Ticker;
import com.google.common.collect.Lists;
/** attaches to a DynamicCluster and replaces a failed member in response to HASensors.ENTITY_FAILED or other sensor;
* if this fails, it sets the Cluster state to on-fire */
@Catalog(name="Service Replacer", description="HA policy for replacing a failed member of a group")
public class ServiceReplacer extends AbstractPolicy {
private static final Logger LOG = LoggerFactory.getLogger(ServiceReplacer.class);
// TODO if there are multiple failures perhaps we should abort quickly
public static final BasicNotificationSensor ENTITY_REPLACEMENT_FAILED = new BasicNotificationSensor(
FailureDescriptor.class,
"ha.entityFailed.replacement",
"Indicates that an entity replacement attempt has failed");
@SetFromFlag("setOnFireOnFailure")
public static final ConfigKey SET_ON_FIRE_ON_FAILURE = ConfigKeys.newBooleanConfigKey(
"setOnFireOnFailure",
"Whether to set the entity as 'ON_FIRE' when failure is detected",
true);
/** monitors this sensor, by default ENTITY_RESTART_FAILED */
@SetFromFlag("failureSensorToMonitor")
@SuppressWarnings("rawtypes")
public static final ConfigKey FAILURE_SENSOR_TO_MONITOR = new BasicConfigKey(
Sensor.class,
"failureSensorToMonitor",
"The sensor, emitted by an entity, used to trigger its replacement. Defaults to 'ha.entityFailed.restart' "
+ "(i.e. a 'ServiceRestarter' policy tried and failed to restart the entity)",
ServiceRestarter.ENTITY_RESTART_FAILED);
/** skips replace if replacement has failed this many times failure re-occurs within this time interval */
@SetFromFlag("failOnRecurringFailuresInThisDuration")
public static final ConfigKey FAIL_ON_RECURRING_FAILURES_IN_THIS_DURATION = ConfigKeys.newLongConfigKey(
"failOnRecurringFailuresInThisDuration",
"Abandon replace if replacement has failed many times within this time interval",
5*60*1000L);
/** skips replace if replacement has failed this many times failure re-occurs within this time interval */
@SetFromFlag("failOnNumRecurringFailures")
public static final ConfigKey FAIL_ON_NUM_RECURRING_FAILURES = ConfigKeys.newIntegerConfigKey(
"failOnNumRecurringFailures",
"Abandon replace if replacement has failed this many times (100% of attempts) within the time interval",
5);
@SetFromFlag("ticker")
public static final ConfigKey TICKER = ConfigKeys.newConfigKey(Ticker.class,
"ticker",
"A time source (defaults to system-clock, which is almost certainly what's wanted, except in tests)",
null);
protected final List consecutiveReplacementFailureTimes = Lists.newCopyOnWriteArrayList();
public ServiceReplacer() {
}
@Override
public void setEntity(final EntityLocal entity) {
checkArgument(entity instanceof MemberReplaceable, "ServiceReplacer must take a MemberReplaceable, not %s", entity);
Sensor> failureSensorToMonitor = checkNotNull(getConfig(FAILURE_SENSOR_TO_MONITOR), "failureSensorToMonitor");
super.setEntity(entity);
subscriptions().subscribeToMembers((Group)entity, failureSensorToMonitor, new SensorEventListener