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.
/*
* Copyright (c) 2014 Spotify AB.
*
* 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 com.spotify.helios.agent;
import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.common.util.concurrent.AbstractIdleService;
import com.spotify.helios.common.descriptors.Goal;
import com.spotify.helios.common.descriptors.Job;
import com.spotify.helios.common.descriptors.JobId;
import com.spotify.helios.common.descriptors.Task;
import com.spotify.helios.common.descriptors.TaskStatus;
import com.spotify.helios.servicescommon.PersistentAtomicReference;
import com.spotify.helios.servicescommon.Reactor;
import com.spotify.helios.servicescommon.ReactorFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Predicates.in;
import static com.google.common.base.Predicates.not;
import static com.spotify.helios.common.descriptors.Goal.START;
import static com.spotify.helios.common.descriptors.Goal.UNDEPLOY;
import static com.spotify.helios.servicescommon.Reactor.Callback;
import static java.util.concurrent.TimeUnit.SECONDS;
/**
* Runs jobs to implement the desired container deployment state.
*/
public class Agent extends AbstractIdleService {
public static final Map EMPTY_EXECUTIONS = Collections.emptyMap();
private static final Logger log = LoggerFactory.getLogger(Agent.class);
private static final long UPDATE_INTERVAL = SECONDS.toMillis(30);
private static final Predicate PORT_ALLOCATION_PENDING = new Predicate() {
@Override
public boolean apply(final Execution execution) {
assert execution != null;
return execution.getGoal() != UNDEPLOY && execution.getPorts() == null;
}
};
private static final Predicate PORTS_ALLOCATED = new Predicate() {
@Override
public boolean apply(final Execution execution) {
assert execution != null;
return execution.getPorts() != null;
}
};
private final AgentModel model;
private final SupervisorFactory supervisorFactory;
private final ModelListener modelListener = new ModelListener();
private final Supervisor.Listener supervisorListener = new SupervisorListener();
private final Map supervisors = Maps.newHashMap();
private final Reactor reactor;
private final PersistentAtomicReference