001/*
002 * VM-Operator
003 * Copyright (C) 2023 Michael N. Lipp
004 * 
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Affero General Public License as
007 * published by the Free Software Foundation, either version 3 of the
008 * License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013 * GNU Affero General Public License for more details.
014 *
015 * You should have received a copy of the GNU Affero General Public License
016 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
017 */
018
019package org.jdrupes.vmoperator.manager.events;
020
021import io.kubernetes.client.openapi.models.V1Pod;
022import org.jdrupes.vmoperator.common.K8sObserver;
023import org.jgrapes.core.Channel;
024import org.jgrapes.core.Components;
025import org.jgrapes.core.Event;
026
027/**
028 * Indicates a change in a pod that runs a VM.
029 */
030public class PodChanged extends Event<Void> {
031
032    private final V1Pod pod;
033    private final K8sObserver.ResponseType type;
034
035    /**
036     * Instantiates a new VM changed event.
037     *
038     * @param pod the pod
039     * @param type the type
040     */
041    public PodChanged(V1Pod pod, K8sObserver.ResponseType type) {
042        this.pod = pod;
043        this.type = type;
044    }
045
046    /**
047     * Gets the pod.
048     *
049     * @return the pod
050     */
051    public V1Pod pod() {
052        return pod;
053    }
054
055    /**
056     * Returns the type.
057     *
058     * @return the type
059     */
060    public K8sObserver.ResponseType type() {
061        return type;
062    }
063
064    @Override
065    public String toString() {
066        StringBuilder builder = new StringBuilder();
067        builder.append(Components.objectName(this)).append(" [")
068            .append(pod.getMetadata().getName()).append(' ').append(type);
069        if (channels() != null) {
070            builder.append(", channels=").append(Channel.toString(channels()));
071        }
072        builder.append(']');
073        return builder.toString();
074    }
075}