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.entity.software.base;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import org.apache.brooklyn.api.entity.Entity;
import org.apache.brooklyn.api.entity.EntityLocal;
import org.apache.brooklyn.api.entity.drivers.DriverDependentEntity;
import org.apache.brooklyn.api.entity.drivers.EntityDriverManager;
import org.apache.brooklyn.api.location.Location;
import org.apache.brooklyn.api.location.MachineLocation;
import org.apache.brooklyn.api.location.MachineProvisioningLocation;
import org.apache.brooklyn.api.mgmt.Task;
import org.apache.brooklyn.api.sensor.EnricherSpec;
import org.apache.brooklyn.api.sensor.SensorEvent;
import org.apache.brooklyn.api.sensor.SensorEventListener;
import org.apache.brooklyn.core.enricher.AbstractEnricher;
import org.apache.brooklyn.core.entity.AbstractEntity;
import org.apache.brooklyn.core.entity.Attributes;
import org.apache.brooklyn.core.entity.BrooklynConfigKeys;
import org.apache.brooklyn.core.entity.Entities;
import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic;
import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic.ServiceNotUpLogic;
import org.apache.brooklyn.core.location.LocationConfigKeys;
import org.apache.brooklyn.core.location.cloud.CloudLocationConfig;
import org.apache.brooklyn.feed.function.FunctionFeed;
import org.apache.brooklyn.feed.function.FunctionPollConfig;
import org.apache.brooklyn.location.jclouds.networking.NetworkingEffectors;
import org.apache.brooklyn.location.ssh.SshMachineLocation;
import org.apache.brooklyn.util.collections.MutableMap;
import org.apache.brooklyn.util.collections.MutableSet;
import org.apache.brooklyn.util.core.config.ConfigBag;
import org.apache.brooklyn.util.core.task.BasicTask;
import org.apache.brooklyn.util.core.task.DynamicTasks;
import org.apache.brooklyn.util.core.task.ScheduledTask;
import org.apache.brooklyn.util.core.task.Tasks;
import org.apache.brooklyn.util.exceptions.Exceptions;
import org.apache.brooklyn.util.guava.Maybe;
import org.apache.brooklyn.util.time.CountdownTimer;
import org.apache.brooklyn.util.time.Duration;
import org.apache.brooklyn.util.time.Time;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.base.Functions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import groovy.time.TimeDuration;
/**
* An {@link Entity} representing a piece of software which can be installed, run, and controlled.
* A single such entity can only run on a single {@link MachineLocation} at a time (you can have multiple on the machine).
* It typically takes config keys for suggested versions, filesystem locations to use, and environment variables to set.
*
* It exposes sensors for service state (Lifecycle) and status (String), and for host info, log file location.
*/
public abstract class SoftwareProcessImpl extends AbstractEntity implements SoftwareProcess, DriverDependentEntity {
private static final Logger LOG = LoggerFactory.getLogger(SoftwareProcessImpl.class);
private transient SoftwareProcessDriver driver;
/** @see #connectServiceUpIsRunning() */
private transient FunctionFeed serviceProcessIsRunning;
protected boolean connectedSensors = false;
public SoftwareProcessImpl() {
super(MutableMap.of(), null);
}
public SoftwareProcessImpl(Entity parent) {
this(MutableMap.of(), parent);
}
public SoftwareProcessImpl(Map properties) {
this(properties, null);
}
public SoftwareProcessImpl(Map properties, Entity parent) {
super(properties, parent);
}
protected void setProvisioningLocation(MachineProvisioningLocation val) {
if (getAttribute(PROVISIONING_LOCATION) != null) throw new IllegalStateException("Cannot change provisioning location: existing="+getAttribute(PROVISIONING_LOCATION)+"; new="+val);
sensors().set(PROVISIONING_LOCATION, val);
}
protected MachineProvisioningLocation getProvisioningLocation() {
return getAttribute(PROVISIONING_LOCATION);
}
@Override
public SoftwareProcessDriver getDriver() {
return driver;
}
protected SoftwareProcessDriver newDriver(MachineLocation loc){
EntityDriverManager entityDriverManager = getManagementContext().getEntityDriverManager();
return (SoftwareProcessDriver)entityDriverManager.build(this, loc);
}
protected MachineLocation getMachineOrNull() {
return Iterables.get(Iterables.filter(getLocations(), MachineLocation.class), 0, null);
}
@Override
public void init() {
super.init();
getLifecycleEffectorTasks().attachLifecycleEffectors(this);
if (Boolean.TRUE.equals(getConfig(ADD_OPEN_INBOUND_PORTS_EFFECTOR))) {
getMutableEntityType().addEffector(NetworkingEffectors.OPEN_INBOUND_PORTS_IN_SECURITY_GROUP_EFFECTOR);
}
}
@Override
protected void initEnrichers() {
super.initEnrichers();
ServiceNotUpLogic.updateNotUpIndicator(this, SERVICE_PROCESS_IS_RUNNING, "No information yet on whether this service is running");
// add an indicator above so that if is_running comes through, the map is cleared and an update is guaranteed
enrichers().add(EnricherSpec.create(UpdatingNotUpFromServiceProcessIsRunning.class).uniqueTag("service-process-is-running-updating-not-up"));
enrichers().add(EnricherSpec.create(ServiceNotUpDiagnosticsCollector.class).uniqueTag("service-not-up-diagnostics-collector"));
}
/**
* @since 0.8.0
*/
protected static class ServiceNotUpDiagnosticsCollector extends AbstractEnricher implements SensorEventListener