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 org.jdrupes.vmoperator.common.K8sObserver; 022import org.jdrupes.vmoperator.common.VmDefinition; 023import org.jgrapes.core.Channel; 024import org.jgrapes.core.Components; 025import org.jgrapes.core.Event; 026 027/** 028 * Indicates a change in a VM definition. Note that the definition 029 * consists of the metadata (mostly immutable), the "spec" and the 030 * "status" parts. Consumers that are only interested in "spec" 031 * changes should check {@link #specChanged()} before processing 032 * the event any further. 033 */ 034@SuppressWarnings("PMD.DataClass") 035public class VmDefChanged extends Event<Void> { 036 037 private final K8sObserver.ResponseType type; 038 private final boolean specChanged; 039 private final VmDefinition vmDefinition; 040 041 /** 042 * Instantiates a new VM changed event. 043 * 044 * @param type the type 045 * @param specChanged the spec part changed 046 * @param vmDefinition the VM definition 047 */ 048 public VmDefChanged(K8sObserver.ResponseType type, boolean specChanged, 049 VmDefinition vmDefinition) { 050 this.type = type; 051 this.specChanged = specChanged; 052 this.vmDefinition = vmDefinition; 053 } 054 055 /** 056 * Returns the type. 057 * 058 * @return the type 059 */ 060 public K8sObserver.ResponseType type() { 061 return type; 062 } 063 064 /** 065 * Indicates if the "spec" part changed. 066 */ 067 public boolean specChanged() { 068 return specChanged; 069 } 070 071 /** 072 * Return the VM definition. 073 * 074 * @return the VM definition 075 */ 076 public VmDefinition vmDefinition() { 077 return vmDefinition; 078 } 079 080 @Override 081 public String toString() { 082 StringBuilder builder = new StringBuilder(); 083 builder.append(Components.objectName(this)).append(" [") 084 .append(vmDefinition.name()).append(' ').append(type); 085 if (channels() != null) { 086 builder.append(", channels=").append(Channel.toString(channels())); 087 } 088 builder.append(']'); 089 return builder.toString(); 090 } 091}