This is an automated email from the ASF dual-hosted git repository. heneveld pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/brooklyn-server.git
commit db8115b362254e1c4858fa65d7412ec9484e39aa Author: Alex Heneveld <[email protected]> AuthorDate: Fri Dec 3 19:19:06 2021 +0000 migrate removed guava EmptyImmutableBiMap --- .../camp/brooklyn/rebind/RebindMiscTest.java | 68 ++++++++ .../rebind/misc-guava-2021-12-entity-hrxo4j0dcs | 192 +++++++++++++++++++++ .../persist/deserializingClassRenames.properties | 1 + .../brooklyn/util/guava/EmptyImmutableBiMap.java | 133 ++++++++++++++ 4 files changed, 394 insertions(+) diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/rebind/RebindMiscTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/rebind/RebindMiscTest.java new file mode 100644 index 0000000..2a57109 --- /dev/null +++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/rebind/RebindMiscTest.java @@ -0,0 +1,68 @@ +/* + * 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 org.apache.brooklyn.camp.brooklyn.rebind; + +import com.google.common.collect.BiMap; +import com.google.common.io.Files; +import com.google.common.reflect.TypeToken; +import java.io.File; +import org.apache.brooklyn.api.entity.Entity; +import org.apache.brooklyn.api.sensor.Sensor; +import org.apache.brooklyn.camp.brooklyn.AbstractYamlRebindTest; +import org.apache.brooklyn.config.ConfigKey; +import org.apache.brooklyn.core.config.ConfigKeys; +import org.apache.brooklyn.core.sensor.Sensors; +import org.apache.brooklyn.core.sensor.StaticSensor; +import org.apache.brooklyn.entity.stock.BasicApplication; +import org.apache.brooklyn.util.os.Os; +import org.apache.brooklyn.util.stream.Streams; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import static org.testng.Assert.assertEquals; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class RebindMiscTest extends AbstractYamlRebindTest { + + // TODO What about testing DslBrooklynObjectConfigSupplier? + + @SuppressWarnings("unused") + private static final Logger log = LoggerFactory.getLogger(RebindMiscTest.class); + + // update of Guava removed BiMap class, we have to handle it ourselves + @Test + public void testGuavaEmptyBiMap_2021_12() throws Exception { + String entityId = "hrxo4j0dcs"; + doAddEntityMemento("guava-2021-12", entityId); + + rebind(); + Entity newEntity = mgmt().getEntityManager().getEntity(entityId); + + BiMap diags = newEntity.sensors().get(Sensors.newSensor(BiMap.class, "service.notUp.diagnostics")); + assertEquals(diags.size(), 0); + } + + protected void doAddEntityMemento(String label, String entityId) throws Exception { + String mementoResourceName = "misc-" + label + "-entity-" + entityId; + String memento = Streams.readFullyString(getClass().getResourceAsStream(mementoResourceName)); + + File persistedEntityFile = new File(mementoDir, Os.mergePaths("entities", entityId)); + Files.write(memento.getBytes(), persistedEntityFile); + } +} diff --git a/camp/camp-brooklyn/src/test/resources/org/apache/brooklyn/camp/brooklyn/rebind/misc-guava-2021-12-entity-hrxo4j0dcs b/camp/camp-brooklyn/src/test/resources/org/apache/brooklyn/camp/brooklyn/rebind/misc-guava-2021-12-entity-hrxo4j0dcs new file mode 100644 index 0000000..9f1709a --- /dev/null +++ b/camp/camp-brooklyn/src/test/resources/org/apache/brooklyn/camp/brooklyn/rebind/misc-guava-2021-12-entity-hrxo4j0dcs @@ -0,0 +1,192 @@ +<!-- +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. +--> + +<entity> + <brooklynVersion>1.1.0-SNAPSHOT</brooklynVersion> + <type>org.apache.brooklyn.core.test.entity.TestApplicationNoEnrichersImpl</type> + <id>hrxo4j0dcs</id> + <displayName>Load Balancer (nginx)</displayName> + <tags> + <org.apache.brooklyn.core:org.apache.brooklyn.core.mgmt.BrooklynTags_-NamedStringTag> + <kind>yaml_spec</kind> + <contents>services: +- type: org.apache.brooklyn.entity.proxy.nginx.NginxController + name: Nginx Server + description: A single Nginx server. Provides HTTP and reverse proxy services</contents> + </org.apache.brooklyn.core:org.apache.brooklyn.core.mgmt.BrooklynTags_-NamedStringTag> + <MutableMap> + <spec__hierarchy> + <MutableList serialization="custom"> + <unserializable-parents/> + <list> + <default> + <size>1</size> + </default> + <int>1</int> + <org.apache.brooklyn.core:org.apache.brooklyn.core.mgmt.BrooklynTags_-SpecSummary> + <summary>brooklyn-camp plan for type org.apache.brooklyn.entity.proxy.nginx.NginxController</summary> + <format>brooklyn-camp</format> + <contents class="string">services: +- type: org.apache.brooklyn.entity.proxy.nginx.NginxController + name: Nginx Server + description: A single Nginx server. Provides HTTP and reverse proxy services</contents> + </org.apache.brooklyn.core:org.apache.brooklyn.core.mgmt.BrooklynTags_-SpecSummary> + </list> + </MutableList> + </spec__hierarchy> + </MutableMap> + <MutableMap> + <depth__in__ancestor type="int">1</depth__in__ancestor> + </MutableMap> + </tags> + + <attributes> + <service.notUp.diagnostics> + <com.google.guava:com.google.common.collect.EmptyImmutableBiMap/> + </service.notUp.diagnostics> + <dashboard.locations> + <com.google.guava:com.google.common.collect.SingletonImmutableBiMap> + <entry> + <string>resources</string> + <set> + <java.util.Collections_-UnmodifiableMap> + <m class="MutableMap"> + <id>us-east-1/i-0e1d6bd972a305499</id> + <name>3.83.112.67</name> + <provider>aws-ec2</provider> + <region>us-east-1</region> + <icon> + <null/> + </icon> + <resourceType>server</resourceType> + </m> + </java.util.Collections_-UnmodifiableMap> + </set> + </entry> + </com.google.guava:com.google.common.collect.SingletonImmutableBiMap> + </dashboard.locations> + <host.addresses.private> + <com.google.guava:com.google.common.collect.SingletonImmutableSet> + <string>172.31.78.228</string> + </com.google.guava:com.google.common.collect.SingletonImmutableSet> + </host.addresses.private> + <member.sensor.portNumber> + <org.apache.brooklyn.core:org.apache.brooklyn.core.sensor.PortAttributeSensorAndConfigKey> + <typeToken class="com.google.guava:com.google.common.reflect.TypeToken$SimpleTypeToken"> + <runtimeType class="java-class">java.lang.Integer</runtimeType> + </typeToken> + <name>http.port</name> + <description>HTTP port</description> + <persistence>REQUIRED</persistence> + <configKey class="configKey"> + <name>http.port</name> + <deprecatedNames class="ImmutableList"/> + <typeToken class="com.google.guava:com.google.common.reflect.TypeToken$SimpleTypeToken"> + <runtimeType class="java-class">org.apache.brooklyn.api:org.apache.brooklyn.api.location.PortRange</runtimeType> + </typeToken> + <description>HTTP port</description> + <defaultValue class="org.apache.brooklyn.core:org.apache.brooklyn.core.location.PortRanges$AggregatePortRange"> + <ranges class="ImmutableList"> + <org.apache.brooklyn.core:org.apache.brooklyn.core.location.PortRanges_-SinglePort> + <port>8080</port> + </org.apache.brooklyn.core:org.apache.brooklyn.core.location.PortRanges_-SinglePort> + <org.apache.brooklyn.core:org.apache.brooklyn.core.location.PortRanges_-LinearPortRange> + <start>18080</start> + <end>65535</end> + <delta>1</delta> + </org.apache.brooklyn.core:org.apache.brooklyn.core.location.PortRanges_-LinearPortRange> + </ranges> + </defaultValue> + <reconfigurable>false</reconfigurable> + <constraint class="com.google.common.base.Predicates$ObjectPredicate">ALWAYS_TRUE</constraint> + </configKey> + </org.apache.brooklyn.core:org.apache.brooklyn.core.sensor.PortAttributeSensorAndConfigKey> + </member.sensor.portNumber> + </attributes> + + <attributeKeys> + <service.notUp.indicators> + <attributeSensor> + <typeToken class="org.apache.brooklyn.core:org.apache.brooklyn.core.entity.Attributes$1" resolves-to="com.google.guava:com.google.common.reflect.TypeToken$SimpleTypeToken"> + <runtimeType class="com.google.guava:com.google.common.reflect.Types$ParameterizedTypeImpl"> + <argumentsList> + <java-class>java.lang.String</java-class> + <java-class>java.lang.Object</java-class> + </argumentsList> + <rawType>java.util.Map</rawType> + </runtimeType> + </typeToken> + <name>service.notUp.indicators</name> + <description>A map of namespaced indicators that the service is not up</description> + <persistence>REQUIRED</persistence> + </attributeSensor> + </service.notUp.indicators> + <service.notUp.diagnostics> + <attributeSensor> + <typeToken class="org.apache.brooklyn.core:org.apache.brooklyn.core.entity.Attributes$3" resolves-to="com.google.guava:com.google.common.reflect.TypeToken$SimpleTypeToken"> + <runtimeType class="com.google.guava:com.google.common.reflect.Types$ParameterizedTypeImpl"> + <argumentsList> + <java-class>java.lang.String</java-class> + <java-class>java.lang.Object</java-class> + </argumentsList> + <rawType>java.util.Map</rawType> + </runtimeType> + </typeToken> + <name>service.notUp.diagnostics</name> + <description>A map of namespaced diagnostics, from when the service is not up</description> + <persistence>REQUIRED</persistence> + </attributeSensor> + </service.notUp.diagnostics> + <dashboard.locations> + <org.apache.brooklyn.core:org.apache.brooklyn.core.sensor.BasicAttributeSensorAndConfigKey> + <typeToken class="com.google.guava:com.google.common.reflect.TypeToken$SimpleTypeToken"> + <runtimeType class="java-class">java.util.Map</runtimeType> + </typeToken> + <name>dashboard.locations</name> + <description>Locations in which the VMs are running. A map where the key is category of location (e.g. server) and the value is a list of maps containing name/icon/count</description> + <persistence>REQUIRED</persistence> + <configKey class="configKey"> + <name>dashboard.locations</name> + <deprecatedNames class="ImmutableList" reference="../../../../../attributes/member.sensor.portNumber/org.apache.brooklyn.core:org.apache.brooklyn.core.sensor.PortAttributeSensorAndConfigKey/configKey/deprecatedNames"/> + <typeToken class="com.google.guava:com.google.common.reflect.TypeToken$SimpleTypeToken"> + <runtimeType class="java-class">java.util.Map</runtimeType> + </typeToken> + <description>Locations in which the VMs are running. A map where the key is category of location (e.g. server) and the value is a list of maps containing name/icon/count</description> + <reconfigurable>false</reconfigurable> + <constraint class="com.google.common.base.Predicates$ObjectPredicate">ALWAYS_TRUE</constraint> + </configKey> + </org.apache.brooklyn.core:org.apache.brooklyn.core.sensor.BasicAttributeSensorAndConfigKey> + </dashboard.locations> + <host.addresses.private> + <attributeSensor> + <typeToken class="org.apache.brooklyn.locations-jclouds:org.apache.brooklyn.location.jclouds.ConnectivityResolver$2" resolves-to="com.google.guava:com.google.common.reflect.TypeToken$SimpleTypeToken"> + <runtimeType class="com.google.guava:com.google.common.reflect.Types$ParameterizedTypeImpl"> + <argumentsList> + <java-class>java.lang.String</java-class> + </argumentsList> + <rawType>java.lang.Iterable</rawType> + </runtimeType> + </typeToken> + <name>host.addresses.private</name> + <description>Private addresses on an instance</description> + <persistence>REQUIRED</persistence> + </attributeSensor> + </host.addresses.private> + </attributeKeys> +</entity> diff --git a/core/src/main/resources/org/apache/brooklyn/core/mgmt/persist/deserializingClassRenames.properties b/core/src/main/resources/org/apache/brooklyn/core/mgmt/persist/deserializingClassRenames.properties index 959b76d..e233a99 100644 --- a/core/src/main/resources/org/apache/brooklyn/core/mgmt/persist/deserializingClassRenames.properties +++ b/core/src/main/resources/org/apache/brooklyn/core/mgmt/persist/deserializingClassRenames.properties @@ -1462,3 +1462,4 @@ org.apache.brooklyn.software-cm-salt\:org.apache.brooklyn.entity.cm.salt.impl.Sa # code-grant of new UI io.cloudsoft.amp.ui.common.enricher.AmpExternalUiModuleEnricher : org.apache.brooklyn.ui.modularity.enricher.BrooklynExternalUiModuleEnricher +com.google.common.collect.EmptyImmutableBiMap : org.apache.brooklyn.util.guava.EmptyImmutableBiMap \ No newline at end of file diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/guava/EmptyImmutableBiMap.java b/utils/common/src/main/java/org/apache/brooklyn/util/guava/EmptyImmutableBiMap.java new file mode 100644 index 0000000..0f8e2a2 --- /dev/null +++ b/utils/common/src/main/java/org/apache/brooklyn/util/guava/EmptyImmutableBiMap.java @@ -0,0 +1,133 @@ +/* + * 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 org.apache.brooklyn.util.guava; + +import com.google.common.collect.BiMap; +import com.google.common.collect.ImmutableBiMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableSetMultimap; +import java.util.Map; +import java.util.Set; +import javax.annotation.Nullable; + +@Deprecated +/** @deprecated since introduced; use ImmutableBiMap#of(). here for deserialization compatibility. */ +public class EmptyImmutableBiMap<K,V> implements BiMap<K,V> { + + public final static ImmutableBiMap<Object,Object> INSTANCE = ImmutableBiMap.of(); + + @Override + public @Nullable V put(@Nullable K key, @Nullable V value) { + return null; + } + + @Override + public @Nullable V forcePut(@Nullable K key, @Nullable V value) { + return null; + } + + @Override + public void putAll(Map<? extends K, ? extends V> map) { + + } + + @Override + public Set<V> values() { + return null; + } + + @Override + public ImmutableBiMap<V,K> inverse() { + return (ImmutableBiMap) INSTANCE; + } + + @Override + public boolean isEmpty() { + return INSTANCE.isEmpty(); + } + + @Override + public boolean containsKey(@Nullable Object key) { + return INSTANCE.containsKey(key); + } + + @Override + public boolean containsValue(@Nullable Object value) { + return INSTANCE.containsValue(value); + } + + @Override + public V get(@Nullable Object key) { + return null; + } + + public Object getOrDefault(@Nullable Object key, @Nullable Object defaultValue) { + return INSTANCE.getOrDefault(key, defaultValue); + } + + @Override + public ImmutableSet<Entry<K, V>> entrySet() { + return (ImmutableSet) INSTANCE.entrySet(); + } + + @Override + public ImmutableSet<K> keySet() { + return (ImmutableSet) INSTANCE.keySet(); + } + + public ImmutableSetMultimap<Object, Object> asMultimap() { + return INSTANCE.asMultimap(); + } + + @Override + public boolean equals(@Nullable Object object) { + return INSTANCE.equals(object); + } + + @Override + public int hashCode() { + return INSTANCE.hashCode(); + } + + @Override + public String toString() { + return INSTANCE.toString(); + } + + @Override + public int size() { + return INSTANCE.size(); + } + + @Override + public V remove(Object key) { + return null; + } + + @Deprecated + @Override + public void clear() { + INSTANCE.clear(); + } + + @Override + public boolean remove(Object key, Object value) { + return INSTANCE.remove(key, value); + } +}
