All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.spotify.helios.rollingupdate.DeploymentGroupEventFactory Maven / Gradle / Ivy

There is a newer version: 0.9.9
Show newest version
/*
 * Copyright (c) 2015 Spotify AB.
 *
 * Licensed 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.rollingupdate;

import com.google.common.collect.Maps;

import com.spotify.helios.common.descriptors.DeploymentGroup;
import com.spotify.helios.common.descriptors.RolloutTask;

import java.util.Collections;
import java.util.Map;

public class DeploymentGroupEventFactory {

  private Map createEvent(final String eventType,
                                          final DeploymentGroup deploymentGroup) {
    final Map ev = Maps.newHashMap();
    ev.put("eventType", eventType);
    ev.put("timestamp", System.currentTimeMillis());
    ev.put("deploymentGroup", deploymentGroup);
    return ev;
  }

  private Map addTaskFields(final Map ev,
                                            final RolloutTask task) {
    ev.put("action", task.getAction());
    ev.put("target", task.getTarget());
    return ev;
  }

  public Map rollingUpdateTaskFailed(final DeploymentGroup deploymentGroup,
                                                     final RolloutTask task,
                                                     final String error,
                                                     final RollingUpdateError errorCode) {
    return rollingUpdateTaskFailed(deploymentGroup, task, error, errorCode,
                                   Collections.emptyMap());
  }

  public Map rollingUpdateTaskFailed(final DeploymentGroup deploymentGroup,
                                                     final RolloutTask task,
                                                     final String error,
                                                     final RollingUpdateError errorCode,
                                                     final Map metadata) {
    final Map ev = createEvent("rollingUpdateTaskResult", deploymentGroup);
    ev.putAll(metadata);
    ev.put("success", 0);
    ev.put("error", error);
    ev.put("errorCode", errorCode);
    return addTaskFields(ev, task);
  }

  public Map rollingUpdateTaskSucceeded(final DeploymentGroup deploymentGroup,
                                                        final RolloutTask task) {
    final Map ev = createEvent("rollingUpdateTaskResult", deploymentGroup);
    ev.put("success", 1);
    return addTaskFields(ev, task);
  }

  public Map rollingUpdateStarted(final DeploymentGroup deploymentGroup) {
    final Map ev = createEvent("rollingUpdateStarted", deploymentGroup);
    ev.put("reason", deploymentGroup.getRollingUpdateReason());
    return ev;
  }

  public Map rollingUpdateDone(final DeploymentGroup deploymentGroup) {
    final Map ev = createEvent("rollingUpdateFinished", deploymentGroup);
    ev.put("success", 1);
    return ev;
  }

  public Map rollingUpdateFailed(final DeploymentGroup deploymentGroup,
                                                 final Map failEvent) {
    final Map ev = createEvent("rollingUpdateFinished", deploymentGroup);
    ev.put("success", 0);
    ev.put("failedTask", failEvent);
    return ev;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy