001/*
002 * VM-Operator
003 * Copyright (C) 2024 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.V1Service;
022import org.jdrupes.vmoperator.common.K8sObserver.ResponseType;
023import org.jgrapes.core.Channel;
024import org.jgrapes.core.Components;
025import org.jgrapes.core.Event;
026
027/**
028 * Indicates that a service has changed. 
029 */
030@SuppressWarnings("PMD.DataClass")
031public class ServiceChanged extends Event<Void> {
032
033    private final ResponseType type;
034    private final V1Service service;
035
036    /**
037     * Initializes a new service changed event.
038     *
039     * @param type the type
040     * @param service the service
041     */
042    public ServiceChanged(ResponseType type, V1Service service) {
043        this.type = type;
044        this.service = service;
045    }
046
047    /**
048     * Returns the type.
049     *
050     * @return the type
051     */
052    public ResponseType type() {
053        return type;
054    }
055
056    /**
057     * Gets the service.
058     *
059     * @return the service
060     */
061    public V1Service service() {
062        return service;
063    }
064
065    @Override
066    public String toString() {
067        StringBuilder builder = new StringBuilder();
068        builder.append(Components.objectName(this)).append(" [")
069            .append(service.getMetadata().getName()).append(' ').append(type);
070        if (channels() != null) {
071            builder.append(", channels=").append(Channel.toString(channels()));
072        }
073        builder.append(']');
074        return builder.toString();
075    }
076}