Mercurial > hg > thermostat-ng > agent
changeset 2705:e06cb0c117d9
Refactor Vm-GC to merge agent and common bundles.
Reviewed-By: neugens, jerboaa
Review-Thread: http://icedtea.classpath.org/pipermail/thermostat/2017-June/023857.html
line wrap: on
line diff
--- a/plugins/vm-gc/agent/pom.xml Fri Jun 23 10:25:42 2017 -0400 +++ b/plugins/vm-gc/agent/pom.xml Fri Jun 23 11:45:40 2017 -0400 @@ -47,6 +47,26 @@ <packaging>bundle</packaging> <name>Thermostat VM GC Agent plugin</name> <build> + <resources> + <resource> + <directory>src/main/resources</directory> + <filtering>true</filtering> + <excludes> + <exclude>**/*.png</exclude> + <exclude>**/*.xml</exclude> + <exclude>**/*.xsd</exclude> + </excludes> + </resource> + <resource> + <directory>src/main/resources</directory> + <filtering>false</filtering> + <includes> + <include>**/*.png</include> + <include>**/*.xml</include> + <include>**/*.xsd</include> + </includes> + </resource> + </resources> <plugins> <plugin> <groupId>org.apache.felix</groupId> @@ -56,9 +76,14 @@ <instructions> <Bundle-Vendor>Red Hat, Inc.</Bundle-Vendor> <Bundle-SymbolicName>com.redhat.thermostat.vm.gc.agent</Bundle-SymbolicName> - <Export-Package /> + <Export-Package> + com.redhat.thermostat.vm.gc.agent, + com.redhat.thermostat.vm.gc.agent.model, + com.redhat.thermostat.vm.gc.agent.params + </Export-Package> <Private-Package> - com.redhat.thermostat.vm.gc.agent.internal + com.redhat.thermostat.vm.gc.agent.internal, + com.redhat.thermostat.vm.gc.agent.internal.models </Private-Package> <!-- Do not autogenerate uses clauses in Manifests --> <_nouses>true</_nouses> @@ -107,11 +132,6 @@ </dependency> <dependency> <groupId>com.redhat.thermostat</groupId> - <artifactId>thermostat-vm-gc-common</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>com.redhat.thermostat</groupId> <artifactId>thermostat-agent-core</artifactId> <version>${project.version}</version> </dependency> @@ -131,5 +151,10 @@ <version>${project.version}</version> <scope>test</scope> </dependency> + <!-- declarative services --> + <dependency> + <groupId>org.apache.felix</groupId> + <artifactId>org.apache.felix.scr.annotations</artifactId> + </dependency> </dependencies> </project>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/Constants.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,49 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent; + +import com.redhat.thermostat.common.Ordered; + +public class Constants { + + public static final int ORDER = Ordered.ORDER_MEMORY_GROUP + 20; + + private Constants() { + throw new AssertionError("Do not instantiate this"); + } + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/GcCommonNameMapper.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,129 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class GcCommonNameMapper { + + private static final Map<Set<String>, CollectorCommonName> commonNameMap; + + public enum CollectorCommonName { + /** Serial Collector: {@code -XX:+UseSerialGC} */ + SERIAL_COLLECTOR("Serial Collector"), + /** G1 Collector: {@code -XX:+UseG1GC} */ + G1("Garbage-First Collector (G1)"), + /** Parallel Collector: {@code -XX:+UseParallelGC} */ + PARALLEL_COLLECTOR("Parallel Collector"), + /** Concurrent Mark and Sweep Collector: {@code +XX:+UseConcMarkSweepGC} */ + CONCURRENT_COLLECTOR("Concurrent Collector (Concurrent Mark and Sweep)"), + /** Mark Sweep Compact Collector: {@code -XX:+UseParNewGC} */ + MARK_SWEEP_COMPACT("Mark Sweep Compact Collector"), + /** Shenandoah Collector: {@code -XX:+UseShenandoahGC} */ + SHENANDOAH("Shenandoah Collector"), + UNKNOWN_COLLECTOR("Unknown Collector"); + + private String humanReadableName; + + private CollectorCommonName(String humanReadableName) { + this.humanReadableName = humanReadableName; + } + + public String getHumanReadableString() { + return humanReadableName; + } + } + + static { + commonNameMap = new HashMap<>(4); + // Serial collector has two sub collectors, MSC and Copy + Set<String> serialCollectorColls = new HashSet<>(2); + serialCollectorColls.add("MSC"); + serialCollectorColls.add("Copy"); + commonNameMap.put(serialCollectorColls, CollectorCommonName.SERIAL_COLLECTOR); + // Mark Sweep Compact GC has two sub collectors, MSC and PCopy + Set<String> msCompactColls = new HashSet<>(2); + msCompactColls.add("MSC"); + msCompactColls.add("PCopy"); + commonNameMap.put(msCompactColls, CollectorCommonName.MARK_SWEEP_COMPACT); + // Garbage first collector (G1) has only one collector, namely + // 'G1 incremental collections' + Set<String> g1Colls = new HashSet<>(1); + g1Colls.add("G1 incremental collections"); + commonNameMap.put(g1Colls, CollectorCommonName.G1); + // Current default, the Parallel Collector has two sub collectors: + // PSParallelCompact and PSScavenge + Set<String> parallelColls = new HashSet<>(2); + parallelColls.add("PSParallelCompact"); + parallelColls.add("PSScavenge"); + commonNameMap.put(parallelColls, CollectorCommonName.PARALLEL_COLLECTOR); + // Concurrent collector has two sub collectors: + // CMS and PCopy + Set<String> concurrentColls = new HashSet<>(2); + concurrentColls.add("CMS"); + concurrentColls.add("PCopy"); + commonNameMap.put(concurrentColls, CollectorCommonName.CONCURRENT_COLLECTOR); + // Shenandoah collector has 3 exposed sub collectors even though + // it's non-generational + Set<String> shenandoahColls = new HashSet<>(3); + shenandoahColls.add("Shenandoah concurrent phases"); + shenandoahColls.add("Shenandoah pauses"); + shenandoahColls.add("Shenandoah full GC pauses"); + commonNameMap.put(shenandoahColls, CollectorCommonName.SHENANDOAH); + } + + /** + * + * @param distinctCollectors + * A set of distinct collector names for one JVM. + * @return The common name of the collector for this set of distinct + * collectors. + */ + public CollectorCommonName mapToCommonName(Set<String> distinctCollectors) { + for (Set<String> subCollSet: commonNameMap.keySet()) { + if (subCollSet.equals(distinctCollectors)) { + return commonNameMap.get(subCollSet); + } + } + // not found so far? return unknown. + return CollectorCommonName.UNKNOWN_COLLECTOR; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/internal/LocaleResources.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,54 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.internal; + +import com.redhat.thermostat.shared.locale.Translate; + +public enum LocaleResources { + + VALIDATION_FAILED, + VALIDATION_WARNING, + VALIDATION_ERROR, + VALIDATION_FATAL_ERROR, + ; + + static final String RESOURCE_BUNDLE = "com.redhat.thermostat.vm.gc.agent.locale.strings"; + + public static Translate<LocaleResources> createLocalizer() { + return new Translate<>(RESOURCE_BUNDLE, LocaleResources.class); + } +}
--- a/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/internal/VmGcBackend.java Fri Jun 23 10:25:42 2017 -0400 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/internal/VmGcBackend.java Fri Jun 23 11:45:40 2017 -0400 @@ -48,8 +48,8 @@ import com.redhat.thermostat.backend.Backend; import com.redhat.thermostat.common.Version; import com.redhat.thermostat.storage.core.WriterID; -import com.redhat.thermostat.vm.gc.common.Constants; -import com.redhat.thermostat.vm.gc.common.VmGcStatDAO; +import com.redhat.thermostat.vm.gc.agent.Constants; +import com.redhat.thermostat.vm.gc.agent.internal.models.VmGcStatDAO; @Component @Service(value = Backend.class)
--- a/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/internal/VmGcVmListener.java Fri Jun 23 10:25:42 2017 -0400 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/internal/VmGcVmListener.java Fri Jun 23 11:45:40 2017 -0400 @@ -43,8 +43,8 @@ import com.redhat.thermostat.jvm.overview.agent.VmUpdate; import com.redhat.thermostat.jvm.overview.agent.VmUpdateException; import com.redhat.thermostat.jvm.overview.agent.VmUpdateListener; -import com.redhat.thermostat.vm.gc.common.VmGcStatDAO; -import com.redhat.thermostat.vm.gc.common.model.VmGcStat; +import com.redhat.thermostat.vm.gc.agent.internal.models.VmGcStatDAO; +import com.redhat.thermostat.vm.gc.agent.model.VmGcStat; public class VmGcVmListener implements VmUpdateListener {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/internal/models/VmGcStatDAO.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,47 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.internal.models; + +import com.redhat.thermostat.annotations.Service; +import com.redhat.thermostat.vm.gc.agent.model.VmGcStat; + +@Service +public interface VmGcStatDAO { + + public void putVmGcStat(VmGcStat stat); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/internal/models/VmGcStatDAOImpl.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,146 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.internal.models; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.Service; +import org.eclipse.jetty.client.api.ContentResponse; +import org.eclipse.jetty.http.HttpMethod; +import org.eclipse.jetty.http.HttpStatus; + +import com.redhat.thermostat.agent.http.HttpRequestService; +import com.redhat.thermostat.common.config.experimental.ConfigurationInfoSource; +import com.redhat.thermostat.common.plugins.PluginConfiguration; +import com.redhat.thermostat.common.utils.LoggingUtils; +import com.redhat.thermostat.vm.gc.agent.model.VmGcStat; + +@Component +@Service(value = VmGcStatDAO.class) +public class VmGcStatDAOImpl implements VmGcStatDAO { + + private static final Logger logger = LoggingUtils.getLogger(VmGcStatDAOImpl.class); + private static final String PLUGIN_ID = "vm-gc"; + static final String CONTENT_TYPE = "application/json"; + + private final JsonHelper jsonHelper; + private final ConfigurationCreator configCreator; + + @Reference + private ConfigurationInfoSource configInfoSource; + private String gatewayURL; + + @Reference + private HttpRequestService httpRequestService; + + public VmGcStatDAOImpl() { + this(new JsonHelper(new VmGcStatTypeAdapter()), new ConfigurationCreator(), null); + } + + VmGcStatDAOImpl(JsonHelper jh, ConfigurationCreator creator, ConfigurationInfoSource source) { + this.jsonHelper = jh; + this.configCreator = creator; + this.configInfoSource = source; + } + + @Activate + void activate() throws Exception { + PluginConfiguration config = configCreator.create(configInfoSource); + this.gatewayURL = config.getGatewayURL(); + } + + protected void bindHttpRequestService(HttpRequestService httpRequestService) { + this.httpRequestService = httpRequestService; + } + + protected void unbindHttpRequestService(HttpRequestService httpRequestService) { + this.httpRequestService = null; + } + + @Override + public void putVmGcStat(final VmGcStat stat) { + try { + String json = jsonHelper.toJson(Arrays.asList(stat)); + + if (null != httpRequestService) { + ContentResponse response = httpRequestService.sendHttpRequest(json, gatewayURL, HttpMethod.POST); + + int status = response.getStatus(); + if (status != HttpStatus.OK_200) { + throw new IOException("Gateway returned HTTP status " + String.valueOf(status) + " - " + response.getReason()); + } + + } else { + logger.log(Level.WARNING, "Failed to send VmGcStat information to web gateway. Http service unavailable."); + } + } catch (Exception e) { + logger.log(Level.WARNING, "Failed to send VmGcStat information to web gateway", e); + } + } + + // For Testing purposes + static class JsonHelper { + + private final VmGcStatTypeAdapter adapter; + + public JsonHelper(VmGcStatTypeAdapter adapter) { + this.adapter = adapter; + } + + public String toJson(List<VmGcStat> list) throws IOException { + return adapter.toJson(list); + } + + } + + // For Testing purposes + static class ConfigurationCreator { + + PluginConfiguration create(ConfigurationInfoSource source) { + return new PluginConfiguration(source, PLUGIN_ID); + } + + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/internal/models/VmGcStatTypeAdapter.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,95 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.internal.models; + +import com.google.gson.TypeAdapter; +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import com.redhat.thermostat.vm.gc.agent.model.VmGcStat; + +import java.io.IOException; +import java.util.List; + +public class VmGcStatTypeAdapter extends TypeAdapter<List<VmGcStat>> { + + private static final String TYPE_LONG = "$numberLong"; + private static final String AGENT_ID = "agentId"; + private static final String VM_ID = "jvmId"; + private static final String TIMESTAMP = "timeStamp"; + private static final String COLLECTOR_NAME = "collectorName"; + private static final String RUN_COUNT = "runCount"; + private static final String WALL_TIME_IN_MICROS = "wallTimeInMicros"; + + @Override + public List<VmGcStat> read(JsonReader in) throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public void write(JsonWriter out, List<VmGcStat> stats) throws IOException { + out.beginArray(); + for (VmGcStat stat : stats) { + writeGcStat(out, stat); + } + out.endArray(); + } + + private void writeGcStat(JsonWriter out, VmGcStat stat) throws IOException { + out.beginObject(); + out.name(AGENT_ID); + out.value(stat.getAgentId()); + out.name(VM_ID); + out.value(stat.getVmId()); + out.name(TIMESTAMP); + writeLong(out, stat.getTimeStamp()); + out.name(COLLECTOR_NAME); + out.value(stat.getCollectorName()); + out.name(RUN_COUNT); + writeLong(out, stat.getRunCount()); + out.name(WALL_TIME_IN_MICROS); + writeLong(out, stat.getWallTime()); + out.endObject(); + } + + private void writeLong(JsonWriter out, long value) throws IOException { + // Write MongoDB representation of a Long + out.beginObject(); + out.name(TYPE_LONG); + out.value(String.valueOf(value)); + out.endObject(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/model/VmGcStat.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,119 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.model; + +import com.redhat.thermostat.storage.core.Entity; +import com.redhat.thermostat.storage.core.Persist; +import com.redhat.thermostat.storage.model.BasePojo; +import com.redhat.thermostat.storage.model.TimeStampedPojo; + +@Entity +public class VmGcStat extends BasePojo implements TimeStampedPojo { + + private long timeStamp; + private String vmId; + private String collectorName; + private long runCount; + private long wallTimeInMicros; + + public VmGcStat() { + super(null); + } + + public VmGcStat(String writerId, String vmId, long timestamp, String collectorName, long runCount, long wallTimeInMicros) { + super(writerId); + this.timeStamp = timestamp; + this.vmId = vmId; + this.collectorName = collectorName; + this.runCount = runCount; + this.wallTimeInMicros = wallTimeInMicros; + } + + @Persist + public String getVmId() { + return vmId; + } + + @Persist + public void setVmId(String vmId) { + this.vmId = vmId; + } + + @Persist + public String getCollectorName() { + return collectorName; + } + + @Persist + public void setCollectorName(String collectorName) { + this.collectorName = collectorName; + } + + @Persist + public long getRunCount() { + return runCount; + } + + @Persist + public void setRunCount(long runCount) { + this.runCount = runCount; + } + + /** In microseconds */ + @Persist + public long getWallTime() { + return wallTimeInMicros; + } + + @Persist + public void setWallTime(long wallTimeInMicros) { + this.wallTimeInMicros = wallTimeInMicros; + } + + @Override + @Persist + public long getTimeStamp() { + return timeStamp; + } + + @Persist + public void setTimeStamp(long timeStamp) { + this.timeStamp = timeStamp; + } + +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/params/AbstractValidationError.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,94 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.params; + +/** + * + * Exception thrown on XML validation errors of gc-params-mapping.xml files. + * + */ +public abstract class AbstractValidationError implements ValidationIssue { + + private int lineNumber; + private int columnNumber; + private String message; + private String gcParamsMappingXmlFilePath; + + public AbstractValidationError(int lineNumber, int columnNumber, String message, String gcParamsMappingXmlFilePath) { + this.lineNumber = lineNumber; + this.columnNumber = columnNumber; + this.message = message; + this.gcParamsMappingXmlFilePath = gcParamsMappingXmlFilePath; + } + + @Override + public int getLineNumber() { + return lineNumber; + } + + @Override + public int getColumnNumber() { + return columnNumber; + } + + @Override + public String getMessage() { + return message; + } + + @Override + public String getXmlFilePath() { + return gcParamsMappingXmlFilePath; + } + + public String toString() { + String LS = System.getProperty("line.separator"); + StringBuilder builder = new StringBuilder(); + + builder.append("[").append(getName()).append("]").append(LS); + builder.append(" Message: ").append(getMessage()).append(LS); + builder.append(" File: ").append(getXmlFilePath()).append(LS); + builder.append(" Line number: ").append(getLineNumber()).append(LS); + builder.append(" Column number: ").append(getColumnNumber()).append(LS); + + return builder.toString(); + + } + + public abstract String getName(); + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/params/Collector.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,78 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.params; + +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; + +import static java.util.Objects.requireNonNull; + +public class Collector { + + private final CollectorInfo collectorInfo; + private final Set<GcParam> gcParams; + + public Collector(CollectorInfo collectorInfo, Set<GcParam> gcParams) { + this.collectorInfo = requireNonNull(collectorInfo); + this.gcParams = new HashSet<>(requireNonNull(gcParams)); + } + + public CollectorInfo getCollectorInfo() { + return collectorInfo; + } + + public Set<GcParam> getGcParams() { + return gcParams; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Collector collector = (Collector) o; + + return Objects.equals(collectorInfo, collector.collectorInfo) + && Objects.equals(gcParams, collector.gcParams); + } + + @Override + public int hashCode() { + return Objects.hash(collectorInfo, gcParams); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/params/CollectorInfo.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,92 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.params; + +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; + +import static java.util.Objects.requireNonNull; + +public class CollectorInfo { + + private final JavaVersionRange javaVersionRange; + private final String commonName; + private final Set<String> collectorDistinctNames; + private final String referenceUrl; + + public CollectorInfo(JavaVersionRange javaVersionRange, String commonName, Set<String> collectorDistinctNames, String referenceUrl) { + this.javaVersionRange = requireNonNull(javaVersionRange); + this.commonName = requireNonNull(commonName); + this.collectorDistinctNames = new HashSet<>(requireNonNull(collectorDistinctNames)); + this.referenceUrl = requireNonNull(referenceUrl); + } + + public JavaVersionRange getJavaVersionRange() { + return javaVersionRange; + } + + public String getCommonName() { + return commonName; + } + + public Set<String> getCollectorDistinctNames() { + return new HashSet<>(collectorDistinctNames); + } + + public String getReferenceUrl() { + return referenceUrl; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + CollectorInfo that = (CollectorInfo) o; + + return Objects.equals(javaVersionRange, that.javaVersionRange) + && Objects.equals(commonName, that.commonName) + && Objects.equals(collectorDistinctNames, that.collectorDistinctNames) + && Objects.equals(referenceUrl, that.referenceUrl); + } + + @Override + public int hashCode() { + return Objects.hash(javaVersionRange, commonName, collectorDistinctNames, referenceUrl); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/params/Error.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,50 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.params; + +public class Error extends AbstractValidationError { + + Error(int lineNumber, int columnNumber, String message, String gcParamsMappingXmlFilePath) { + super(lineNumber, columnNumber, message, gcParamsMappingXmlFilePath); + } + + @Override + public String getName() { + return this.getClass().getSimpleName(); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/params/FatalError.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,50 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.params; + +public class FatalError extends AbstractValidationError { + + FatalError(int lineNumber, int columnNumber, String message, String gcParamsMappingXmlFilePath) { + super(lineNumber, columnNumber, message, gcParamsMappingXmlFilePath); + } + + @Override + public String getName() { + return this.getClass().getSimpleName(); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/params/GcParam.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,87 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.params; + +import java.util.Objects; + +import static java.util.Objects.requireNonNull; + +public class GcParam { + + private final String flag; + private final String description; + private final JavaVersionRange javaVersionRange; + + public GcParam(String flag, String description, JavaVersionRange javaVersionRange) { + this.flag = requireNonNull(flag); + this.description = requireNonNull(description); + this.javaVersionRange = requireNonNull(javaVersionRange); + } + + public String getFlag() { + return flag; + } + + public String getDescription() { + return description; + } + + public JavaVersionRange getJavaVersionRange() { + return javaVersionRange; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + GcParam gcParam = (GcParam) o; + + return Objects.equals(flag, gcParam.flag) + && Objects.equals(description, gcParam.description) + && Objects.equals(javaVersionRange, gcParam.javaVersionRange); + } + + @Override + public int hashCode() { + return Objects.hash(flag, description, javaVersionRange); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/params/GcParamsMapper.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,146 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.params; + +import com.redhat.thermostat.common.utils.LoggingUtils; +import com.redhat.thermostat.shared.locale.Translate; +import com.redhat.thermostat.vm.gc.agent.GcCommonNameMapper; +import com.redhat.thermostat.vm.gc.agent.internal.LocaleResources; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.logging.Logger; + +public enum GcParamsMapper { + + INSTANCE; + + static final String XML_RESOURCE_URL = "/com/redhat/thermostat/vm/gc/agent/gc-params-mapping.xml"; + + private final Translate<LocaleResources> translator = LocaleResources.createLocalizer(); + private final Logger logger = LoggingUtils.getLogger(GcParamsMapper.class); + private final Map<GcCommonNameMapper.CollectorCommonName, Collector> paramsMap = new HashMap<>(); + private final Set<GcParam> commonParams = new HashSet<>(); + + GcParamsMapper() { + validateGcParamsMapping(); + parseGcParamsMapping(); + } + + void validateGcParamsMapping() { + InputStream xmlStream; + try { + xmlStream = getXmlStream(); + GcParamsMappingValidator validator = new GcParamsMappingValidator(); + validator.validate(XML_RESOURCE_URL, xmlStream); + } catch (URISyntaxException | FileNotFoundException e) { + logger.warning(translator.localize( + LocaleResources.VALIDATION_FAILED, + XML_RESOURCE_URL, + e.getLocalizedMessage()) + .getContents()); + } catch (GcParamsMappingValidatorException e) { + ValidationErrorsFormatter formatter = new ValidationErrorsFormatter(); + logger.warning(translator.localize( + LocaleResources.VALIDATION_FAILED, + XML_RESOURCE_URL, + formatter.format(e.getAllErrors())) + .getContents()); + } + } + + InputStream getXmlStream() throws URISyntaxException { + return this.getClass().getResourceAsStream(XML_RESOURCE_URL); + } + + private void parseGcParamsMapping() { + try { + GcParamsParser parser = new GcParamsParser(getXmlStream()); + GcParamsParser.ParseResult parseResult = parser.parse(); + for (Collector collector : parseResult.getCollectors()) { + GcCommonNameMapper commonNameMapper = new GcCommonNameMapper(); + paramsMap.put(commonNameMapper.mapToCommonName(collector.getCollectorInfo().getCollectorDistinctNames()), collector); + } + commonParams.addAll(parseResult.getGcCommonParams()); + } catch (URISyntaxException | IOException | GcParamsParser.GcParamsParseException e) { + logger.warning("Failed to parse " + XML_RESOURCE_URL + " : " + e.getLocalizedMessage()); + } + } + + List<Collector> getCollectors() { + return new ArrayList<>(paramsMap.values()); + } + + Set<GcParam> getCommonParams() { + return new HashSet<>(commonParams); + } + + public List<GcParam> getParams(GcCommonNameMapper.CollectorCommonName collectorCommonName, JavaVersionRange javaVersionRange) { + Objects.requireNonNull(collectorCommonName); + Objects.requireNonNull(javaVersionRange); + if (!paramsMap.containsKey(collectorCommonName)) { + return Collections.emptyList(); + } + Collector collector = paramsMap.get(collectorCommonName); + if (collector == null || !collector.getCollectorInfo().getJavaVersionRange().contains(javaVersionRange)) { + return Collections.emptyList(); + } + List<GcParam> params = new ArrayList<>(); + for (GcParam param : collector.getGcParams()) { + if (param.getJavaVersionRange().contains(javaVersionRange)) { + params.add(param); + } + } + params.addAll(commonParams); + return params; + } + + public static GcParamsMapper getInstance() { + return INSTANCE; + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/params/GcParamsMappingValidator.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,90 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.params; + +import org.xml.sax.SAXException; + +import javax.xml.XMLConstants; +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; +import javax.xml.validation.Validator; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +public class GcParamsMappingValidator { + + static final String XSD_RESOURCE_URL = "/com/redhat/thermostat/vm/gc/agent/gc-params-mapping.xsd"; + + public void validate(String path, InputStream gcParamsMappingXmlStream) throws GcParamsMappingValidatorException, FileNotFoundException { + URL schemaUrl = GcParamsMappingValidator.class.getResource(XSD_RESOURCE_URL); + SchemaFactory schemaFactory = + SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + GcParamsMappingValidatorErrorHandler handler = new GcParamsMappingValidatorErrorHandler(path); + + try { + Schema schema = schemaFactory.newSchema(schemaUrl); + Validator validator = schema.newValidator(); + validator.setErrorHandler(handler); + validator.validate(new StreamSource(gcParamsMappingXmlStream)); + } catch (SAXException exception) { + throw new GcParamsMappingValidatorException( + "gc-params-mapping.xml not well-formed XML", path, + handler.getErrors(), handler.getWarnings(), + handler.getFatalErrors(), exception); + } catch (FileNotFoundException fnfe) { + throw fnfe; + } catch (IOException ioe) { + throw new GcParamsMappingValidatorException( + ioe.getLocalizedMessage(), path, handler.getErrors(), + handler.getWarnings(), handler.getFatalErrors(), ioe); + } + + // We've registered an exception handler, so validation issues do not throw + // exceptions unless the xml file itself is not valid. Let's ask the handler + // if there were issues so we can throw an exception accordingly. + if (handler.hasValidationIssues()) { + throw new GcParamsMappingValidatorException( + "Failed to validate gc-params-mapping.xml", path, + handler.getErrors(), handler.getWarnings(), + handler.getFatalErrors()); + } + } + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/params/GcParamsMappingValidatorErrorHandler.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,110 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.params; + +import java.util.ArrayList; +import java.util.List; + +import org.xml.sax.ErrorHandler; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; + +public class GcParamsMappingValidatorErrorHandler implements ErrorHandler { + + private final String gcParamsMappingXmlFilePath; + private final List<ValidationIssue> warnings; + private final List<ValidationIssue> errors; + private final List<ValidationIssue> fatalErrors; + + public GcParamsMappingValidatorErrorHandler(String gcParamsMappingXmlFilePath) { + this.gcParamsMappingXmlFilePath = gcParamsMappingXmlFilePath; + warnings = new ArrayList<>(); + errors = new ArrayList<>(); + fatalErrors = new ArrayList<>(); + } + + @Override + public void warning(SAXParseException exception) throws SAXException { + Warning newWarning = new Warning(exception.getLineNumber(), + exception.getColumnNumber(), + exception.getLocalizedMessage(), + gcParamsMappingXmlFilePath); + warnings.add(newWarning); + } + + @Override + public void error(SAXParseException exception) throws SAXParseException { + Error newError = new Error(exception.getLineNumber(), + exception.getColumnNumber(), + exception.getLocalizedMessage(), + gcParamsMappingXmlFilePath); + errors.add(newError); + } + + @Override + public void fatalError(SAXParseException exception) throws SAXParseException { + // Fatal errors will be reported just when no validation warnings and errors happened. + // In this way we avoid wrong messages of bad form for files that have wrong tags not closed properly + if (errors.size() == 0 && warnings.size() == 0) { + FatalError newFatalError = new FatalError(exception.getLineNumber(), + exception.getColumnNumber(), + exception.getLocalizedMessage(), + gcParamsMappingXmlFilePath); + fatalErrors.add(newFatalError); + } + } + + public List<ValidationIssue> getWarnings() { + return warnings; + } + + public List<ValidationIssue> getErrors() { + return errors; + } + + public List<ValidationIssue> getFatalErrors() { + return fatalErrors; + } + + public boolean hasValidationIssues() { + return errors.size() > 0 || + warnings.size() > 0 || + fatalErrors.size() > 0; + } + +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/params/GcParamsMappingValidatorException.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,148 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.params; + +import java.util.ArrayList; +import java.util.List; + +/** + * Thrown if there were schema validation issues or other problems in a + * gc-params-mapping.xml + * + */ +public class GcParamsMappingValidatorException extends Exception { + + private static final long serialVersionUID = 1L; + private final String xmlFilePath; + private final List<ValidationIssue> warnings; + private final List<ValidationIssue> errors; + private final List<ValidationIssue> fatals; + + /** + * Constructor. + * + * Calls + * {@link #GcParamsMappingValidatorException(String, String, List, List, List, Throwable)} + * with a null cause. + */ + public GcParamsMappingValidatorException(String message, String xmlFilePath, + List<ValidationIssue> errors, List<ValidationIssue> warnings, + List<ValidationIssue> fatals) { + this(message, xmlFilePath, errors, warnings, fatals, null); + } + + /** + * Constructor. + * + * @param message + * A descriptive message. + * @param xmlFilePath + * The gc-params-mapping.xml file path which caused this exception to + * be thrown. + * @param errors + * The list of schema validation errors. + * @param warnings + * The list of (validation) warnings. + * @param fatals + * The list of fatal (validation) errors. + * @param cause + * The underlying exception. May be null. + */ + public GcParamsMappingValidatorException(String message, String xmlFilePath, + List<ValidationIssue> errors, List<ValidationIssue> warnings, + List<ValidationIssue> fatals, Throwable cause) { + super(message); + this.xmlFilePath = xmlFilePath; + this.warnings = warnings; + this.errors = errors; + this.fatals = fatals; + } + + /** + * + * @return The list of all validation issues. + */ + public List<ValidationIssue> getAllErrors() { + List<ValidationIssue> errorsList = new ArrayList<>(); + errorsList.addAll(warnings); + errorsList.addAll(errors); + errorsList.addAll(fatals); + return errorsList; + } + + /** + * + * @return The gc-params-mapping.xml file which failed validation. + */ + public String getXmlFilePath() { + return xmlFilePath; + } + + /** + * Conditions that are not errors or fatal errors as defined by the XML + * recommendation. + * + * @return The list of (validation) warnings. + */ + public List<ValidationIssue> getWarnings() { + return warnings; + } + + /** + * Each validation issue corresponds to the definition of "error" in section + * 1.2 of the W3C XML 1.0 Recommendation. + * + * @return The list of violations of schema validity constraints. + */ + public List<ValidationIssue> getErrors() { + return errors; + } + + /** + * Each validation issue corresponds to the definition of "fatal error" in + * section 1.2 of the W3C XML 1.0 Recommendation. + * + * @return The list of fatal (i.e. non-recoverable) errors. Fatal issues may + * occur if the gc-params-mapping.xml violates well-formedness + * constraints. + */ + public List<ValidationIssue> getFatals() { + return fatals; + } + +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/params/GcParamsParser.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,317 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.params; + +import com.redhat.thermostat.common.Pair; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.ErrorHandler; +import org.xml.sax.SAXException; +import org.xml.sax.SAXParseException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class GcParamsParser { + + private static final String ROOT_NODE_NAME = "gc-params-mapping"; + private static final String COMMON_PARAMS_NODE_NAME = "common"; + private static final String COLLECTOR_NODE_NAME = "collector"; + private static final String COLLECTOR_INFO_NODE_NAME = "collector-info"; + private static final String GC_PARAMS_NODE_NAME = "gc-params"; + private static final String VERSION_NODE_NAME = "version"; + private static final String COMMON_NAME_NODE_NAME = "common-name"; + private static final String COLLECTOR_DISTINCT_NAMES_NODE_NAME = "collector-distinct-names"; + private static final String COLLECTOR_DISTINCT_NAME_NODE_NAME = "collector-name"; + private static final String REFERENCE_URL_NODE_NAME = "url"; + private static final String GC_PARAM_NODE_NAME = "gc-param"; + private static final String FLAG_NODE_NAME = "flag"; + private static final String DESCRIPTION_NODE_NAME = "description"; + + private final InputStream xmlStream; + + public GcParamsParser(InputStream xmlStream) { + this.xmlStream = xmlStream; + } + + public ParseResult parse() throws GcParamsParseException, IOException { + return parse(xmlStream); + } + + static ParseResult parse(InputStream inputStream) throws GcParamsParseException { + try { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setIgnoringComments(true); + DocumentBuilder builder = factory.newDocumentBuilder(); + builder.setErrorHandler(new GcParamsParserErrorHandler()); + Document xmlDoc = builder.parse(inputStream); + Node rootNode = xmlDoc.getFirstChild(); + if (rootNode == null) { + throw new GcParamsParseException("Invalid document, could not identify root node"); + } + return parseRootElement(rootNode); + } catch (ParserConfigurationException | SAXException | IOException e) { + throw new GcParamsParseException(e); + } + } + + static ParseResult parseRootElement(Node rootNode) { + List<Collector> collectors = new ArrayList<>(); + Set<GcParam> commonParams = new HashSet<>(); + if (rootNode.getNodeName().equals(ROOT_NODE_NAME)) { + NodeList nodes = rootNode.getChildNodes(); + for (int i = 0; i < nodes.getLength(); i++) { + Node node = nodes.item(i); + if (node.getNodeName().equals(COLLECTOR_NODE_NAME)) { + collectors.add(parseCollector(node)); + } else if (node.getNodeName().equals(COMMON_PARAMS_NODE_NAME)) { + commonParams.addAll(parseCommonParams(node)); + } + } + } + return new ParseResult(collectors, commonParams); + } + + static Set<GcParam> parseCommonParams(Node gcCommonParamsNode) { + Set<GcParam> gcCommonParams = new HashSet<>(); + if (gcCommonParamsNode.getNodeName().equals(COMMON_PARAMS_NODE_NAME)) { + NodeList nodes = gcCommonParamsNode.getChildNodes(); + for (int i = 0; i < nodes.getLength(); i++) { + Node node = nodes.item(i); + if (node.getNodeName().equals(GC_PARAMS_NODE_NAME)) { + JavaVersionRange allJavaVersionRange + = new JavaVersionRange(JavaVersionRange.VersionPoints.MINIMUM_VERSION, true, + JavaVersionRange.VersionPoints.MAXIMUM_VERSION, true); + gcCommonParams.addAll(parseGcParams(node, allJavaVersionRange)); + } + } + } + return gcCommonParams; + } + + static Collector parseCollector(Node collectorNode) { + CollectorInfo collectorInfo = null; + Set<GcParam> gcParams = Collections.emptySet(); + if (collectorNode.getNodeName().equals(COLLECTOR_NODE_NAME)) { + NodeList nodes = collectorNode.getChildNodes(); + for (int i = 0; i < nodes.getLength(); i++) { + Node node = nodes.item(i); + if (node.getNodeName().equals(COLLECTOR_INFO_NODE_NAME)) { + collectorInfo = parseCollectorInfo(node); + } else if (node.getNodeName().equals(GC_PARAMS_NODE_NAME)) { + gcParams = parseGcParams(node, collectorInfo.getJavaVersionRange()); + } + } + } + return new Collector(collectorInfo, gcParams); + } + + static CollectorInfo parseCollectorInfo(Node collectorInfoNode) { + JavaVersionRange javaVersionRange = null; + String commonName = ""; + Set<String> collectorDistinctNames = Collections.emptySet(); + String referenceUrl = ""; + if (collectorInfoNode.getNodeName().equals(COLLECTOR_INFO_NODE_NAME)) { + NodeList nodes = collectorInfoNode.getChildNodes(); + for (int i = 0; i < nodes.getLength(); i++) { + Node node = nodes.item(i); + if (node.getNodeName().equals(VERSION_NODE_NAME)) { + javaVersionRange = parseVersion(node); + } else if (node.getNodeName().equals(COMMON_NAME_NODE_NAME)) { + commonName = parseCommonName(node); + } else if (node.getNodeName().equals(COLLECTOR_DISTINCT_NAMES_NODE_NAME)) { + collectorDistinctNames = parseDistinctNames(node); + } else if (node.getNodeName().equals(REFERENCE_URL_NODE_NAME)) { + referenceUrl = parseReferenceUrl(node); + } + } + } + return new CollectorInfo(javaVersionRange, commonName, collectorDistinctNames, referenceUrl); + } + + static JavaVersionRange parseVersion(Node versionNode) { + JavaVersionRange javaVersionRange = null; + if (versionNode.getNodeName().equals(VERSION_NODE_NAME)) { + try { + javaVersionRange = JavaVersionRange.fromString(versionNode.getTextContent()); + } catch (JavaVersionRange.InvalidJavaVersionFormatException e) { + throw new GcParamsParseException(e); + } + } + return javaVersionRange; + } + + static String parseCommonName(Node commonNameNode) { + String commonName = ""; + if (commonNameNode.getNodeName().equals(COMMON_NAME_NODE_NAME)) { + commonName = commonNameNode.getTextContent(); + } + return commonName; + } + + static Set<String> parseDistinctNames(Node distinctNamesNode) { + Set<String> distinctNames = new HashSet<>(); + if (distinctNamesNode.getNodeName().equals(COLLECTOR_DISTINCT_NAMES_NODE_NAME)) { + NodeList nodes = distinctNamesNode.getChildNodes(); + for (int i = 0; i < nodes.getLength(); i++) { + Node node = nodes.item(i); + if (node.getNodeName().equals(COLLECTOR_DISTINCT_NAME_NODE_NAME)) { + distinctNames.add(parseDistinctName(node)); + } + } + } + return distinctNames; + } + + static String parseDistinctName(Node distinctNameNode) { + String distinctName = ""; + if (distinctNameNode.getNodeName().equals(COLLECTOR_DISTINCT_NAME_NODE_NAME)) { + distinctName = distinctNameNode.getTextContent(); + } + return distinctName; + } + + static String parseReferenceUrl(Node referenceUrlNode) { + String referenceUrl = ""; + if (referenceUrlNode.getNodeName().equals(REFERENCE_URL_NODE_NAME)) { + referenceUrl = referenceUrlNode.getTextContent(); + } + return referenceUrl; + } + + static Set<GcParam> parseGcParams(Node gcParamsNode, JavaVersionRange inheritedJavaVersionRange) { + Set<GcParam> gcParams = new HashSet<>(); + if (gcParamsNode.getNodeName().equals(GC_PARAMS_NODE_NAME)) { + NodeList nodes = gcParamsNode.getChildNodes(); + for (int i = 0; i < nodes.getLength(); i++) { + Node node = nodes.item(i); + if (node.getNodeName().equals(GC_PARAM_NODE_NAME)) { + gcParams.add(parseGcParam(node, inheritedJavaVersionRange)); + } + } + } + return gcParams; + } + + static GcParam parseGcParam(Node gcParamNode, JavaVersionRange inheritedJavaVersionRange) { + String flag = ""; + String description = ""; + JavaVersionRange javaVersionRange = inheritedJavaVersionRange; + if (gcParamNode.getNodeName().equals(GC_PARAM_NODE_NAME)) { + NodeList nodes = gcParamNode.getChildNodes(); + for (int i = 0; i < nodes.getLength(); i++) { + Node node = nodes.item(i); + if (node.getNodeName().equals(FLAG_NODE_NAME)) { + flag = parseFlag(node); + } else if (node.getNodeName().equals(DESCRIPTION_NODE_NAME)) { + description = parseDescription(node); + } else if (node.getNodeName().equals(VERSION_NODE_NAME)) { + javaVersionRange = parseVersion(node); + } + } + } + return new GcParam(flag, description, javaVersionRange); + } + + static String parseFlag(Node flagNode) { + String flag = ""; + if (flagNode.getNodeName().equals(FLAG_NODE_NAME)) { + flag = flagNode.getTextContent(); + } + return flag; + } + + static String parseDescription(Node descriptionNode) { + String description = ""; + if (descriptionNode.getNodeName().equals(DESCRIPTION_NODE_NAME)) { + description = descriptionNode.getTextContent(); + } + return description.trim().replaceAll("\\s+", " "); + } + + public static class ParseResult extends Pair<List<Collector>, Set<GcParam>> { + + ParseResult(List<Collector> collectors, Set<GcParam> gcCommonParams) { + super(collectors, gcCommonParams); + } + + public List<Collector> getCollectors() { + return super.getFirst(); + } + + public Set<GcParam> getGcCommonParams() { + return super.getSecond(); + } + + } + + private static class GcParamsParserErrorHandler implements ErrorHandler { + @Override + public void warning(SAXParseException e) throws SAXException { + // no-op + } + + @Override + public void error(SAXParseException e) throws SAXException { + throw e; + } + + @Override + public void fatalError(SAXParseException e) throws SAXException { + throw e; + } + } + + public static class GcParamsParseException extends RuntimeException { + public GcParamsParseException(String message) { + super(message); + } + + public GcParamsParseException(Throwable cause) { + super(cause); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/params/JavaVersionRange.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,398 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.params; + +import java.util.Objects; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static java.util.Objects.requireNonNull; + +/** + * Models a range of Java versions, using maven version format: + * https://maven.apache.org/enforcer/enforcer-rules/versionRanges.html + * + * A single, exact version number of "w.x.y.z" is considered as a short form for the range "[w.x.y.z,w.x.y.z]" + */ +public class JavaVersionRange implements Comparable<JavaVersionRange> { + + private static final String LBRACK = "([\\[\\(])"; + private static final String RBRACK = "([\\]\\)])"; + private static final String NUM = "([0-9]+)"; + private static final String DOT = "\\."; + // Allow for '_' and '.' as delimiters; Do *not* use "-" as + // delimiter since that is reserved for the pre-release snippet. + private static final String UPDATE_DELIMITER = "[._]"; + private static final String COMMA = ","; + private static final String UPDATE_PATTERN = UPDATE_DELIMITER + NUM; + private static final String OPTIONAL_UPDATE_PATTERN = "(?:" + UPDATE_PATTERN + ")?"; // non-capturing group + private static final String PRE_RELEASE_PATTERN = "-([0-9a-zA-Z]+)"; + private static final String OPTIONAL_PRE_RELEASE_PATTERN = "(?:" + PRE_RELEASE_PATTERN + ")?"; // non-capturing group + private static final String OPTIONAL_VENDOR_PATTERN = OPTIONAL_PRE_RELEASE_PATTERN; // non-capturing group + private static final String OPTIONAL_SUFFIX = "(" + OPTIONAL_UPDATE_PATTERN + OPTIONAL_PRE_RELEASE_PATTERN + OPTIONAL_VENDOR_PATTERN + ")"; + private static final String SINGLE_VERSION_PATTERN_STRING = NUM + DOT + NUM + DOT + NUM + OPTIONAL_SUFFIX; + private static final String VERSION_PATTERN_STRING = LBRACK + "?" + "(" + SINGLE_VERSION_PATTERN_STRING + ")" + RBRACK + "?"; + private static final String RANGE_PATTERN_STRING = LBRACK + "(" + SINGLE_VERSION_PATTERN_STRING + ")?" + COMMA + + "(" + SINGLE_VERSION_PATTERN_STRING + ")?" + RBRACK; + private static final Pattern VERSION_PATTERN = Pattern.compile(VERSION_PATTERN_STRING); + private static final Pattern RANGE_PATTERN = Pattern.compile(RANGE_PATTERN_STRING); + + private final boolean lowerInclusive, upperInclusive; + private final VersionPoints lowerBound, upperBound; + + public JavaVersionRange(int major, int minor, int micro, int update) { + this(new VersionPoints(major, minor, micro, update)); + } + + public JavaVersionRange(VersionPoints versionPoints) { + this(versionPoints, true, versionPoints, true); + } + + public JavaVersionRange(VersionPoints lowerBound, boolean lowerInclusive, VersionPoints upperBound, boolean upperInclusive) { + this.lowerBound = requireNonNull(lowerBound); + this.upperBound = requireNonNull(upperBound); + this.lowerInclusive = lowerInclusive; + this.upperInclusive = upperInclusive; + if (lowerBound.compareTo(upperBound) > 0) { + throw new InvalidJavaVersionFormatException("Range must ascend"); + } + if (lowerBound.equals(upperBound) && !isLowerBoundInclusive() && !isUpperBoundInclusive()) { + throw new InvalidJavaVersionFormatException("Range is empty: " + this); + } + } + + public static JavaVersionRange fromString(String javaVersionString) { + validateFormat(javaVersionString); + Matcher singleVersionMatcher = VERSION_PATTERN.matcher(javaVersionString); + if (singleVersionMatcher.matches()) { + VersionPoints points = VersionPoints.fromString(singleVersionMatcher.group(2)); + String leftBracket = singleVersionMatcher.group(1); + String rightBracket = singleVersionMatcher.group(10); + if (leftBracket == null && rightBracket == null) { + return new JavaVersionRange(points); + } else if (leftBracket != null && rightBracket != null) { + return new JavaVersionRange(points, isInclusive(leftBracket.charAt(0)), points, isInclusive(rightBracket.charAt(0))); + } else { + throw new InvalidJavaVersionFormatException("Unmatched bracket in version string: " + javaVersionString); + } + } else { + Matcher rangeVersionMatcher = RANGE_PATTERN.matcher(javaVersionString); + if (rangeVersionMatcher.matches()) { + String lower = rangeVersionMatcher.group(2); + String upper = rangeVersionMatcher.group(10); + VersionPoints lowerBound, upperBound; + if (lower == null && upper == null) { + throw new InvalidJavaVersionFormatException("Cannot specify a range without any bounds"); + } else if (lower == null) { + lowerBound = VersionPoints.MINIMUM_VERSION; + upperBound = VersionPoints.fromString(upper); + } else if (upper == null) { + lowerBound = VersionPoints.fromString(lower); + upperBound = VersionPoints.MAXIMUM_VERSION; + } else { + lowerBound = VersionPoints.fromString(lower); + upperBound = VersionPoints.fromString(upper); + } + String leftBracket = rangeVersionMatcher.group(1); + String rightBracket = rangeVersionMatcher.group(18); + return new JavaVersionRange(lowerBound, isInclusive(leftBracket.charAt(0)), upperBound, isInclusive(rightBracket.charAt(0))); + } else { + throw new InvalidJavaVersionFormatException(javaVersionString); + // shouldn't reach here - if it doesn't match either pattern then validateFormat should have caught it already + } + } + } + + static boolean isInclusive(char brack) { + if (brack == '[' || brack == ']') { + return true; + } else if (brack == '(' || brack == ')') { + return false; + } else { + throw new IllegalArgumentException(Character.toString(brack)); + } + } + + public boolean isRange() { + return !lowerBound.equals(upperBound); + } + + public JavaVersionRange getLowerBound() { + return new JavaVersionRange(lowerBound); + } + + public JavaVersionRange getUpperBound() { + return new JavaVersionRange(upperBound); + } + + public boolean isLowerBoundInclusive() { + return lowerInclusive; + } + + public boolean isUpperBoundInclusive() { + return upperInclusive; + } + + public boolean contains(JavaVersionRange other) { + if (!isRange()) { + return this.equals(other); + } + + final int lower = lowerBound.compareTo(other.lowerBound); + final int upper = upperBound.compareTo(other.upperBound); + + if (lower > 0 || upper < 0) { + return false; + } + + if (lower == 0) { + return isLowerBoundInclusive(); + } + + if (upper == 0) { + return isUpperBoundInclusive(); + } + + return true; + } + + @Override + public int compareTo(JavaVersionRange javaVersionRange) { + if (this.equals(javaVersionRange)) { + return 0; + } + if (javaVersionRange == null) { + return 1; + } + if (isRange() && javaVersionRange.isRange()) { + return -1; + } + + return lowerBound.compareTo(javaVersionRange.lowerBound); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + JavaVersionRange javaVersionRange = (JavaVersionRange) o; + + return lowerBound.equals(javaVersionRange.lowerBound) && upperBound.equals(javaVersionRange.upperBound) + && isLowerBoundInclusive() == javaVersionRange.isLowerBoundInclusive() + && isUpperBoundInclusive() == javaVersionRange.isUpperBoundInclusive(); + } + + @Override + public int hashCode() { + return Objects.hash(lowerBound, upperBound, lowerInclusive, upperInclusive); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + + if (isLowerBoundInclusive()) { + sb.append('['); + } else { + sb.append('('); + } + + sb.append(lowerBound.toString()); + if (isRange()) { + sb.append(','); + sb.append(upperBound.toString()); + } + + if (isUpperBoundInclusive()) { + sb.append(']'); + } else { + sb.append(')'); + } + + return sb.toString(); + } + + static void validateFormat(String rawVersion) { + if (rawVersion == null) { + throw new InvalidJavaVersionFormatException(null); + } + Matcher singleVersionMatcher = VERSION_PATTERN.matcher(rawVersion); + Matcher rangeMatcher = RANGE_PATTERN.matcher(rawVersion); + if (!(singleVersionMatcher.matches() || rangeMatcher.matches())) { + throw new InvalidJavaVersionFormatException(rawVersion); + } + } + + public static class VersionPoints implements Comparable<VersionPoints> { + + static final VersionPoints MINIMUM_VERSION = new VersionPoints(0, 0, 0, 0); + static final VersionPoints MAXIMUM_VERSION = new VersionPoints(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE); + + private final int major; + private final int minor; + private final int micro; + private final int update; + private final String preRelease; + + public VersionPoints(int major, int minor, int micro, int update) { + this(major, minor, micro, update, ""); + } + + private VersionPoints(int major, int minor, int micro, int update, String preReleaseString) { + this.major = requirePositive(major); + this.minor = requirePositive(minor); + this.micro = requirePositive(micro); + this.update = requirePositive(update); + this.preRelease = Objects.requireNonNull(preReleaseString); + } + + static int requirePositive(int i) { + if (i < 0) { + throw new IllegalArgumentException("Negative arguments are not permitted"); + } + return i; + } + + static VersionPoints fromString(String string) { + Matcher matcher = Pattern.compile(SINGLE_VERSION_PATTERN_STRING).matcher(string); + if (!matcher.matches()) { + throw new InvalidJavaVersionFormatException(string); + } + int major = Integer.parseInt(matcher.group(1)); + int minor = Integer.parseInt(matcher.group(2)); + int micro = Integer.parseInt(matcher.group(3)); + String optionalSuffix = matcher.group(4); // contains both, update and pre-release + String updateStr = matcher.group(5); + String preRelease = matcher.group(6); + if (isNullOrEmpty(optionalSuffix)) { + // Neither update nor pre-release in version string + return new VersionPoints(major, minor, micro, 0); + } + if (isNullOrEmpty(updateStr)) { + // No update provided but pre-release given + return new VersionPoints(major, minor, micro, 0, preRelease); + } + if (isNullOrEmpty(preRelease)) { + // Update given, but no pre-release + int update = Integer.parseInt(updateStr); + return new VersionPoints(major, minor, micro, update); + } + // Both update and pre-release given + int update = Integer.parseInt(updateStr); + return new VersionPoints(major, minor, micro, update, preRelease); + } + + private static boolean isNullOrEmpty(String matchedString) { + return matchedString == null || matchedString.isEmpty(); + } + + public int getMajor() { + return major; + } + + public int getMinor() { + return minor; + } + + public int getMicro() { + return micro; + } + + public int getUpdate() { + return update; + } + + public String getPreRelease() { + return preRelease; + } + + @Override + public int compareTo(VersionPoints versionPoints) { + int majorComparison = Integer.compare(getMajor(), versionPoints.getMajor()); + if (majorComparison != 0) { + return majorComparison; + } + int minorComparison = Integer.compare(getMinor(), versionPoints.getMinor()); + if (minorComparison != 0) { + return minorComparison; + } + int microComparison = Integer.compare(getMicro(), versionPoints.getMicro()); + if (microComparison != 0) { + return microComparison; + } + return Integer.compare(getUpdate(), versionPoints.getUpdate()); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + VersionPoints that = (VersionPoints) o; + + return Objects.equals(major, that.major) + && Objects.equals(minor, that.minor) + && Objects.equals(micro, that.micro) + && Objects.equals(update, that.update); + } + + @Override + public int hashCode() { + return Objects.hash(major, minor, micro, update); + } + + @Override + public String toString() { + return getMajor() + "." + + getMinor() + "." + + getMicro() + "." + + getUpdate() + + (getPreRelease().isEmpty() ? "" : "-" + getPreRelease()); + } + } + + public static class InvalidJavaVersionFormatException extends RuntimeException { + public InvalidJavaVersionFormatException(String message) { + super("Invalid version string: " + message); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/params/ValidationErrorsFormatter.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,137 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.params; + +import com.redhat.thermostat.shared.locale.Translate; +import com.redhat.thermostat.vm.gc.agent.internal.LocaleResources; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Formats XML validation issues to strings. + * + * @see GcParamsMappingValidatorException + */ +public class ValidationErrorsFormatter { + + private enum ErrorType { + WARNING, + ERROR, + FATALERROR; + } + + private Map<ErrorType, LocaleResources> translateKeys; + private static final Translate<LocaleResources> translator = LocaleResources.createLocalizer(); + + public ValidationErrorsFormatter() { + + translateKeys = new HashMap<>(); + translateKeys.put(ErrorType.ERROR, LocaleResources.VALIDATION_ERROR); + translateKeys.put(ErrorType.WARNING, LocaleResources.VALIDATION_WARNING); + translateKeys.put(ErrorType.FATALERROR, LocaleResources.VALIDATION_FATAL_ERROR); + + } + + public String format(List<ValidationIssue> list) { + StringBuilder outputBuilder = new StringBuilder(); + for (ValidationIssue ave : list) { + outputBuilder.append(formatError(ave)); + } + return outputBuilder.toString(); + } + + private StringBuilder formatError(ValidationIssue ave) { + StringBuilder builder = new StringBuilder(); + + String LS = System.lineSeparator(); + String firstLine = null; + String secondLine = null; + String thirdLine = null; + String errorLine = null; + String pointer = ""; + String absolutePath = ave.getXmlFilePath(); + + try { + BufferedReader br = new BufferedReader(new FileReader(absolutePath)); + for (int i = 1; i < ave.getLineNumber()-3; i++) { + br.readLine(); + } + firstLine = br.readLine(); + secondLine = br.readLine(); + thirdLine = br.readLine(); + errorLine = br.readLine(); + + for (int j = 1; j < ave.getColumnNumber()-1; j++) { + pointer = pointer.concat(" "); + } + pointer = pointer.concat("^"); + br.close(); + } catch (IOException exception) { + // if br fails to close + } + + builder.append(translator.localize( + translateKeys.get(ErrorType.valueOf(ave.getClass().getSimpleName().toUpperCase())), + absolutePath, + Integer.toString(ave.getLineNumber()), + Integer.toString(ave.getColumnNumber())).getContents()); + + builder.append(formatMessage(ave.getMessage())).append(LS).append(LS); + builder.append(firstLine).append(LS); + builder.append(secondLine).append(LS); + builder.append(thirdLine).append(LS); + builder.append(errorLine).append(LS); + builder.append(pointer).append(LS); + + return builder; + } + + private String formatMessage(String message) { + String[] arguments = message.split("\"http://icedtea.classpath.org/thermostat/gc-params-mapping/v1.0\":"); + StringBuilder sb = new StringBuilder(); + for (String argument : arguments) { + sb.append(argument); + } + return sb.toString(); + } + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/params/ValidationIssue.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,70 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.params; + +/** + * Represents XML schema validation issues. + * + */ +public interface ValidationIssue { + + /** + * + * @return The line number where the issue occurred. + */ + int getLineNumber(); + + /** + * + * @return The column number where the issue occurred. + */ + int getColumnNumber(); + + /** + * + * @return A message describing the issue. + */ + String getMessage(); + + /** + * + * @return The xml file path which caused the issue. + */ + String getXmlFilePath(); + +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/main/java/com/redhat/thermostat/vm/gc/agent/params/Warning.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,50 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.params; + +public class Warning extends AbstractValidationError { + + Warning(int lineNumber, int columnNumber, String message, String gcParamsMappingXmlFilePath) { + super(lineNumber, columnNumber, message, gcParamsMappingXmlFilePath); + } + + @Override + public String getName() { + return this.getClass().getSimpleName(); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/main/resources/com/redhat/thermostat/vm/gc/agent/gc-params-mapping.xml Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,737 @@ +<?xml version="1.0"?> +<!-- + + Copyright 2012-2017 Red Hat, Inc. + + This file is part of Thermostat. + + Thermostat is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2, or (at your + option) any later version. + + Thermostat is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Thermostat; see the file COPYING. If not see + <http://www.gnu.org/licenses/>. + + Linking this code with other modules is making a combined work + based on this code. Thus, the terms and conditions of the GNU + General Public License cover the whole combination. + + As a special exception, the copyright holders of this code give + you permission to link this code with independent modules to + produce an executable, regardless of the license terms of these + independent modules, and to copy and distribute the resulting + executable under terms of your choice, provided that you also + meet, for each linked independent module, the terms and conditions + of the license of that module. An independent module is a module + which is not derived from or based on this code. If you modify + this code, you may extend this exception to your version of the + library, but you are not obligated to do so. If you do not wish + to do so, delete this exception statement from your version. + +--> +<gc-params-mapping xmlns="http://icedtea.classpath.org/thermostat/gc-params-mapping/v1.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://icedtea.classpath.org/thermostat/gc-params-mapping/v1.0 gc-params-mapping.xsd"> + + <!-- Reference documentation --> + <!-- http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html --> + <!-- http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/G1GettingStarted/index.html --> + <!-- http://www.slideshare.net/SimoneBordet/g1-garbage-collector-details-and-tuning --> + <!-- http://www.oracle.com/technetwork/articles/java/g1gc-1984535.html --> + <!-- http://icedtea.classpath.org/hg/icedtea7-forest/hotspot/file/aea5b566bfab/src/share/vm/gc_implementation/g1/g1_globals.hpp --> + + <common> + <gc-params> + <gc-param> + <flag>PrintGC</flag> + <description>Print messages when garbage collection takes place</description> + </gc-param> + <gc-param> + <flag>PrintGCDetails</flag> + <description>Print more details in garbage collection messages</description> + </gc-param> + <gc-param> + <flag>PrintGCTimeStamps</flag> + <description>Print timestamps in garbage collection messages</description> + </gc-param> + <gc-param> + <flag>UseGCLogFileRotation</flag> + <description>Enable GC log file rotation. Requires -Xloggc:filename, which enables logging GC messages to + file + </description> + </gc-param> + <gc-param> + <flag>NumberOfGClogFiles</flag> + <description>The number of rotating log files to use. Must be greater than or equal to 1. The default is 1. + </description> + </gc-param> + <gc-param> + <flag>GCLogFileSize</flag> + <description>The maximum log file size in bytes after which the log files will be rotated. Must be greater + than or equal to 8K. The default is 8K. + </description> + </gc-param> + </gc-params> + </common> + + <collector> + <collector-info> + <version>[1.4.2.0,]</version> + <common-name>Serial Collector</common-name> + <collector-distinct-names> + <collector-name>MSC</collector-name> + <collector-name>Copy</collector-name> + </collector-distinct-names> + <url>http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#available_collectors</url> + </collector-info> + <gc-params> + <gc-param> + <flag>UseSerialGC</flag> + <description>Use serial garbage collection</description> + </gc-param> + <gc-param> + <flag>ScavengeBeforeFullGC</flag> + <description>Do garbage collection on young generations before performing full GC cycles</description> + </gc-param> + <gc-param> + <flag>UseGCOverheadLimit</flag> + <description>Limit the proportion of time that the VM will spend in garbage collection before an OutOfMemory + error is thrown + </description> + <version>[1.6.0.0,]</version> + </gc-param> + <gc-param> + <flag>MaxHeapFreeRatio</flag> + <description>The maximum percentage of heap size free after a garbage collection cycle to avoid heap + shrinking. The default is 70 + </description> + </gc-param> + <gc-param> + <flag>MinHeapFreeRatio</flag> + <description>The minimum percentage of heap size free after a garbage collection cycle to avoid heap + expansion. The default is 40 + </description> + </gc-param> + <gc-param> + <flag>MaxNewSize</flag> + <description>The maximum size of the new generation, in bytes. Since 1.4, this is computed as a function of + NewRatio + </description> + </gc-param> + <gc-param> + <flag>MaxPermSize</flag> + <description>The maximum size of the permanent generation, in bytes. Since 5.0, 64-bit VMs are scaled 30% + larger + </description> + <version>[1.4.2.0,1.8.0.0)</version> + </gc-param> + <gc-param> + <flag>NewRatio</flag> + <description>Ratio of old and new generation sizes. The default is 2</description> + </gc-param> + <gc-param> + <flag>NewSize</flag> + <description>The default size of the new generation, in bytes. Since 5.0, 64-bit VMs are scaled 30% larger + </description> + </gc-param> + <gc-param> + <flag>SurvivorRatio</flag> + <description>Ratio of eden and survivor space. The default is 8</description> + </gc-param> + <gc-param> + <flag>TargetSurvivorRatio</flag> + <description>The target percentage of survivor space in use after a scavenge</description> + </gc-param> + </gc-params> + </collector> + + <collector> + <collector-info> + <version>[1.6.0.14,]</version> + <common-name>Garbage-First Collector (G1)</common-name> + <collector-distinct-names> + <collector-name>G1 incremental collections</collector-name> + </collector-distinct-names> + <url>http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#available_collectors</url> + </collector-info> + <gc-params> + <gc-param> + <flag>UseG1GC</flag> + <description>use the G1 Garbage Collector</description> + </gc-param> + <gc-param> + <flag>MaxGCPauseMillis</flag> + <description>the max GC pause time goal in milliseconds that G1 will attempt to meet. The default is 200 + </description> + </gc-param> + <gc-param> + <flag>InitiatingHeapOccupancyParent</flag> + <description>percentage of total heap occupancy at which a GC cycle will be triggered. The default is 45 + </description> + </gc-param> + <gc-param> + <flag>GCPauseIntervalMillis</flag> + <description>the time interval over which GC pauses totaling up to MaxGCPauseMillis may take place</description> + </gc-param> + <gc-param> + <flag>NewRatio</flag> + <description>ratio of old a new generation sizes. The default is 2</description> + </gc-param> + <gc-param> + <flag>SurvivorRatio</flag> + <description>Ratio of eden and survivor space. The default is 8</description> + </gc-param> + <gc-param> + <flag>MaxTenuringThreshold</flag> + <description>Maximum value for threshold of object tenuring. The default is 15</description> + </gc-param> + <gc-param> + <flag>MaxNewSize</flag> + <description>The maximum size of the new generation, in bytes. Since 1.4, this is computed as a function of + NewRatio + </description> + </gc-param> + <gc-param> + <flag>MaxPermSize</flag> + <description>The maximum size of the permanent generation, in bytes. Since 5.0, 64-bit VMs are scaled 30% + larger + </description> + <version>[1.6.0.14,1.8.0.0)</version> + </gc-param> + <gc-param> + <flag>ParallelGCThreads</flag> + <description>The number of threads to use during the parallel phase of GC</description> + </gc-param> + <gc-param> + <flag>ConcGCThreads</flag> + <description>The number of concurrent GC threads to use</description> + </gc-param> + <gc-param> + <flag>UseGCOverheadLimit</flag> + <description>Limit the proportion of time that the VM will spend in garbage collection before an OutOfMemory + error is thrown + </description> + </gc-param> + <gc-param> + <flag>ScavengeBeforeFullGC</flag> + <description>Do garbage collection on young generations before performing full GC cycles</description> + </gc-param> + <gc-param> + <flag>MaxHeapFreeRatio</flag> + <description>The maximum percentage of heap size free after a garbage collection cycle to avoid heap + shrinking. The default is 70 + </description> + </gc-param> + <gc-param> + <flag>MinHeapFreeRatio</flag> + <description>The minimum percentage of heap size free after a garbage collection cycle to avoid heap + expansion. The default is 40 + </description> + </gc-param> + <gc-param> + <flag>NewSize</flag> + <description>The default size of the new generation, in bytes. Since 5.0, 64-bit VMs are scaled 30% + larger + </description> + </gc-param> + <gc-param> + <flag>TargetSurvivorRatio</flag> + <description>The target percentage of survivor space in use after a scavenge</description> + </gc-param> + <gc-param> + <flag>G1ConcMarkStepDurationMillis</flag> + <description>The target duration of individual concurrent marking steps</description> + </gc-param> + <gc-param> + <flag>G1ConcRSHotCardLimit</flag> + <description>The threshold that defines a "hot card"</description> + </gc-param> + <gc-param> + <flag>G1ConcRSLogCacheSize</flag> + <description>Log base 2 of the size of concurrent Remembered Set "hot card" cache</description> + </gc-param> + <gc-param> + <flag>G1ConcRefinementGreenZone</flag> + <description>The number of update buffers that are left in the queue by the concurrent processing threads</description> + </gc-param> + <gc-param> + <flag>G1ConcRefinementYellowZone</flag> + <description>Number of enqueued update buffers that will trigger concurrent processing</description> + </gc-param> + <gc-param> + <flag>G1ConcRefinementRedZone</flag> + <description>Number of enqueued update buffers that will trigger concurrent processing + instead of enqueueing them</description> + </gc-param> + <gc-param> + <flag>G1UseAdaptiveConcRefinement</flag> + <description>Select green, yellow, and red zone sizes adaptively to meet the pause time requirements</description> + </gc-param> + <gc-param> + <flag>G1ConcRefinementServiceIntervalMillis</flag> + <description>The last concurrent refinement thread wakes up every specified number of milliseconds to do miscellaneous work</description> + </gc-param> + <gc-param> + <flag>G1ConcRefinementThreads</flag> + <description>The number of threads to use for concurrently updating GC remembered sets. If not set then the default is ParallelGCThreads + 1</description> + </gc-param> + <gc-param> + <flag>G1ConcRefinementThresholdStep</flag> + <description>Each time the remembered set update queue increases by this amount, activate the next refinement thread, if available</description> + </gc-param> + <gc-param> + <flag>G1ConfidencePercent</flag> + <description>Confidence level for MMU/pause predictions</description> + </gc-param> + <gc-param> + <flag>G1MarkingOverheadPercent</flag> + <description>Overhead of concurrent marking</description> + </gc-param> + <gc-param> + <flag>G1UseConcMarkReferenceProcessing</flag> + <description>If true, enable reference discovery during concurrent marking and reference processing at the end + of remark</description> + </gc-param> + <gc-param> + <flag>G1HeapRegionSize</flag> + <description>The size of G1 heap subdivisions. Minimum 1Mb, maximum 32Mb</description> + </gc-param> + <gc-param> + <flag>G1HeapWastePercent</flag> + <description>The maximum threshold of heap space which is permitted to be wasted. GC cycles will not take + place when the reclaimable space as a percentage is below this threshold. The default is 10 percent</description> + </gc-param> + <gc-param> + <flag>G1MixedGCCountTarget</flag> + <description>The number of "mixed" garbage collection cycles to perform after a marking cycle. The default is 8</description> + </gc-param> + <gc-param> + <flag>G1MixedGCLiveThresholdPercent</flag> + <description>The percent of "live" objects in old generation regions under which a mixed GC will be performed. + The default is 85</description> + </gc-param> + <gc-param> + <flag>G1HeapWastePercent</flag> + <description>The threshold percentage of wasted heap space. The default is 5</description> + </gc-param> + <gc-param> + <flag>G1RSetRegionEntries</flag> + <description>The maximum number of regions</description> + </gc-param> + <gc-param> + <flag>G1RSetScanBlockSize</flag> + <description>Size of a work unit of cards claimed by a worker thread during Remembered Set scanning</description> + </gc-param> + <gc-param> + <flag>G1RSetSparseRegionEntries</flag> + <description>Maximum number of entries per region in a sparse table</description> + </gc-param> + <gc-param> + <flag>G1RSetUpdatingPauseTimePercent</flag> + <description>A target percentage of time that is allowed to be spent on processing Remembered Set update buffers during the collection pause</description> + </gc-param> + <gc-param> + <flag>G1RefProcDrainInterval</flag> + <description>The number of discovered reference objects to process before draining concurrent marking work queues</description> + </gc-param> + <gc-param> + <flag>G1ReservePercent</flag> + <description>The percentage of amount of heap space reserved to reduce promotion failure. The default is 10</description> + </gc-param> + <gc-param> + <flag>G1SATBBufferEnqueueingThresholdPercent</flag> + <description>Before enqueueing them, each mutator thread tries to do some + filtering on the SATB buffers it generates. If post-filtering + the percentage of retained entries is over this threshold + the buffer will be enqueued for processing. A value of 0 + specifies that mutator threads should not do such filtering</description> + </gc-param> + <gc-param> + <flag>G1SATBBufferSize</flag> + <description>Number of entries in a SATB log buffer</description> + </gc-param> + <gc-param> + <flag>G1UpdateBufferSize</flag> + <description>Size of an update buffer</description> + </gc-param> + <gc-param> + <flag>G1ExpandByPercentOfAvailable</flag> + <description>When expanding, the percentage of uncommitted space to claim</description> + </gc-param> + </gc-params> + </collector> + + <collector> + <collector-info> + <version>[1.4.1.0,]</version> + <common-name>Parallel Collector</common-name> + <collector-distinct-names> + <collector-name>PSParallelCompact</collector-name> + <collector-name>PSScavenge</collector-name> + </collector-distinct-names> + <url>http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#available_collectors</url> + </collector-info> + <gc-params> + <gc-param> + <flag>UseParallelGC</flag> + <description>Use parallel garbage collection for the young generation</description> + </gc-param> + <gc-param> + <flag>UseParallelOldGC</flag> + <description>Use parallel garbage collection for the both the young and old generation (automatically enables UseParallelGC)</description> + <version>[1.5.0.6,]</version> + </gc-param> + <gc-param> + <flag>UseGCOverheadLimit</flag> + <description>Limit the proportion of time that the VM will spend in garbage collection before an OutOfMemory + error is thrown</description> + <version>[1.6.0.0,]</version> + </gc-param> + <gc-param> + <flag>ScavengeBeforeFullGC</flag> + <description>Do garbage collection on young generations before performing full GC cycles</description> + </gc-param> + <gc-param> + <flag>MaxHeapFreeRatio</flag> + <description>The maximum percentage of heap size free after a garbage collection cycle to avoid heap + shrinking. The default is 70</description> + </gc-param> + <gc-param> + <flag>MinHeapFreeRatio</flag> + <description>The minimum percentage of heap size free after a garbage collection cycle to avoid heap + expansion. The default is 40</description> + </gc-param> + <gc-param> + <flag>MaxNewSize</flag> + <description>The maximum size of the new generation, in bytes. Since 1.4, this is computed as a function of + NewRatio</description> + </gc-param> + <gc-param> + <flag>MaxPermSize</flag> + <description>The maximum size of the permanent generation, in bytes. Since 5.0, 64-bit VMs are scaled 30% + larger</description> + <version>[1.4.1.0,1.8.0.0)</version> + </gc-param> + <gc-param> + <flag>NewRatio</flag> + <description>ratio of old a new generation sizes. The default is 2</description> + </gc-param> + <gc-param> + <flag>NewSize</flag> + <description>The default size of the new generation, in bytes. Since 5.0, 64-bit VMs are scaled 30% larger</description> + </gc-param> + <gc-param> + <flag>SurvivorRatio</flag> + <description>Ratio of eden and survivor space. The default is 8</description> + </gc-param> + <gc-param> + <flag>TargetSurvivorRatio</flag> + <description>The target percentage of survivor space in use after a scavenge</description> + </gc-param> + <gc-param> + <flag>ParallelGCThreads</flag> + <description>The number of threads to use during the parallel phase of GC</description> + </gc-param> + </gc-params> + </collector> + + <collector> + <collector-info> + <version>[1.4.1.0,]</version> + <common-name>Concurrent Collector (Concurrent Mark and Sweep)</common-name> + <collector-distinct-names> + <collector-name>CMS</collector-name> + <collector-name>PCopy</collector-name> + </collector-distinct-names> + <url>http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#available_collectors</url> + </collector-info> + <gc-params> + <gc-param> + <flag>UseConcMarkSweepGC</flag> + <description>Use the Concurrent Mark and Sweep collector for the old generation</description> + </gc-param> + <gc-param> + <flag>UseGCOverheadLimit</flag> + <description>Limit the proportion of time that the VM will spend in garbage collection before an OutOfMemory + error is thrown</description> + <version>[1.6.0.0,]</version> + </gc-param> + <gc-param> + <flag>ScavengeBeforeFullGC</flag> + <description>Do garbage collection on young generations before performing full GC cycles</description> + </gc-param> + <gc-param> + <flag>MaxHeapFreeRatio</flag> + <description>The maximum percentage of heap size free after a garbage collection cycle to avoid heap + shrinking. The default is 70</description> + </gc-param> + <gc-param> + <flag>MinHeapFreeRatio</flag> + <description>The minimum percentage of heap size free after a garbage collection cycle to avoid heap + expansion. The default is 40</description> + </gc-param> + <gc-param> + <flag>MaxNewSize</flag> + <description>The maximum size of the new generation, in bytes. Since 1.4, this is computed as a function of + NewRatio</description> + </gc-param> + <gc-param> + <flag>MaxPermSize</flag> + <description>The maximum size of the permanent generation, in bytes. Since 5.0, 64-bit VMs are scaled 30% + larger</description> + <version>[1.4.1.0,1.8.0.0)</version> + </gc-param> + <gc-param> + <flag>NewRatio</flag> + <description>ratio of old a new generation sizes. The default is 2</description> + </gc-param> + <gc-param> + <flag>NewSize</flag> + <description>The default size of the new generation, in bytes. Since 5.0, 64-bit VMs are scaled 30% + larger</description> + </gc-param> + <gc-param> + <flag>SurvivorRatio</flag> + <description>Ratio of eden and survivor space. The default is 8</description> + </gc-param> + <gc-param> + <flag>TargetSurvivorRatio</flag> + <description>The target percentage of survivor space in use after a scavenge</description> + </gc-param> + </gc-params> + </collector> + + <collector> + <collector-info> + <version>[1.0.0.0,]</version> + <common-name>Mark Sweep Compact Collector</common-name> + <collector-distinct-names> + <collector-name>MSC</collector-name> + <collector-name>PCopy</collector-name> + </collector-distinct-names> + <url>http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#available_collectors</url> + </collector-info> + <gc-params> + <gc-param> + <flag>UseGCOverheadLimit</flag> + <description>Limit the proportion of time that the VM will spend in garbage collection before an OutOfMemory + error is thrown + </description> + <version>[1.6.0.0,]</version> + </gc-param> + <gc-param> + <flag>ScavengeBeforeFullGC</flag> + <description>Do garbage collection on young generations before performing full GC cycles</description> + <version>[1.4.1.0,]</version> + </gc-param> + <gc-param> + <flag>MaxHeapFreeRatio</flag> + <description>The maximum percentage of heap size free after a garbage collection cycle to avoid heap + shrinking. The default is 70 + </description> + </gc-param> + <gc-param> + <flag>MinHeapFreeRatio</flag> + <description>The minimum percentage of heap size free after a garbage collection cycle to avoid heap + expansion. The default is 40 + </description> + </gc-param> + <gc-param> + <flag>MaxNewSize</flag> + <description>The maximum size of the new generation, in bytes. Since 1.4, this is computed as a function of + NewRatio + </description> + </gc-param> + <gc-param> + <flag>MaxPermSize</flag> + <description>The maximum size of the permanent generation, in bytes. Since 5.0, 64-bit VMs are scaled 30% + larger + </description> + <version>[1.0.0.0,1.8.0.0)</version> + </gc-param> + <gc-param> + <flag>NewRatio</flag> + <description>ratio of old a new generation sizes. The default is 2</description> + </gc-param> + <gc-param> + <flag>NewSize</flag> + <description>The default size of the new generation, in bytes. Since 5.0, 64-bit VMs are scaled 30% + larger + </description> + </gc-param> + <gc-param> + <flag>SurvivorRatio</flag> + <description>Ratio of eden and survivor space. The default is 8</description> + </gc-param> + <gc-param> + <flag>TargetSurvivorRatio</flag> + <description>The target percentage of survivor space in use after a scavenge</description> + </gc-param> + </gc-params> + </collector> + + <collector> + <collector-info> + <version>[1.8.0.0,]</version> + <common-name>Shenandoah Collector</common-name> + <collector-distinct-names> + <collector-name>Shenandoah concurrent phases</collector-name> + <collector-name>Shenandoah pauses</collector-name> + <collector-name>Shenandoah full GC pauses</collector-name> + </collector-distinct-names> + <url>http://hg.openjdk.java.net/shenandoah/jdk8u/hotspot/file/c1b5450e17dd/src/share/vm/gc_implementation/shenandoah/shenandoah_globals.hpp</url> + </collector-info> + <gc-params> + <gc-param> + <flag>UseShenandoahGC</flag> + <description>Use the Shenandoah garbage collector. Default is false</description> + </gc-param> + <gc-param> + <flag>ShenandoahAllocReserveRegions</flag> + <description> + How many regions should be kept as allocation reserve, before + Shenandoah attempts to grow the heap. Default is 10 + </description> + </gc-param> + <gc-param> + <flag>ShenandoahAllocationThreshold</flag> + <description> + Sets the number of bytes allocated since last GC cycle before + a region can enter the concurrent marking + phase. Applies to Shenandoah GC dynamic Heuristic mode only + (ignored otherwise) + </description> + </gc-param> + <gc-param> + <flag>ShenandoahFreeThreshold</flag> + <description> + Set the percentage of heap free in relation to the total + capacity before a region can enter the concurrent marking + phase. Applies to Shenandoah GC dynamic Heuristic mode only + (ignored otherwise). Default is 25 + </description> + </gc-param> + <gc-param> + <flag>ShenandoahGCHeuristics</flag> + <description> + The heuristics to use in Shenandoah GC; possible values: + statusquo, aggressive, halfway, lazy, dynamic. Default is + dynamic + </description> + </gc-param> + <gc-param> + <flag>ShenandoahGCVerbose</flag> + <description> + Verbose information about the Shenandoah garbage collector. + Default is false + </description> + </gc-param> + <gc-param> + <flag>ShenandoahGarbageThreshold</flag> + <description> + Sets the percentage of garbage a region need to contain before + it can be marked for collection. Applies to + Shenandoah GC dynamic Heuristic mode only (ignored otherwise). + Default is 60 + </description> + </gc-param> + <gc-param> + <flag>ShenandoahHeapRegionSize</flag> + <description> + Size of the Shenandoah regions + </description> + </gc-param> + <gc-param> + <flag>ShenandoahInitialFreeThreshold</flag> + <description> + Set the percentage of heap free in relation to the total + capacity before a region can enter the concurrent marking + phase. Applies to Shenandoah GC dynamic Heuristic mode only + (ignored otherwise). Default is 50 + </description> + </gc-param> + <gc-param> + <flag>ShenandoahLogConfig</flag> + <description> + Log information about Shenandoah's configuration settings. + Default is false + </description> + </gc-param> + <gc-param> + <flag>ShenandoahOptimizeFinals</flag> + <description>Optimize barriers on final and stable fields/arrays.</description> + </gc-param> + <gc-param> + <flag>ShenandoahPrintCollectionSet</flag> + <description> + Print the collection set before each GC phase. Default is false + </description> + </gc-param> + <gc-param> + <flag>ShenandoahProcessReferences</flag> + <description> + Enable processing of (soft/weak/..) references in Shenandoah. + Default is true + </description> + </gc-param> + <gc-param> + <flag>ShenandoahReadBarrier</flag> + <description> + Turn on/off read barriers in Shenandoah. Default is true + </description> + </gc-param> + <gc-param> + <flag>ShenandoahReadBarrier</flag> + <description> + Turn on/off read barriers in Shenandoah. Default is true + </description> + </gc-param> + <gc-param> + <flag>ShenandoahTargetHeapOccupancy</flag> + <description> + Sets the target maximum percentage occupance of the heap we + would like to maintain. + Shenandoah GC newadaptive Heuristic mode only. Default is 80 + </description> + </gc-param> + <gc-param> + <flag>ShenandoahTraceFullGC</flag> + <description> + Trace Shenandoah full GC. Defaut is false + </description> + </gc-param> + <gc-param> + <flag>ShenandoahTraceHumongous</flag> + <description> + Trace Shenandoah humongous objects. Default is false + </description> + </gc-param> + <gc-param> + <flag>ShenandoahTracePhases</flag> + <description> + Trace Shenandoah GC phases. Default is false + </description> + </gc-param> + <gc-param> + <flag>ShenandoahWarnings</flag> + <description> + Print Shenandoah related warnings. Useful for Shenandoah developers. Default is false + </description> + </gc-param> + <gc-param> + <flag>ShenandoahWriteBarrier</flag> + <description> + Turn on/off write barriers in Shenandoah. Default is true + </description> + </gc-param> + </gc-params> + </collector> + +</gc-params-mapping>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/main/resources/com/redhat/thermostat/vm/gc/agent/gc-params-mapping.xsd Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,118 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Copyright 2012-2015 Red Hat, Inc. + + This file is part of Thermostat. + + Thermostat is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2, or (at your + option) any later version. + + Thermostat is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Thermostat; see the file COPYING. If not see + <http://www.gnu.org/licenses/>. + + Linking this code with other modules is making a combined work + based on this code. Thus, the terms and conditions of the GNU + General Public License cover the whole combination. + + As a special exception, the copyright holders of this code give + you permission to link this code with independent modules to + produce an executable, regardless of the license terms of these + independent modules, and to copy and distribute the resulting + executable under terms of your choice, provided that you also + meet, for each linked independent module, the terms and conditions + of the license of that module. An independent module is a module + which is not derived from or based on this code. If you modify + this code, you may extend this exception to your version of the + library, but you are not obligated to do so. If you do not wish + to do so, delete this exception statement from your version. + +--> +<xs:schema xmlns="http://icedtea.classpath.org/thermostat/gc-params-mapping/v1.0" + xmlns:xs="http://www.w3.org/2001/XMLSchema" + targetNamespace="http://icedtea.classpath.org/thermostat/gc-params-mapping/v1.0" + elementFormDefault="qualified"> + + <xs:element name="version" type="xs:string"/> + <xs:element name="common-name" type="xs:string"/> + <xs:element name="collector-name" type="xs:string"/> + <xs:element name="flag" type="xs:string"/> + <xs:element name="description" type="xs:string"/> + <xs:element name="url" type="xs:string"/> + + <xs:element name="gc-params-mapping"> + <xs:complexType> + <xs:sequence> + <xs:element ref="common" minOccurs="1" maxOccurs="1"/> + <xs:element ref="collector" minOccurs="1" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + + <xs:element name="common"> + <xs:complexType> + <xs:sequence> + <xs:element ref="gc-params" minOccurs="1" maxOccurs="1"/> + </xs:sequence> + </xs:complexType> + </xs:element> + + <xs:element name="collector"> + <xs:complexType> + <xs:sequence> + <xs:element ref="collector-info"/> + <xs:element ref="gc-params"/> + </xs:sequence> + </xs:complexType> + </xs:element> + + <xs:element name="collector-info"> + <xs:complexType> + <xs:sequence> + <xs:element ref="version"/> + <xs:element ref="common-name"/> + <xs:element ref="collector-distinct-names"/> + <xs:element ref="url"/> + </xs:sequence> + </xs:complexType> + </xs:element> + + <xs:element name="collector-distinct-names"> + <xs:annotation> + <xs:documentation>See GcCommonNameMapper.java + </xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:sequence> + <xs:element ref="collector-name" minOccurs="1" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + + <xs:element name="gc-params"> + <xs:complexType> + <xs:sequence> + <xs:element ref="gc-param" minOccurs="0" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + + <xs:element name="gc-param"> + <xs:complexType> + <xs:sequence> + <xs:element ref="flag"/> + <xs:element ref="description"/> + <xs:element ref="version" minOccurs="0"/> + </xs:sequence> + </xs:complexType> + </xs:element> + +</xs:schema> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/main/resources/com/redhat/thermostat/vm/gc/agent/locale/strings.properties Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,4 @@ +VALIDATION_FAILED = Validation failed for file {0} : {1} +VALIDATION_WARNING = Warning in file {0}:{1}.{2} +VALIDATION_ERROR = Error in file {0}:{1}.{2} +VALIDATION_FATAL_ERROR = Fatal error in file {0}:{1}.{2}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/test/java/com/redhat/thermostat/vm/gc/agent/GcCommonNameMapperTest.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,112 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent; + +import static org.junit.Assert.assertEquals; + +import java.util.HashSet; +import java.util.Set; + +import org.junit.Test; + +import com.redhat.thermostat.vm.gc.agent.GcCommonNameMapper.CollectorCommonName; + +public class GcCommonNameMapperTest { + + private static final GcCommonNameMapper mapper = new GcCommonNameMapper(); + + @Test + public void testMappings() { + Set<String> distinctSet = getDistinctColNames("CMS", "PCopy"); + CollectorCommonName actual = mapper.mapToCommonName(distinctSet); + assertEquals("'CMS' + 'PCopy' should map to concurrent collector", + CollectorCommonName.CONCURRENT_COLLECTOR, actual); + distinctSet = getDistinctColNames("PCopy", "MSC"); + actual = mapper.mapToCommonName(distinctSet); + assertEquals("'MSC' + 'PCopy' should map to MS Compact GC", + CollectorCommonName.MARK_SWEEP_COMPACT, actual); + distinctSet = getDistinctColNames("G1 incremental collections"); + actual = mapper.mapToCommonName(distinctSet); + assertEquals("'G1 incremental collections' should map to G1", + CollectorCommonName.G1, actual); + distinctSet = getDistinctColNames("PSParallelCompact", "PSScavenge"); + actual = mapper.mapToCommonName(distinctSet); + assertEquals("'PSParallelCompact' + 'PSScavenge' should map to parallel collector", + CollectorCommonName.PARALLEL_COLLECTOR, actual); + distinctSet = getDistinctColNames("MSC", "Copy"); + actual = mapper.mapToCommonName(distinctSet); + assertEquals("'MSC' + 'Copy' should map to serial collector", + CollectorCommonName.SERIAL_COLLECTOR, actual); + distinctSet = getDistinctColNames("Shenandoah concurrent phases", + "Shenandoah pauses", + "Shenandoah full GC pauses"); + actual = mapper.mapToCommonName(distinctSet); + assertEquals("Should map to shenandoah GC", + CollectorCommonName.SHENANDOAH, actual); + } + + @Test + public void testHumanReadableNames() { + assertEquals("Parallel Collector", CollectorCommonName.PARALLEL_COLLECTOR.getHumanReadableString()); + assertEquals("Serial Collector", CollectorCommonName.SERIAL_COLLECTOR.getHumanReadableString()); + assertEquals("Garbage-First Collector (G1)", CollectorCommonName.G1.getHumanReadableString()); + assertEquals("Concurrent Collector (Concurrent Mark and Sweep)", CollectorCommonName.CONCURRENT_COLLECTOR.getHumanReadableString()); + assertEquals("Mark Sweep Compact Collector", CollectorCommonName.MARK_SWEEP_COMPACT.getHumanReadableString()); + assertEquals("Shenandoah Collector", CollectorCommonName.SHENANDOAH.getHumanReadableString()); + assertEquals("Unknown Collector", CollectorCommonName.UNKNOWN_COLLECTOR.getHumanReadableString()); + } + + @Test + public void testUnknownCollector() { + Set<String> distinctSet = getDistinctColNames("Me_Dont_Know_Sub-Collector"); + CollectorCommonName actual = mapper.mapToCommonName(distinctSet); + assertEquals("Some random set should map to unknown collector", + CollectorCommonName.UNKNOWN_COLLECTOR, actual); + distinctSet = getDistinctColNames("foo", "bar"); + actual = mapper.mapToCommonName(distinctSet); + assertEquals("Some random set should map to unknown collector", + CollectorCommonName.UNKNOWN_COLLECTOR, actual); + } + + private Set<String> getDistinctColNames(String ... vals) { + Set<String> retval = new HashSet<>(); + for (String val: vals) { + retval.add(val); + } + return retval; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/test/java/com/redhat/thermostat/vm/gc/agent/internal/LocaleResourcesTest.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,54 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.internal; + +import com.redhat.thermostat.testutils.AbstractLocaleResourcesTest; + +public class LocaleResourcesTest extends AbstractLocaleResourcesTest<LocaleResources> { + + @Override + protected Class<LocaleResources> getEnumClass() { + return LocaleResources.class; + } + + @Override + protected String getResourceBundle() { + return LocaleResources.RESOURCE_BUNDLE; + } + +} +
--- a/plugins/vm-gc/agent/src/test/java/com/redhat/thermostat/vm/gc/agent/internal/VmGcBackendTest.java Fri Jun 23 10:25:42 2017 -0400 +++ b/plugins/vm-gc/agent/src/test/java/com/redhat/thermostat/vm/gc/agent/internal/VmGcBackendTest.java Fri Jun 23 11:45:40 2017 -0400 @@ -54,7 +54,7 @@ import com.redhat.thermostat.common.Ordered; import com.redhat.thermostat.storage.core.WriterID; import com.redhat.thermostat.vm.gc.agent.internal.VmGcBackend.ListenerCreator; -import com.redhat.thermostat.vm.gc.common.VmGcStatDAO; +import com.redhat.thermostat.vm.gc.agent.internal.models.VmGcStatDAO; public class VmGcBackendTest {
--- a/plugins/vm-gc/agent/src/test/java/com/redhat/thermostat/vm/gc/agent/internal/VmGcVmListenerTest.java Fri Jun 23 10:25:42 2017 -0400 +++ b/plugins/vm-gc/agent/src/test/java/com/redhat/thermostat/vm/gc/agent/internal/VmGcVmListenerTest.java Fri Jun 23 11:45:40 2017 -0400 @@ -52,8 +52,8 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; -import com.redhat.thermostat.vm.gc.common.VmGcStatDAO; -import com.redhat.thermostat.vm.gc.common.model.VmGcStat; +import com.redhat.thermostat.vm.gc.agent.internal.models.VmGcStatDAO; +import com.redhat.thermostat.vm.gc.agent.model.VmGcStat; public class VmGcVmListenerTest {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/test/java/com/redhat/thermostat/vm/gc/agent/internal/models/VmGcStatDAOImplTest.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,114 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.internal.models; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyListOf; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Arrays; + +import org.eclipse.jetty.client.api.ContentResponse; +import org.eclipse.jetty.http.HttpMethod; +import org.eclipse.jetty.http.HttpStatus; +import org.junit.Before; +import org.junit.Test; + +import com.redhat.thermostat.agent.http.HttpRequestService; +import com.redhat.thermostat.common.config.experimental.ConfigurationInfoSource; +import com.redhat.thermostat.common.plugins.PluginConfiguration; +import com.redhat.thermostat.vm.gc.agent.internal.models.VmGcStatDAOImpl.ConfigurationCreator; +import com.redhat.thermostat.vm.gc.agent.internal.models.VmGcStatDAOImpl.JsonHelper; +import com.redhat.thermostat.vm.gc.agent.model.VmGcStat; + +public class VmGcStatDAOImplTest { + + private static final String AGENT_ID = "some-agent"; + private static final String JSON = "{\"this\":\"is\",\"also\":\"JSON\"}"; + private static final String GATEWAY_URL = "http://example.com/jvm-gc"; + + private VmGcStat stat; + private JsonHelper jsonHelper; + private VmGcStatDAOImpl dao; + + private HttpRequestService httpRequestService; + + @Before + public void setup() throws Exception { + stat = new VmGcStat(); + stat.setAgentId(AGENT_ID); + stat.setTimeStamp(1234l); + stat.setWallTime(4000l); + stat.setRunCount(1000l); + stat.setVmId("Vm-1"); + stat.setCollectorName("Collector"); + + jsonHelper = mock(JsonHelper.class); + when(jsonHelper.toJson(anyListOf(VmGcStat.class))).thenReturn(JSON); + + ConfigurationInfoSource source = mock(ConfigurationInfoSource.class); + PluginConfiguration config = mock(PluginConfiguration.class); + when(config.getGatewayURL()).thenReturn(GATEWAY_URL); + ConfigurationCreator creator = mock(ConfigurationCreator.class); + when(creator.create(source)).thenReturn(config); + + httpRequestService = mock(HttpRequestService.class); + ContentResponse contentResponse = mock(ContentResponse.class); + when(httpRequestService.sendHttpRequest(anyString(), anyString(), any(HttpMethod.class))).thenReturn(contentResponse); + when(contentResponse.getStatus()).thenReturn(HttpStatus.OK_200); + + dao = new VmGcStatDAOImpl(jsonHelper, creator, source); + dao.bindHttpRequestService(httpRequestService); + } + + @Test + public void verifyAddVmGcStat() throws Exception { + dao.activate(); + dao.putVmGcStat(stat); + + verify(jsonHelper).toJson(eq(Arrays.asList(stat))); + + verify(httpRequestService, times(1)).sendHttpRequest(JSON, GATEWAY_URL, HttpMethod.POST); + } + +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/test/java/com/redhat/thermostat/vm/gc/agent/internal/models/VmGcStatTypeAdapterTest.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,62 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.internal.models; + +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; + +import org.junit.Test; + +import com.redhat.thermostat.vm.gc.agent.model.VmGcStat; + +public class VmGcStatTypeAdapterTest { + + @Test + public void testWrite() throws Exception { + VmGcStatTypeAdapter typeAdapter = new VmGcStatTypeAdapter(); + VmGcStat stat = new VmGcStat(); + stat.setAgentId("1"); + stat.setVmId("2"); + stat.setTimeStamp(100l); + stat.setCollectorName("Collector"); + stat.setRunCount(10l); + stat.setWallTime(200l); + assertEquals("[{\"agentId\":\"1\",\"jvmId\":\"2\",\"timeStamp\":{\"$numberLong\":\"100\"},\"collectorName\":\"Collector\",\"runCount\":{\"$numberLong\":\"10\"},\"wallTimeInMicros\":{\"$numberLong\":\"200\"}}]", + typeAdapter.toJson(Arrays.asList(stat))); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/test/java/com/redhat/thermostat/vm/gc/agent/model/VmGcStatTest.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,48 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.model; + +import com.redhat.thermostat.testutils.DataObjectTest; + +public class VmGcStatTest extends DataObjectTest { + + @Override + public Class<?>[] getDataClasses() { + return new Class[] { VmGcStat.class }; + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/test/java/com/redhat/thermostat/vm/gc/agent/params/CollectorInfoTest.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,86 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.params; + +import org.junit.Test; + +import java.util.HashSet; +import java.util.Set; + +import static org.junit.Assert.assertTrue; + +public class CollectorInfoTest { + + private static final JavaVersionRange JAVA_VERSION = new JavaVersionRange(new JavaVersionRange.VersionPoints(1, 8, 0, 45)); + private static final String COMMON_NAME = "COMMON_NAME"; + private static final Set<String> COLLECTOR_DISTINCT_NAMES = new HashSet<String>() {{ + add("COLLECTOR1"); + add("COLLECTOR2"); + }}; + private static final String REFERENCE_URL = "http://example.com"; + + @Test + public void testGetters() { + CollectorInfo collectorInfo = new CollectorInfo(JAVA_VERSION, COMMON_NAME, COLLECTOR_DISTINCT_NAMES, REFERENCE_URL); + assertTrue(JAVA_VERSION.toString(), JAVA_VERSION.equals(collectorInfo.getJavaVersionRange())); + assertTrue(COMMON_NAME, COMMON_NAME.equals(collectorInfo.getCommonName())); + assertTrue(COLLECTOR_DISTINCT_NAMES.toString(), COLLECTOR_DISTINCT_NAMES.equals(collectorInfo.getCollectorDistinctNames())); + assertTrue(REFERENCE_URL, REFERENCE_URL.equals(collectorInfo.getReferenceUrl())); + } + + @Test(expected = NullPointerException.class) + public void testNullVersionDisallowed() { + new CollectorInfo(null, COMMON_NAME, COLLECTOR_DISTINCT_NAMES, REFERENCE_URL); + } + + @Test(expected = NullPointerException.class) + public void testNullCommonNameDisallowed() { + new CollectorInfo(JAVA_VERSION, null, COLLECTOR_DISTINCT_NAMES, REFERENCE_URL); + } + + @Test(expected = NullPointerException.class) + public void testNullCollectorDistinctNamesDisallowed() { + new CollectorInfo(JAVA_VERSION, COMMON_NAME, null, REFERENCE_URL); + } + + @Test(expected = NullPointerException.class) + public void testNullReferenceUrlDisallowed() { + new CollectorInfo(JAVA_VERSION, COMMON_NAME, COLLECTOR_DISTINCT_NAMES, null); + } + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/test/java/com/redhat/thermostat/vm/gc/agent/params/CollectorTest.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,74 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.params; + +import org.junit.Test; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import static org.junit.Assert.assertTrue; + +public class CollectorTest { + + private static final String COMMON_NAME = "COMMON_NAME"; + private static final Set<String> DISTINCT_COLLECTOR_NAMES = new HashSet<>(Arrays.asList("COLLECTOR1", "COLLECTOR2")); + private static final JavaVersionRange JAVA_VERSION = new JavaVersionRange(new JavaVersionRange.VersionPoints(1, 8, 0, 45)); + private static final Set<GcParam> GC_PARAMS = new HashSet<GcParam>() {{ + add(new GcParam("-XXflag", "Description", new JavaVersionRange(new JavaVersionRange.VersionPoints(1, 9, 0, 10)))); + }}; + private static final String REFERENCE_URL = "http://example.com"; + private static final CollectorInfo COLLECTOR_INFO = new CollectorInfo(JAVA_VERSION, COMMON_NAME, DISTINCT_COLLECTOR_NAMES, REFERENCE_URL); + + @Test + public void testGetters() { + Collector collector = new Collector(COLLECTOR_INFO, GC_PARAMS); + assertTrue(COLLECTOR_INFO.toString(), COLLECTOR_INFO.equals(collector.getCollectorInfo())); + assertTrue(GC_PARAMS.toString(), GC_PARAMS.equals(collector.getGcParams())); + } + + @Test(expected = NullPointerException.class) + public void testNullCollectorInfoDisallowed() { + new Collector(null, GC_PARAMS); + } + + @Test(expected = NullPointerException.class) + public void testNullGcParamsDisallowed() { + new Collector(COLLECTOR_INFO, null); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/test/java/com/redhat/thermostat/vm/gc/agent/params/GcParamTest.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,71 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.params; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class GcParamTest { + + private static final String FLAG = "-XXflag"; + private static final String DESCRIPTION = "A short description of -XXflag"; + private static final JavaVersionRange JAVA_VERSION = new JavaVersionRange(new JavaVersionRange.VersionPoints(1, 8, 0, 45)); + + @Test + public void testGetters() { + GcParam param = new GcParam(FLAG, DESCRIPTION, JAVA_VERSION); + assertTrue(FLAG, param.getFlag().equals(FLAG)); + assertTrue(DESCRIPTION, param.getDescription().equals(DESCRIPTION)); + assertTrue(JAVA_VERSION.toString(), param.getJavaVersionRange().equals(JAVA_VERSION)); + } + + @Test(expected = NullPointerException.class) + public void testNullFlagDisallowed() { + new GcParam(null, DESCRIPTION, JAVA_VERSION); + } + + @Test(expected = NullPointerException.class) + public void testNullDescriptionDisallowed() { + new GcParam(FLAG, null, JAVA_VERSION); + } + + @Test(expected = NullPointerException.class) + public void testNullVersionDisallowed() { + new GcParam(FLAG, DESCRIPTION, null); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/test/java/com/redhat/thermostat/vm/gc/agent/params/GcParamsMapperTest.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,105 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.params; + +import com.redhat.thermostat.vm.gc.agent.GcCommonNameMapper; +import org.junit.Test; + +import java.io.FileNotFoundException; +import java.io.InputStream; +import java.net.URISyntaxException; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class GcParamsMapperTest { + + public static final JavaVersionRange JAVA_VERSION = new JavaVersionRange(new JavaVersionRange.VersionPoints(1, 8, 0, 45)); + private final GcParamsMapper paramsMapper = GcParamsMapper.getInstance(); + + @Test + public void testXsdValidatesXml() { + Exception ex = null; + String exceptionMessage = null; + try { + InputStream stream = paramsMapper.getXmlStream(); + GcParamsMappingValidator validator = new GcParamsMappingValidator(); + validator.validate(GcParamsMapper.XML_RESOURCE_URL, stream); + } catch (GcParamsMappingValidatorException e) { + ValidationErrorsFormatter formatter = new ValidationErrorsFormatter(); + exceptionMessage = formatter.format(e.getAllErrors()); + ex = e; + } catch (FileNotFoundException | URISyntaxException e) { + exceptionMessage = e.getMessage(); + ex = e; + } + assertTrue(exceptionMessage, ex == null); + } + + @Test + public void testUnknownHasNoParams() { + List<GcParam> params = paramsMapper.getParams(GcCommonNameMapper.CollectorCommonName.UNKNOWN_COLLECTOR, JAVA_VERSION); + assertEquals(0, params.size()); + } + + @Test + public void testNoEmptyFlags() { + List<Collector> collectors = paramsMapper.getCollectors(); + for (Collector collector : collectors) { + for (GcParam param : collector.getGcParams()) { + String flag = param.getFlag(); + assertFalse(collector.getCollectorInfo().getCommonName(), flag == null || flag.isEmpty()); + } + } + } + + @Test + public void testTunableVersionsContainedByCollectorVersions() { + List<Collector> collectors = paramsMapper.getCollectors(); + for (Collector collector : collectors) { + JavaVersionRange collectorVersion = collector.getCollectorInfo().getJavaVersionRange(); + for (GcParam param : collector.getGcParams()) { + JavaVersionRange paramVersion = param.getJavaVersionRange(); + assertTrue(collector.getCollectorInfo().getCommonName() + " - " + param.getFlag() + " lower", collectorVersion.contains(paramVersion.getLowerBound())); + assertTrue(collector.getCollectorInfo().getCommonName() + " - " + param.getFlag() + " upper", collectorVersion.contains(paramVersion.getUpperBound())); + } + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/test/java/com/redhat/thermostat/vm/gc/agent/params/GcParamsMappingValidatorTest.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,212 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.params; + +import org.junit.Test; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; + +import static org.junit.Assert.fail; + +public class GcParamsMappingValidatorTest { + + @Test + public void validateEmptyGcParamsMapping() throws IOException { + String config = "<?xml version=\"1.0\"?>\n"; + File testFile = createFile("testSystemId", config); + GcParamsMappingValidator validator = new GcParamsMappingValidator(); + try { + validator.validate("testSystemId", new FileInputStream(testFile)); + fail("should not come here"); + } catch (GcParamsMappingValidatorException e) { + //pass + } finally { + testFile.delete(); + } + } + + @Test + public void canValidateGcParamsMappingXMLMultipleTimes() throws Exception { + try { + String config = "<v1:gc-params-mapping xmlns:v1=\"http://icedtea.classpath.org/thermostat/gc-params-mapping/v1.0\">\n" + + " <v1:common>\n" + + " <v1:gc-params>" + + " <v1:gc-param>" + + " <v1:flag>string</v1:flag>" + + " <v1:description>string</v1:description>" + + " </v1:gc-param>" + + " </v1:gc-params>" + + " </v1:common>" + + " <!--1 or more repetitions:-->\n" + + " <v1:collector>\n" + + " <v1:collector-info>\n" + + " <v1:version>string</v1:version>\n" + + " <v1:common-name>string</v1:common-name>\n" + + " <v1:collector-distinct-names>\n" + + " <!--1 or more repetitions:-->\n" + + " <v1:collector-name>string</v1:collector-name>\n" + + " </v1:collector-distinct-names>\n" + + " <v1:url>string</v1:url>\n" + + " </v1:collector-info>\n" + + " <v1:gc-params>\n" + + " <!--Zero or more repetitions:-->\n" + + " <v1:gc-param>\n" + + " <v1:flag>string</v1:flag>\n" + + " <v1:description>string</v1:description>\n" + + " <!--Optional:-->\n" + + " <v1:version>string</v1:version>\n" + + " </v1:gc-param>\n" + + " </v1:gc-params>\n" + + " </v1:collector>\n" + + "</v1:gc-params-mapping>"; + File testFile = createFile("testSystemId", config); + GcParamsMappingValidator validator = new GcParamsMappingValidator(); + validator.validate("testSystemId", new FileInputStream(testFile)); + + // Second validation on the same file + validator.validate("testSystemId", new FileInputStream(testFile)); + testFile.delete(); + } catch (GcParamsMappingValidatorException e) { + fail("should not reach here, gc-params-mapping.xml should be validated according to schema"); + } + } + + @Test + public void validationFailsOnInvalidGcParamsMappingFile() throws Exception { + String config = "<v1:gc-params-mapping xmlns:v1=\"http://icedtea.classpath.org/thermostat/gc-params-mapping/v1.0\">\n" + + " <v1:common>\n" + + " <v1:gc-params>" + + " <v1:gc-param>" + + " <v1:flag>string</v1:flag>" + + " <v1:description>string</v1:description>" + + " </v1:gc-param>" + + " </v1:gc-params>" + + " </v1:common>" + + " <!--1 or more repetitions:-->\n" + + " <v1:collector>\n" + + " <v1:collector-info>\n" + + " <!-- <v1:version>string</v1:version> -->\n" + + " <v1:common-name>string</v1:common-name>\n" + + " <v1:collector-distinct-names>\n" + + " <!--1 or more repetitions:-->\n" + + " <v1:collector-name>string</v1:collector-name>\n" + + " </v1:collector-distinct-names>\n" + + " <v1:url>string</v1:url>\n" + + " </v1:collector-info>\n" + + " <v1:gc-params>\n" + + " <!--Zero or more repetitions:-->\n" + + " <v1:gc-param>\n" + + " <!-- <v1:flag>string</v1:flag> -->\n" + + " <v1:description>string</v1:description>\n" + + " <!--Optional:-->\n" + + " <v1:version>string</v1:version>\n" + + " </v1:gc-param>\n" + + " </v1:gc-params>\n" + + " </v1:collector>\n" + + "</v1:gc-params-mapping>"; + + File testFile = createFile("testSystemId", config); + GcParamsMappingValidator validator = new GcParamsMappingValidator(); + try { + validator.validate("testSystemId", new FileInputStream(testFile)); + fail("gc-params-mapping.xml should not validate according to schema"); + } catch (GcParamsMappingValidatorException e) { + //pass + } finally { + testFile.delete(); + } + } + + @Test + public void canValidateCorrectFile() throws IOException { + String config = "<v1:gc-params-mapping xmlns:v1=\"http://icedtea.classpath.org/thermostat/gc-params-mapping/v1.0\">\n" + + " <v1:common>\n" + + " <v1:gc-params>" + + " <v1:gc-param>" + + " <v1:flag>string</v1:flag>" + + " <v1:description>string</v1:description>" + + " </v1:gc-param>" + + " </v1:gc-params>" + + " </v1:common>" + + " <v1:collector>\n" + + " <v1:collector-info>\n" + + " <v1:version>1.0.0_0:1.8.0_45</v1:version>\n" + + " <v1:common-name>G1</v1:common-name>\n" + + " <v1:collector-distinct-names>\n" + + " <v1:collector-name>G1 garbage collection</v1:collector-name>\n" + + " </v1:collector-distinct-names>\n" + + " <v1:url>http://example.com</v1:url>\n" + + " </v1:collector-info>\n" + + " <v1:gc-params>\n" + + " <v1:gc-param>\n" + + " <v1:flag>-XXUseG1GC</v1:flag>\n" + + " <v1:description>Enable G1 collector</v1:description>\n" + + " <v1:version>1.0.0_0:1.8.0_45</v1:version>\n" + + " </v1:gc-param>\n" + + " <v1:gc-param>\n" + + " <v1:flag>-XXExtremePerformanceFlag</v1:flag>\n" + + " <v1:description>Turbo Super Ultra Charged Performance</v1:description>\n" + + " <v1:version>1.2.0_0:1.8.0_45</v1:version>\n" + + " </v1:gc-param>\n" + + " </v1:gc-params>\n" + + " </v1:collector>\n" + + "</v1:gc-params-mapping>"; + + File testFile = createFile("testSystemId", config); + GcParamsMappingValidator validator = new GcParamsMappingValidator(); + try { + validator.validate("testSystemId", new FileInputStream(testFile)); + } catch (GcParamsMappingValidatorException e) { + fail("should not reach here, gc-params-mapping.xml should be validated according to schema"); + } finally { + testFile.delete(); + } + } + + private File createFile(String fileName, String contents) throws IOException { + FileWriter fstream = new FileWriter(fileName); + BufferedWriter out = new BufferedWriter(fstream); + out.write(contents); + out.close(); + return new File(fileName); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/test/java/com/redhat/thermostat/vm/gc/agent/params/GcParamsParserTest.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,397 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.params; + +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.UnsupportedEncodingException; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class GcParamsParserTest { + + private static final String SINGLE_COLLECTOR_CONFIG = "<gc-params-mapping xmlns=\"http://icedtea.classpath.org/thermostat/gc-params-mapping/v1.0\"\n" + + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + + " xsi:schemaLocation=\"http://icedtea.classpath.org/thermostat/plugins/v1.0 gc-params-mapping.xsd\">\n" + + " <common>\n" + + " <gc-params>\n" + + " <gc-param>\n" + + " <flag>PrintGC</flag>\n" + + " <description>Print messages when garbage collection takes place</description>\n" + + " </gc-param>\n" + + " <gc-param>\n" + + " <flag>PrintGCDetails</flag>\n" + + " <description>Print more details in garbage collection messages</description>\n" + + " </gc-param>\n" + + " </gc-params>\n" + + " </common>" + + " <collector>\n" + + " <collector-info>\n" + + " <version>[1.0.0.0,1.8.0.45]</version>\n" + + " <common-name>Garbage-First Collector (G1)</common-name>\n" + + " <collector-distinct-names>\n" + + " <collector-name>G1 incremental collections</collector-name>\n" + + " </collector-distinct-names>\n" + + " <url>http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#available_collectors</url>\n" + + " </collector-info>\n" + + " <gc-params>\n" + + " <gc-param>\n" + + " <flag>G1ConcMarkStepDurationMillis</flag>\n" + + " <description>Description Text</description>\n" + + " <version>[1.5.0.31,1.8.0.45]</version>" + + " </gc-param>\n" + + " <gc-param>\n" + + " <flag>G1ConcRSHotCardLimit</flag>\n" + + " <description></description>\n" + + " </gc-param>\n" + + " <gc-param>\n" + + " <flag>G1ConcRSLogCacheSize</flag>\n" + + " <description></description>\n" + + " </gc-param>\n" + + " <gc-param>\n" + + " <flag>G1ConcRefinementGreenZone</flag>\n" + + " <description></description>\n" + + " </gc-param>\n" + + " <gc-param>\n" + + " <flag>G1ConcRefinementRedZone</flag>\n" + + " <description></description>\n" + + " </gc-param>\n" + + " <gc-param>\n" + + " <flag>G1ConcRefinementServiceIntervalMillis</flag>\n" + + " <description></description>\n" + + " </gc-param>\n" + + " <gc-param>\n" + + " <flag>G1ConcRefinementThreads</flag>\n" + + " <description></description>\n" + + " </gc-param>\n" + + " <gc-param>\n" + + " <flag>G1ConcRefinementThresholdStep</flag>\n" + + " <description></description>\n" + + " </gc-param>\n" + + " <gc-param>\n" + + " <flag>G1ConcRefinementYellowZone</flag>\n" + + " <description></description>\n" + + " </gc-param>\n" + + " <gc-param>\n" + + " <flag>G1ConfidencePercent</flag>\n" + + " <description></description>\n" + + " </gc-param>\n" + + " <gc-param>\n" + + " <flag>G1HeapRegionSize</flag>\n" + + " <description></description>\n" + + " </gc-param>\n" + + " <gc-param>\n" + + " <flag>G1HeapWastePercent</flag>\n" + + " <description></description>\n" + + " </gc-param>\n" + + " <gc-param>\n" + + " <flag>G1MixedGCCountTarget</flag>\n" + + " <description></description>\n" + + " </gc-param>\n" + + " <gc-param>\n" + + " <flag>G1RSetRegionEntries</flag>\n" + + " <description></description>\n" + + " </gc-param>\n" + + " <gc-param>\n" + + " <flag>G1RSetScanBlockSize</flag>\n" + + " <description></description>\n" + + " </gc-param>\n" + + " <gc-param>\n" + + " <flag>G1RSetSparseRegionEntries</flag>\n" + + " <description></description>\n" + + " </gc-param>\n" + + " <gc-param>\n" + + " <flag>G1RSetUpdatingPauseTimePercent</flag>\n" + + " <description></description>\n" + + " </gc-param>\n" + + " <gc-param>\n" + + " <flag>G1RefProcDrainInterval</flag>\n" + + " <description></description>\n" + + " </gc-param>\n" + + " <gc-param>\n" + + " <flag>G1ReservePercent</flag>\n" + + " <description></description>\n" + + " </gc-param>\n" + + " <gc-param>\n" + + " <flag>G1SATBBufferEnqueueingThresholdPercent</flag>\n" + + " <description></description>\n" + + " </gc-param>\n" + + " <gc-param>\n" + + " <flag>G1SATBBufferSize</flag>\n" + + " <description></description>\n" + + " </gc-param>\n" + + " <gc-param>\n" + + " <flag>G1UpdateBufferSize</flag>\n" + + " <description></description>\n" + + " </gc-param>\n" + + " <gc-param>\n" + + " <flag>G1UseAdaptiveConcRefinement</flag>\n" + + " <description></description>\n" + + " </gc-param>\n" + + " <gc-param>\n" + + " <flag>UseG1GC</flag>\n" + + " <description></description>\n" + + " </gc-param>\n" + + " </gc-params>\n" + + " </collector>\n" + + "</gc-params-mapping>"; + + private static final String TWO_COLLECTOR_CONFIG = "<gc-params-mapping xmlns=\"http://icedtea.classpath.org/thermostat/gc-params-mapping/v1.0\"\n" + + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + + " xsi:schemaLocation=\"http://icedtea.classpath.org/thermostat/plugins/v1.0 gc-params-mapping.xsd\">\n" + + " <common>\n" + + " <gc-params>\n" + + " <gc-param>\n" + + " <flag>PrintGC</flag>\n" + + " <description>Print messages when garbage collection takes place</description>\n" + + " </gc-param>\n" + + " <gc-param>\n" + + " <flag>PrintGCDetails</flag>\n" + + " <description>Print more details in garbage collection messages</description>\n" + + " </gc-param>\n" + + " </gc-params>\n" + + " </common>" + + " <collector>\n" + + " <collector-info>\n" + + " <version>[1.0.0.0,1.8.0.45]</version>\n" + + " <common-name>Garbage-First Collector (G1)</common-name>\n" + + " <collector-distinct-names>\n" + + " <collector-name>G1 incremental collections</collector-name>\n" + + " </collector-distinct-names>\n" + + " <url>http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#available_collectors</url>\n" + + " </collector-info>\n" + + " <gc-params>\n" + + " <gc-param>\n" + + " <flag>G1ConcMarkStepDurationMillis</flag>\n" + + " <description>Description Text</description>\n" + + " <version>[1.5.0.31,1.8.0.45]</version>" + + " </gc-param>\n" + + " </gc-params>\n" + + " </collector>\n" + + " <collector>\n" + + " <collector-info>\n" + + " <version>[1.5.0.31,1.8.0.45]</version>\n" + + " <common-name>Parallel</common-name>\n" + + " <collector-distinct-names>\n" + + " <collector-name>PSParallelCompact</collector-name>\n" + + " <collector-name>PSScavenge</collector-name>\n" + + " </collector-distinct-names>\n" + + " <url>http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#available_collectors</url>\n" + + " </collector-info>\n" + + " <gc-params>\n" + + " <gc-param>\n" + + " <flag>UseParallelGC</flag>\n" + + " <description>Parallel Description Text</description>\n" + + " <version>[1.7.0.41,1.8.0.45]</version>" + + " </gc-param>\n" + + " </gc-params>\n" + + " </collector>\n" + + "</gc-params-mapping>"; + + private static final JavaVersionRange G1_VERSION = new JavaVersionRange(new JavaVersionRange.VersionPoints(1, 0, 0, 0), true, new JavaVersionRange.VersionPoints(1, 8, 0, 45), true); + private static final String G1_COMMON_NAME = "Garbage-First Collector (G1)"; + private static final Set<String> G1_DISTINCT_NAMES = Collections.singleton("G1 incremental collections"); + private static final String G1_REFERENCE_URL = "http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#available_collectors"; + + private static final String PARALLEL_COMMON_NAME = "Parallel"; + + private static final String MARK_STEP_DURATION_MILLIS_FLAG = "G1ConcMarkStepDurationMillis"; + private static final String MARK_STEP_DURATION_MILLIS_DESCRIPTION = "Description Text"; + private static final JavaVersionRange MARK_STEP_DURATION_MILLIS_VERSION = new JavaVersionRange(new JavaVersionRange.VersionPoints(1, 5, 0, 31), true, new JavaVersionRange.VersionPoints(1, 8, 0, 45), true); + private static final Set<String> PARALLEL_DISTINCT_NAMES = new HashSet<>(Arrays.asList("PSParallelCompact", "PSScavenge")); + private static final JavaVersionRange ALL_JAVA_VERSIONS_RANGE = new JavaVersionRange(JavaVersionRange.VersionPoints.MINIMUM_VERSION, true, JavaVersionRange.VersionPoints.MAXIMUM_VERSION, true); + private static final GcParam PRINT_GC_COMMON_PARAM = new GcParam("PrintGC", "Print messages when garbage collection takes place", ALL_JAVA_VERSIONS_RANGE); + private static final GcParam PRINT_GC_DETAILS_COMMON_PARAM = new GcParam("PrintGCDetails", "Print more details in garbage collection messages", ALL_JAVA_VERSIONS_RANGE); + private static final Set<GcParam> COMMON_PARAMS = new HashSet<>(Arrays.asList(PRINT_GC_COMMON_PARAM, PRINT_GC_DETAILS_COMMON_PARAM)); + + @Test(expected = GcParamsParser.GcParamsParseException.class) + public void testEmptyConfigurationThrowsException() throws UnsupportedEncodingException { + String config = "<?xml version=\"1.0\"?>\n"; + GcParamsParser.parse(new ByteArrayInputStream(config.getBytes("UTF-8"))); + fail("should not reach here"); + } + + @Test + public void testMinimalConfigurationParsesOneCollector() throws UnsupportedEncodingException { + GcParamsParser.ParseResult result = getSingleCollectorResult(); + assertEquals(1, result.getCollectors().size()); + } + + @Test + public void testMinimalConfigurationParsesCorrectCommonParams() throws UnsupportedEncodingException { + GcParamsParser.ParseResult result = getSingleCollectorResult(); + assertNonEmptyResult(result.getGcCommonParams()); + assertEquals(result.getGcCommonParams(), COMMON_PARAMS); + } + + @Test + public void testMinimalConfigurationParsesCorrectCollectorName() throws UnsupportedEncodingException { + GcParamsParser.ParseResult result = getSingleCollectorResult(); + assertNonEmptyResult(result.getCollectors()); + assertEquals(result.getCollectors().get(0).getCollectorInfo().getCommonName(), G1_COMMON_NAME); + } + + @Test + public void testMinimalConfigurationParsesCorrectCollectorDistinctNames() throws UnsupportedEncodingException { + GcParamsParser.ParseResult result = getSingleCollectorResult(); + assertNonEmptyResult(result.getCollectors()); + assertEquals(result.getCollectors().get(0).getCollectorInfo().getCollectorDistinctNames(), G1_DISTINCT_NAMES); + } + + @Test + public void testMinimalConfigurationParsesCorrectCollectorVersion() throws UnsupportedEncodingException { + GcParamsParser.ParseResult result = getSingleCollectorResult(); + assertNonEmptyResult(result.getCollectors()); + assertEquals(result.getCollectors().get(0).getCollectorInfo().getJavaVersionRange(), G1_VERSION); + } + + @Test + public void testMinimalConfigurationParsesCorrectReferenceUrl() throws UnsupportedEncodingException { + GcParamsParser.ParseResult result = getSingleCollectorResult(); + assertNonEmptyResult(result.getCollectors()); + assertEquals(result.getCollectors().get(0).getCollectorInfo().getReferenceUrl(), G1_REFERENCE_URL); + } + + @Test + public void testMinimalConfigurationParsesGcParams() throws UnsupportedEncodingException { + GcParamsParser.ParseResult result = getSingleCollectorResult(); + assertNonEmptyResult(result.getCollectors()); + assertEquals(result.getCollectors().get(0).getGcParams().size(), 24); + } + + @Test + public void testMinimalConfigurationParsesGcParamsVersions() throws UnsupportedEncodingException { + GcParamsParser.ParseResult result = getSingleCollectorResult(); + assertNonEmptyResult(result.getCollectors()); + for (GcParam param : result.getCollectors().get(0).getGcParams()) { + if (param.getFlag().equals(MARK_STEP_DURATION_MILLIS_FLAG)) { + assertEquals(param.getJavaVersionRange(), MARK_STEP_DURATION_MILLIS_VERSION); + } else { + assertEquals(param.getJavaVersionRange(), G1_VERSION); + } + } + } + + @Test + public void testMinimalConfigurationParsesGcParamsDescriptions() throws UnsupportedEncodingException { + GcParamsParser.ParseResult result = getSingleCollectorResult(); + assertNonEmptyResult(result.getCollectors()); + for (GcParam param : result.getCollectors().get(0).getGcParams()) { + if (param.getFlag().equals(MARK_STEP_DURATION_MILLIS_FLAG)) { + assertEquals(param.getDescription(), MARK_STEP_DURATION_MILLIS_DESCRIPTION); + } else { + assertTrue(param.getDescription(), param.getDescription().isEmpty()); + } + } + } + + @Test + public void testTwoCollectorConfigurationParsesCommonParams() throws UnsupportedEncodingException { + GcParamsParser.ParseResult parseResult = getTwoCollectorResult(); + assertNonEmptyResult(parseResult.getGcCommonParams()); + assertEquals(parseResult.getGcCommonParams(), COMMON_PARAMS); + } + + @Test + public void testTwoCollectorConfigurationParsesCollectors() throws UnsupportedEncodingException { + GcParamsParser.ParseResult result = getTwoCollectorResult(); + assertNonEmptyResult(result.getCollectors()); + assertEquals(result.getCollectors().size(), 2); + } + + @Test + public void testTwoCollectorConfigurationParsesCollectorCommonNames() throws UnsupportedEncodingException { + GcParamsParser.ParseResult result = getTwoCollectorResult(); + assertNonEmptyResult(result.getCollectors()); + assertEquals(result.getCollectors().size(), 2); + Set<String> commonNames = new HashSet<>(Arrays.asList(result.getCollectors().get(0).getCollectorInfo().getCommonName(), + result.getCollectors().get(1).getCollectorInfo().getCommonName())); + assertEquals(commonNames, new HashSet<>(Arrays.asList(G1_COMMON_NAME, PARALLEL_COMMON_NAME))); + } + + @Test + public void testTwoCollectorConfigurationParsesCollectorDistinctNames() throws UnsupportedEncodingException { + GcParamsParser.ParseResult result = getTwoCollectorResult(); + assertNonEmptyResult(result.getCollectors()); + assertEquals(result.getCollectors().size(), 2); + for (Collector collector : result.getCollectors()) { + if (collector.getCollectorInfo().getCommonName().equals(G1_COMMON_NAME)) { + assertEquals(G1_DISTINCT_NAMES, collector.getCollectorInfo().getCollectorDistinctNames()); + } else if (collector.getCollectorInfo().getCommonName().equals(PARALLEL_COMMON_NAME)) { + assertEquals(PARALLEL_DISTINCT_NAMES, collector.getCollectorInfo().getCollectorDistinctNames()); + } else { + fail("no other collector should have been parsed"); + } + } + } + + private void assertNonEmptyResult(List<Collector> result) { + failIfEmpty(result, "collectors"); + } + + private void assertNonEmptyResult(Set<GcParam> result) { + failIfEmpty(result, "common params"); + } + + private void failIfEmpty(Collection<?> result, String part) { + if (result.isEmpty()) { + fail(part + " should not be empty"); + } + } + + private GcParamsParser.ParseResult getSingleCollectorResult() throws UnsupportedEncodingException { + return parseHelper(SINGLE_COLLECTOR_CONFIG); + } + + private GcParamsParser.ParseResult getTwoCollectorResult() throws UnsupportedEncodingException { + return parseHelper(TWO_COLLECTOR_CONFIG); + } + + private GcParamsParser.ParseResult parseHelper(String config) throws UnsupportedEncodingException { + return GcParamsParser.parse(new ByteArrayInputStream(config.getBytes("UTF-8"))); + } + +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/agent/src/test/java/com/redhat/thermostat/vm/gc/agent/params/JavaVersionRangeTest.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,400 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.vm.gc.agent.params; + +import org.junit.Assert; +import org.junit.Test; + +import com.redhat.thermostat.vm.gc.agent.params.JavaVersionRange.VersionPoints; + +import java.util.regex.Pattern; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class JavaVersionRangeTest { + + public static final JavaVersionRange.VersionPoints ONE_ZERO_ZERO_U0 = new JavaVersionRange.VersionPoints(1, 0, 0, 0); + public static final JavaVersionRange.VersionPoints ONE_ZERO_ONE_U0 = new JavaVersionRange.VersionPoints(1, 0, 1, 0); + public static final JavaVersionRange.VersionPoints ONE_ONE_ZERO_U10 = new JavaVersionRange.VersionPoints(1, 1, 0, 10); + public static final JavaVersionRange.VersionPoints TWO_ZERO_TEN_U40 = new JavaVersionRange.VersionPoints(2, 0, 10, 40); + static final JavaVersionRange VERSION_ONE_ZERO_ZERO_U0 = new JavaVersionRange(ONE_ZERO_ZERO_U0); + static final JavaVersionRange VERSION_ONE_ZERO_ONE_U0 = new JavaVersionRange(ONE_ZERO_ONE_U0); + static final JavaVersionRange VERSION_ONE_ONE_ZERO_U10 = new JavaVersionRange(ONE_ONE_ZERO_U10); + static final JavaVersionRange VERSION_TWO_ZERO_TEN_U40 = new JavaVersionRange(TWO_ZERO_TEN_U40); + + static final JavaVersionRange SMALL_RANGE = new JavaVersionRange(ONE_ZERO_ZERO_U0, true, ONE_ZERO_ONE_U0, true); + static final JavaVersionRange LARGE_RANGE = new JavaVersionRange(ONE_ZERO_ZERO_U0, true, TWO_ZERO_TEN_U40, true); + + @Test + public void testVendorStringInVersion() { + final String winRawStr = "1.8.0_101-1-comment"; + final String oldRawStr = "1.8.0_101-1"; + final JavaVersionRange winRange = JavaVersionRange.fromString(winRawStr); + final JavaVersionRange oldRange = JavaVersionRange.fromString(oldRawStr); + final String winRangeStr = winRange.toString(); + final String oldRangeStr = oldRange.toString(); + Assert.assertEquals("must strip off '-comment'", oldRangeStr, winRangeStr); + } + + @Test + public void testValidSingleVersionComparisons() { + assertFalse(ONE_ZERO_ZERO_U0 + " = " + ONE_ZERO_ZERO_U0, lessThan(VERSION_ONE_ZERO_ZERO_U0, VERSION_ONE_ZERO_ZERO_U0)); + assertTrue(ONE_ZERO_ZERO_U0 + " < " + ONE_ZERO_ONE_U0, lessThan(VERSION_ONE_ZERO_ZERO_U0, VERSION_ONE_ZERO_ONE_U0)); + assertTrue(ONE_ZERO_ONE_U0 + " < " + ONE_ONE_ZERO_U10, lessThan(VERSION_ONE_ZERO_ONE_U0, VERSION_ONE_ONE_ZERO_U10)); + assertTrue(ONE_ONE_ZERO_U10 + " < " + TWO_ZERO_TEN_U40, lessThan(VERSION_ONE_ONE_ZERO_U10, VERSION_TWO_ZERO_TEN_U40)); + } + + @Test + public void testContains() { + assertTrue(VERSION_ONE_ZERO_ZERO_U0 + " in " + SMALL_RANGE, SMALL_RANGE.contains(VERSION_ONE_ZERO_ZERO_U0)); + assertTrue(VERSION_ONE_ONE_ZERO_U10 + " in " + LARGE_RANGE, LARGE_RANGE.contains(VERSION_ONE_ONE_ZERO_U10)); + assertFalse(VERSION_TWO_ZERO_TEN_U40 + " in " + SMALL_RANGE, SMALL_RANGE.contains(VERSION_TWO_ZERO_TEN_U40)); + assertTrue(VERSION_TWO_ZERO_TEN_U40 + " in " + LARGE_RANGE, LARGE_RANGE.contains(VERSION_TWO_ZERO_TEN_U40)); + assertTrue(SMALL_RANGE + " in " + LARGE_RANGE, LARGE_RANGE.contains(SMALL_RANGE)); + assertFalse(LARGE_RANGE + " in " + SMALL_RANGE, SMALL_RANGE.contains(LARGE_RANGE)); + } + + @Test + public void testIsRange() { + assertTrue(SMALL_RANGE.toString(), SMALL_RANGE.isRange()); + assertTrue(LARGE_RANGE.toString(), LARGE_RANGE.isRange()); + assertFalse(VERSION_ONE_ZERO_ZERO_U0.toString(), VERSION_ONE_ZERO_ZERO_U0.isRange()); + assertFalse(VERSION_TWO_ZERO_TEN_U40.toString(), VERSION_TWO_ZERO_TEN_U40.isRange()); + } + + @Test + public void testGetLowerBound() { + assertEquals(new JavaVersionRange(ONE_ZERO_ZERO_U0), VERSION_ONE_ZERO_ZERO_U0.getLowerBound()); + assertEquals(VERSION_ONE_ZERO_ZERO_U0, VERSION_ONE_ZERO_ZERO_U0.getLowerBound()); + assertEquals(VERSION_ONE_ZERO_ZERO_U0, SMALL_RANGE.getLowerBound()); + } + + @Test + public void testGetUpperBound() { + assertEquals(new JavaVersionRange(ONE_ZERO_ZERO_U0), VERSION_ONE_ZERO_ZERO_U0.getUpperBound()); + assertEquals(VERSION_ONE_ZERO_ZERO_U0, VERSION_ONE_ZERO_ZERO_U0.getUpperBound()); + assertEquals(VERSION_TWO_ZERO_TEN_U40, LARGE_RANGE.getUpperBound()); + } + + @Test + public void testSingleVersionIsShortcutForSameWithComma() { + JavaVersionRange single = JavaVersionRange.fromString("[1.0.0.0]"); + JavaVersionRange pair = JavaVersionRange.fromString("[1.0.0.0,1.0.0.0]"); + assertEquals(single, pair); + } + + @Test + public void testDefaultIsInclusive() { + JavaVersionRange version = new JavaVersionRange(1, 0, 0, 0); + assertTrue(version.isLowerBoundInclusive()); + assertTrue(version.isUpperBoundInclusive()); + } + + @Test + public void testLowerBoundInclusive() { + JavaVersionRange inclusive = new JavaVersionRange(new JavaVersionRange.VersionPoints(2, 0, 0, 0), true, + new JavaVersionRange.VersionPoints(2, 1, 0, 0), false); // [2.0.0.0, 2.1.0.0) + JavaVersionRange exclusive = new JavaVersionRange(new JavaVersionRange.VersionPoints(2, 0, 0, 0), false, + new JavaVersionRange.VersionPoints(2, 1, 0, 0), false); // (2.0.0.0, 2.1.0.0) + JavaVersionRange version = new JavaVersionRange(2, 0, 0, 0); + assertTrue(inclusive.contains(version)); + assertFalse(exclusive.contains(version)); + } + + @Test + public void testUpperBoundInclusive() { + JavaVersionRange inclusive = new JavaVersionRange(new JavaVersionRange.VersionPoints(2, 0, 0, 0), false, + new JavaVersionRange.VersionPoints(2, 1, 0, 0), true); // (2.0.0.0, 2.1.0.0] + JavaVersionRange exclusive = new JavaVersionRange(new JavaVersionRange.VersionPoints(2, 0, 0, 0), false, + new JavaVersionRange.VersionPoints(2, 1, 0, 0), false); // (2.0.0.0, 2.1.0.0) + JavaVersionRange version = new JavaVersionRange(2, 1, 0, 0); + assertTrue(inclusive.contains(version)); + assertFalse(exclusive.contains(version)); + } + + @Test(expected = NumberFormatException.class) + public void testExtremelyLargeVersionNumberCannotBeParsed() { + JavaVersionRange version = JavaVersionRange.fromString("[" + Long.toString((long) Integer.MAX_VALUE + 1) + ".2.3_4" + "]"); + String expectedVersion = "[2147483648.2.3_4]"; + String expectedRange = "[" + expectedVersion + "," + expectedVersion + "]"; + assertEquals(expectedRange, version.toString()); + assertTrue(version.toString() + " = " + version.toString(), version.compareTo(version) == 0); + } + + @Test(expected = NullPointerException.class) + public void testNullNotAccepted() { + new JavaVersionRange(null); + } + + @Test(expected = IllegalArgumentException.class) + public void testNegativeMajorDisallowed() { + new JavaVersionRange.VersionPoints(-1, 0, 0, 0); + } + + @Test(expected = IllegalArgumentException.class) + public void testNegativeMinorDisallowed() { + new JavaVersionRange.VersionPoints(0, -1, 0, 0); + } + + @Test(expected = IllegalArgumentException.class) + public void testNegativeMicroDisallowed() { + new JavaVersionRange.VersionPoints(0, 0, -1, 0); + } + + @Test(expected = IllegalArgumentException.class) + public void testNegativeUpdateDisallowed() { + new JavaVersionRange.VersionPoints(0, 0, 0, -1); + } + + @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) + public void testInvalidTextNotAccepted() { + JavaVersionRange.fromString("INVALID TEXT"); + } + + @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) + public void testInvalidFormatNotAccepted() { + JavaVersionRange.fromString("[1,0,2]"); + } + + @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) + public void testInvalidFormatNotAccepted2() { + JavaVersionRange.fromString("[1#3.3_4]"); + } + + @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) + public void testInvalidFormatNotAccepted3() { + JavaVersionRange.fromString("[1,300,6_3]"); + } + + @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) + public void testInvalidFormatNotAcceptedWithNull() { + JavaVersionRange.fromString(null); + } + + @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) + public void testFromStringDoesNotAcceptNegative() { + JavaVersionRange.fromString("[-1.0.1]"); + } + + @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) + public void testRangeMustAscend() { + JavaVersionRange.fromString("[2.0.0_10,1.0.0_0]"); + } + + @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) + public void testRangeMustAscend2() { + new JavaVersionRange(new JavaVersionRange.VersionPoints(2, 0, 0, 10), true, new JavaVersionRange.VersionPoints(1, 0, 0, 0), true); + } + + @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) + public void testRangeMustNotBeEmpty() { + JavaVersionRange.fromString("(1.0.0.0)"); + } + + @Test + public void testBracketsAreOptionalForSingleVersion() { + JavaVersionRange without = JavaVersionRange.fromString("1.0.0.0"); + JavaVersionRange with = JavaVersionRange.fromString("[1.0.0.0]"); + assertEquals(without, with); + } + + @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) + public void testMismatchedBracketsForSingleVersion() { + JavaVersionRange.fromString("[1.0.0.0"); + } + + @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) + public void testMismatchedBracketsForSingleVersion2() { + JavaVersionRange.fromString("1.0.0.0]"); + } + + @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) + public void testBracketsAreNotOptionalForRanges() { + JavaVersionRange.fromString("1.0.0.0,2.0.0.0"); + } + + @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) + public void testBracketsAreNotOptionalForRanges2() { + JavaVersionRange.fromString("[1.0.0.0,2.0.0.0"); + } + + @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) + public void testBracketsAreNotOptionalForRanges3() { + JavaVersionRange.fromString("1.0.0.0,2.0.0.0]"); + } + + @Test + public void testUnboundedUpperBound() { + int max = Integer.MAX_VALUE; + JavaVersionRange unbounded = JavaVersionRange.fromString("[1.0.0.0,]"); + assertTrue(unbounded.isLowerBoundInclusive()); + assertTrue(unbounded.isUpperBoundInclusive()); + assertTrue(unbounded.getLowerBound().equals(new JavaVersionRange(1, 0, 0, 0))); + assertTrue(unbounded.getUpperBound().equals(new JavaVersionRange(max, max, max, max))); + } + + @Test + public void testUnboundedLowerBound() { + JavaVersionRange unbounded = JavaVersionRange.fromString("[,1.0.0.0]"); + assertTrue(unbounded.isLowerBoundInclusive()); + assertTrue(unbounded.isUpperBoundInclusive()); + assertTrue(unbounded.getLowerBound().equals(new JavaVersionRange(0, 0, 0, 0))); + assertTrue(unbounded.getUpperBound().equals(new JavaVersionRange(1, 0, 0, 0))); + } + + @Test + public void testUnboundedUpperBoundExclusiveLowerBound() { + JavaVersionRange version = JavaVersionRange.fromString("(1.2.0.0,)"); + JavaVersionRange one = JavaVersionRange.fromString("1.0.0.0"); + JavaVersionRange two = JavaVersionRange.fromString("1.2.0.0"); + JavaVersionRange three = JavaVersionRange.fromString("1.3.0.0"); + assertFalse(version.contains(one)); + assertFalse(version.contains(two)); + assertTrue(version.contains(three)); + } + + @Test + public void testUnboundedLowerBoundExclusiveUpperBound() { + JavaVersionRange version = JavaVersionRange.fromString("[,1.8.0.0)"); + JavaVersionRange two = JavaVersionRange.fromString("1.2.0.0"); + JavaVersionRange seven = JavaVersionRange.fromString("1.7.0.0"); + JavaVersionRange lateSeven = JavaVersionRange.fromString("1.7.0.81"); + JavaVersionRange eight = JavaVersionRange.fromString("1.8.0.0"); + JavaVersionRange lateEight = JavaVersionRange.fromString("1.8.0_51"); + assertTrue(version.contains(two)); + assertTrue(version.contains(seven)); + assertTrue(version.contains(lateSeven)); + assertFalse(version.contains(eight)); + assertFalse(version.contains(lateEight)); + } + + @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) + public void testVersionsRequiredOnAtLeastOneSideOfCommaWithBrackets() { + JavaVersionRange.fromString("[,]"); + } + + @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) + public void testVersionsRequiredOnBothSidesOfCommaWithoutBrackets() { + JavaVersionRange.fromString("1.0.0.0,"); + } + + @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) + public void testVersionsRequiredOnBothSidesOfCommaWithoutBrackets2() { + JavaVersionRange.fromString(",1.0.0.0"); + } + + @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) + public void testVersionsRequiredOnBothSidesOfCommaWithoutBrackets3() { + JavaVersionRange.fromString(","); + } + + @Test + public void testUnderscoreEquivalentToDot() { + JavaVersionRange score = JavaVersionRange.fromString("1.2.3_4"); + JavaVersionRange dot = JavaVersionRange.fromString("1.2.3.4"); + assertEquals(score, dot); + } + + @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) + public void testScoreOnlyAllowedAsFinalSeparator() { + JavaVersionRange.fromString("1_2.3.4"); + } + + @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) + public void testScoreOnlyAllowedAsFinalSeparator2() { + JavaVersionRange.fromString("1.2_3.4"); + } + + @Test + public void canParseCustomBuiltJDKVersion() { + testJDKVersion("1.7.0-internal"); // a custom JDK 7 build has this version string + testJDKVersion("1.7.0"); + testJDKVersion("1.8.0"); + testJDKVersion("1.8.0.55-internal"); + } + + @Test + public void testVersionPointsFromString() { + VersionPoints points = VersionPoints.fromString("1.7.0-internal"); + assertEquals(1, points.getMajor()); + assertEquals(7, points.getMinor()); + assertEquals(0, points.getMicro()); + assertEquals(0, points.getUpdate()); + assertEquals("internal", points.getPreRelease()); + assertEquals("1.7.0.0-internal", points.toString()); + + points = VersionPoints.fromString("1.7.0"); + assertEquals(1, points.getMajor()); + assertEquals(7, points.getMinor()); + assertEquals(0, points.getMicro()); + assertEquals(0, points.getUpdate()); + assertEquals("", points.getPreRelease()); + assertEquals("1.7.0.0", points.toString()); + + points = VersionPoints.fromString("1.8.1_55-b20"); + assertEquals(1, points.getMajor()); + assertEquals(8, points.getMinor()); + assertEquals(1, points.getMicro()); + assertEquals(55, points.getUpdate()); + assertEquals("b20", points.getPreRelease()); + assertEquals("1.8.1.55-b20", points.toString()); + } + + @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) + public void shouldFailToParseVersionPointsForIrregularVersion() { + VersionPoints.fromString("1.7.0|30-internal"); // illegal update separator + } + + private void testJDKVersion(String jdkVersion) { + JavaVersionRange version = null; + try { + version = JavaVersionRange.fromString(jdkVersion); + // pass + } catch (JavaVersionRange.InvalidJavaVersionFormatException e) { + fail("Expected to be able to parse " + jdkVersion); + } + assertFalse(version.isRange()); + } + + private static boolean lessThan(JavaVersionRange a, JavaVersionRange b) { + return a.compareTo(b) < 0; + } + +}
--- a/plugins/vm-gc/common/pom.xml Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,154 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Copyright 2012-2017 Red Hat, Inc. - - This file is part of Thermostat. - - Thermostat is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 2, or (at your - option) any later version. - - Thermostat is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Thermostat; see the file COPYING. If not see - <http://www.gnu.org/licenses/>. - - Linking this code with other modules is making a combined work - based on this code. Thus, the terms and conditions of the GNU - General Public License cover the whole combination. - - As a special exception, the copyright holders of this code give - you permission to link this code with independent modules to - produce an executable, regardless of the license terms of these - independent modules, and to copy and distribute the resulting - executable under terms of your choice, provided that you also - meet, for each linked independent module, the terms and conditions - of the license of that module. An independent module is a module - which is not derived from or based on this code. If you modify - this code, you may extend this exception to your version of the - library, but you are not obligated to do so. If you do not wish - to do so, delete this exception statement from your version. - ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <artifactId>thermostat-vm-gc</artifactId> - <groupId>com.redhat.thermostat</groupId> - <version>1.99.12-SNAPSHOT</version> - </parent> - <artifactId>thermostat-vm-gc-common</artifactId> - <packaging>bundle</packaging> - <name>Thermostat VM GC Common plugin</name> - <build> - <resources> - <resource> - <directory>src/main/resources</directory> - <filtering>true</filtering> - <excludes> - <exclude>**/*.png</exclude> - <exclude>**/*.xml</exclude> - <exclude>**/*.xsd</exclude> - </excludes> - </resource> - <resource> - <directory>src/main/resources</directory> - <filtering>false</filtering> - <includes> - <include>**/*.png</include> - <include>**/*.xml</include> - <include>**/*.xsd</include> - </includes> - </resource> - </resources> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Bundle-Vendor>Red Hat, Inc.</Bundle-Vendor> - <Bundle-SymbolicName>com.redhat.thermostat.vm.gc.common</Bundle-SymbolicName> - <Export-Package> - com.redhat.thermostat.vm.gc.common, - com.redhat.thermostat.vm.gc.common.model, - com.redhat.thermostat.vm.gc.common.params - </Export-Package> - <Private-Package> - com.redhat.thermostat.vm.gc.common.internal, - </Private-Package> - <!-- Do not autogenerate uses clauses in Manifests --> - <_nouses>true</_nouses> - </instructions> - </configuration> - </plugin> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-scr-plugin</artifactId> - <executions> - <execution> - <id>generate-scr-scrdescriptor</id> - <goals> - <goal>scr</goal> - </goals> - </execution> - </executions> - </plugin> - </plugins> - </build> - <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.core</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.osgi</groupId> - <artifactId>org.osgi.compendium</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>com.redhat.thermostat</groupId> - <artifactId>thermostat-common-core</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>com.redhat.thermostat</groupId> - <artifactId>thermostat-agent-core</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>com.redhat.thermostat</groupId> - <artifactId>thermostat-storage-core</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>com.redhat.thermostat</groupId> - <artifactId>thermostat-common-test</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> - <!-- declarative services --> - <dependency> - <groupId>org.apache.felix</groupId> - <artifactId>org.apache.felix.scr.annotations</artifactId> - </dependency> - </dependencies> -</project>
--- a/plugins/vm-gc/common/src/main/java/com/redhat/thermostat/vm/gc/common/Constants.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common; - -import com.redhat.thermostat.common.Ordered; - -public class Constants { - - public static final int ORDER = Ordered.ORDER_MEMORY_GROUP + 20; - - private Constants() { - throw new AssertionError("Do not instantiate this"); - } - -} \ No newline at end of file
--- a/plugins/vm-gc/common/src/main/java/com/redhat/thermostat/vm/gc/common/GcCommonNameMapper.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,129 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -public class GcCommonNameMapper { - - private static final Map<Set<String>, CollectorCommonName> commonNameMap; - - public enum CollectorCommonName { - /** Serial Collector: {@code -XX:+UseSerialGC} */ - SERIAL_COLLECTOR("Serial Collector"), - /** G1 Collector: {@code -XX:+UseG1GC} */ - G1("Garbage-First Collector (G1)"), - /** Parallel Collector: {@code -XX:+UseParallelGC} */ - PARALLEL_COLLECTOR("Parallel Collector"), - /** Concurrent Mark and Sweep Collector: {@code +XX:+UseConcMarkSweepGC} */ - CONCURRENT_COLLECTOR("Concurrent Collector (Concurrent Mark and Sweep)"), - /** Mark Sweep Compact Collector: {@code -XX:+UseParNewGC} */ - MARK_SWEEP_COMPACT("Mark Sweep Compact Collector"), - /** Shenandoah Collector: {@code -XX:+UseShenandoahGC} */ - SHENANDOAH("Shenandoah Collector"), - UNKNOWN_COLLECTOR("Unknown Collector"); - - private String humanReadableName; - - private CollectorCommonName(String humanReadableName) { - this.humanReadableName = humanReadableName; - } - - public String getHumanReadableString() { - return humanReadableName; - } - } - - static { - commonNameMap = new HashMap<>(4); - // Serial collector has two sub collectors, MSC and Copy - Set<String> serialCollectorColls = new HashSet<>(2); - serialCollectorColls.add("MSC"); - serialCollectorColls.add("Copy"); - commonNameMap.put(serialCollectorColls, CollectorCommonName.SERIAL_COLLECTOR); - // Mark Sweep Compact GC has two sub collectors, MSC and PCopy - Set<String> msCompactColls = new HashSet<>(2); - msCompactColls.add("MSC"); - msCompactColls.add("PCopy"); - commonNameMap.put(msCompactColls, CollectorCommonName.MARK_SWEEP_COMPACT); - // Garbage first collector (G1) has only one collector, namely - // 'G1 incremental collections' - Set<String> g1Colls = new HashSet<>(1); - g1Colls.add("G1 incremental collections"); - commonNameMap.put(g1Colls, CollectorCommonName.G1); - // Current default, the Parallel Collector has two sub collectors: - // PSParallelCompact and PSScavenge - Set<String> parallelColls = new HashSet<>(2); - parallelColls.add("PSParallelCompact"); - parallelColls.add("PSScavenge"); - commonNameMap.put(parallelColls, CollectorCommonName.PARALLEL_COLLECTOR); - // Concurrent collector has two sub collectors: - // CMS and PCopy - Set<String> concurrentColls = new HashSet<>(2); - concurrentColls.add("CMS"); - concurrentColls.add("PCopy"); - commonNameMap.put(concurrentColls, CollectorCommonName.CONCURRENT_COLLECTOR); - // Shenandoah collector has 3 exposed sub collectors even though - // it's non-generational - Set<String> shenandoahColls = new HashSet<>(3); - shenandoahColls.add("Shenandoah concurrent phases"); - shenandoahColls.add("Shenandoah pauses"); - shenandoahColls.add("Shenandoah full GC pauses"); - commonNameMap.put(shenandoahColls, CollectorCommonName.SHENANDOAH); - } - - /** - * - * @param distinctCollectors - * A set of distinct collector names for one JVM. - * @return The common name of the collector for this set of distinct - * collectors. - */ - public CollectorCommonName mapToCommonName(Set<String> distinctCollectors) { - for (Set<String> subCollSet: commonNameMap.keySet()) { - if (subCollSet.equals(distinctCollectors)) { - return commonNameMap.get(subCollSet); - } - } - // not found so far? return unknown. - return CollectorCommonName.UNKNOWN_COLLECTOR; - } - -}
--- a/plugins/vm-gc/common/src/main/java/com/redhat/thermostat/vm/gc/common/VmGcStatDAO.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,47 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common; - -import com.redhat.thermostat.annotations.Service; -import com.redhat.thermostat.vm.gc.common.model.VmGcStat; - -@Service -public interface VmGcStatDAO { - - public void putVmGcStat(VmGcStat stat); -} -
--- a/plugins/vm-gc/common/src/main/java/com/redhat/thermostat/vm/gc/common/internal/LocaleResources.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.internal; - -import com.redhat.thermostat.shared.locale.Translate; - -public enum LocaleResources { - - VALIDATION_FAILED, - VALIDATION_WARNING, - VALIDATION_ERROR, - VALIDATION_FATAL_ERROR, - ; - - static final String RESOURCE_BUNDLE = "com.redhat.thermostat.vm.gc.common.locale.strings"; - - public static Translate<LocaleResources> createLocalizer() { - return new Translate<>(RESOURCE_BUNDLE, LocaleResources.class); - } -}
--- a/plugins/vm-gc/common/src/main/java/com/redhat/thermostat/vm/gc/common/internal/VmGcStatDAOImpl.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,147 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.internal; - -import java.io.IOException; -import java.util.Arrays; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; -import org.eclipse.jetty.client.api.ContentResponse; -import org.eclipse.jetty.http.HttpMethod; -import org.eclipse.jetty.http.HttpStatus; - -import com.redhat.thermostat.agent.http.HttpRequestService; -import com.redhat.thermostat.common.config.experimental.ConfigurationInfoSource; -import com.redhat.thermostat.common.plugins.PluginConfiguration; -import com.redhat.thermostat.common.utils.LoggingUtils; -import com.redhat.thermostat.vm.gc.common.VmGcStatDAO; -import com.redhat.thermostat.vm.gc.common.model.VmGcStat; - -@Component -@Service(value = VmGcStatDAO.class) -public class VmGcStatDAOImpl implements VmGcStatDAO { - - private static final Logger logger = LoggingUtils.getLogger(VmGcStatDAOImpl.class); - private static final String PLUGIN_ID = "vm-gc"; - static final String CONTENT_TYPE = "application/json"; - - private final JsonHelper jsonHelper; - private final ConfigurationCreator configCreator; - - @Reference - private ConfigurationInfoSource configInfoSource; - private String gatewayURL; - - @Reference - private HttpRequestService httpRequestService; - - public VmGcStatDAOImpl() { - this(new JsonHelper(new VmGcStatTypeAdapter()), new ConfigurationCreator(), null); - } - - VmGcStatDAOImpl(JsonHelper jh, ConfigurationCreator creator, ConfigurationInfoSource source) { - this.jsonHelper = jh; - this.configCreator = creator; - this.configInfoSource = source; - } - - @Activate - void activate() throws Exception { - PluginConfiguration config = configCreator.create(configInfoSource); - this.gatewayURL = config.getGatewayURL(); - } - - protected void bindHttpRequestService(HttpRequestService httpRequestService) { - this.httpRequestService = httpRequestService; - } - - protected void unbindHttpRequestService(HttpRequestService httpRequestService) { - this.httpRequestService = null; - } - - @Override - public void putVmGcStat(final VmGcStat stat) { - try { - String json = jsonHelper.toJson(Arrays.asList(stat)); - - if (null != httpRequestService) { - ContentResponse response = httpRequestService.sendHttpRequest(json, gatewayURL, HttpMethod.POST); - - int status = response.getStatus(); - if (status != HttpStatus.OK_200) { - throw new IOException("Gateway returned HTTP status " + String.valueOf(status) + " - " + response.getReason()); - } - - } else { - logger.log(Level.WARNING, "Failed to send VmGcStat information to web gateway. Http service unavailable."); - } - } catch (Exception e) { - logger.log(Level.WARNING, "Failed to send VmGcStat information to web gateway", e); - } - } - - // For Testing purposes - static class JsonHelper { - - private final VmGcStatTypeAdapter adapter; - - public JsonHelper(VmGcStatTypeAdapter adapter) { - this.adapter = adapter; - } - - public String toJson(List<VmGcStat> list) throws IOException { - return adapter.toJson(list); - } - - } - - // For Testing purposes - static class ConfigurationCreator { - - PluginConfiguration create(ConfigurationInfoSource source) { - return new PluginConfiguration(source, PLUGIN_ID); - } - - } -} -
--- a/plugins/vm-gc/common/src/main/java/com/redhat/thermostat/vm/gc/common/internal/VmGcStatTypeAdapter.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.internal; - -import com.google.gson.TypeAdapter; -import com.google.gson.stream.JsonReader; -import com.google.gson.stream.JsonWriter; -import com.redhat.thermostat.vm.gc.common.model.VmGcStat; - -import java.io.IOException; -import java.util.List; - -public class VmGcStatTypeAdapter extends TypeAdapter<List<VmGcStat>> { - - private static final String TYPE_LONG = "$numberLong"; - private static final String AGENT_ID = "agentId"; - private static final String VM_ID = "jvmId"; - private static final String TIMESTAMP = "timeStamp"; - private static final String COLLECTOR_NAME = "collectorName"; - private static final String RUN_COUNT = "runCount"; - private static final String WALL_TIME_IN_MICROS = "wallTimeInMicros"; - - @Override - public List<VmGcStat> read(JsonReader in) throws IOException { - throw new UnsupportedOperationException(); - } - - @Override - public void write(JsonWriter out, List<VmGcStat> stats) throws IOException { - out.beginArray(); - for (VmGcStat stat : stats) { - writeGcStat(out, stat); - } - out.endArray(); - } - - private void writeGcStat(JsonWriter out, VmGcStat stat) throws IOException { - out.beginObject(); - out.name(AGENT_ID); - out.value(stat.getAgentId()); - out.name(VM_ID); - out.value(stat.getVmId()); - out.name(TIMESTAMP); - writeLong(out, stat.getTimeStamp()); - out.name(COLLECTOR_NAME); - out.value(stat.getCollectorName()); - out.name(RUN_COUNT); - writeLong(out, stat.getRunCount()); - out.name(WALL_TIME_IN_MICROS); - writeLong(out, stat.getWallTime()); - out.endObject(); - } - - private void writeLong(JsonWriter out, long value) throws IOException { - // Write MongoDB representation of a Long - out.beginObject(); - out.name(TYPE_LONG); - out.value(String.valueOf(value)); - out.endObject(); - } -}
--- a/plugins/vm-gc/common/src/main/java/com/redhat/thermostat/vm/gc/common/model/VmGcStat.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,119 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.model; - -import com.redhat.thermostat.storage.core.Entity; -import com.redhat.thermostat.storage.core.Persist; -import com.redhat.thermostat.storage.model.BasePojo; -import com.redhat.thermostat.storage.model.TimeStampedPojo; - -@Entity -public class VmGcStat extends BasePojo implements TimeStampedPojo { - - private long timeStamp; - private String vmId; - private String collectorName; - private long runCount; - private long wallTimeInMicros; - - public VmGcStat() { - super(null); - } - - public VmGcStat(String writerId, String vmId, long timestamp, String collectorName, long runCount, long wallTimeInMicros) { - super(writerId); - this.timeStamp = timestamp; - this.vmId = vmId; - this.collectorName = collectorName; - this.runCount = runCount; - this.wallTimeInMicros = wallTimeInMicros; - } - - @Persist - public String getVmId() { - return vmId; - } - - @Persist - public void setVmId(String vmId) { - this.vmId = vmId; - } - - @Persist - public String getCollectorName() { - return collectorName; - } - - @Persist - public void setCollectorName(String collectorName) { - this.collectorName = collectorName; - } - - @Persist - public long getRunCount() { - return runCount; - } - - @Persist - public void setRunCount(long runCount) { - this.runCount = runCount; - } - - /** In microseconds */ - @Persist - public long getWallTime() { - return wallTimeInMicros; - } - - @Persist - public void setWallTime(long wallTimeInMicros) { - this.wallTimeInMicros = wallTimeInMicros; - } - - @Override - @Persist - public long getTimeStamp() { - return timeStamp; - } - - @Persist - public void setTimeStamp(long timeStamp) { - this.timeStamp = timeStamp; - } - -} -
--- a/plugins/vm-gc/common/src/main/java/com/redhat/thermostat/vm/gc/common/params/AbstractValidationError.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,94 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.params; - -/** - * - * Exception thrown on XML validation errors of gc-params-mapping.xml files. - * - */ -public abstract class AbstractValidationError implements ValidationIssue { - - private int lineNumber; - private int columnNumber; - private String message; - private String gcParamsMappingXmlFilePath; - - public AbstractValidationError(int lineNumber, int columnNumber, String message, String gcParamsMappingXmlFilePath) { - this.lineNumber = lineNumber; - this.columnNumber = columnNumber; - this.message = message; - this.gcParamsMappingXmlFilePath = gcParamsMappingXmlFilePath; - } - - @Override - public int getLineNumber() { - return lineNumber; - } - - @Override - public int getColumnNumber() { - return columnNumber; - } - - @Override - public String getMessage() { - return message; - } - - @Override - public String getXmlFilePath() { - return gcParamsMappingXmlFilePath; - } - - public String toString() { - String LS = System.getProperty("line.separator"); - StringBuilder builder = new StringBuilder(); - - builder.append("[").append(getName()).append("]").append(LS); - builder.append(" Message: ").append(getMessage()).append(LS); - builder.append(" File: ").append(getXmlFilePath()).append(LS); - builder.append(" Line number: ").append(getLineNumber()).append(LS); - builder.append(" Column number: ").append(getColumnNumber()).append(LS); - - return builder.toString(); - - } - - public abstract String getName(); - -} \ No newline at end of file
--- a/plugins/vm-gc/common/src/main/java/com/redhat/thermostat/vm/gc/common/params/Collector.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,78 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.params; - -import java.util.HashSet; -import java.util.Objects; -import java.util.Set; - -import static java.util.Objects.requireNonNull; - -public class Collector { - - private final CollectorInfo collectorInfo; - private final Set<GcParam> gcParams; - - public Collector(CollectorInfo collectorInfo, Set<GcParam> gcParams) { - this.collectorInfo = requireNonNull(collectorInfo); - this.gcParams = new HashSet<>(requireNonNull(gcParams)); - } - - public CollectorInfo getCollectorInfo() { - return collectorInfo; - } - - public Set<GcParam> getGcParams() { - return gcParams; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Collector collector = (Collector) o; - - return Objects.equals(collectorInfo, collector.collectorInfo) - && Objects.equals(gcParams, collector.gcParams); - } - - @Override - public int hashCode() { - return Objects.hash(collectorInfo, gcParams); - } -} \ No newline at end of file
--- a/plugins/vm-gc/common/src/main/java/com/redhat/thermostat/vm/gc/common/params/CollectorInfo.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.params; - -import java.util.HashSet; -import java.util.Objects; -import java.util.Set; - -import static java.util.Objects.requireNonNull; - -public class CollectorInfo { - - private final JavaVersionRange javaVersionRange; - private final String commonName; - private final Set<String> collectorDistinctNames; - private final String referenceUrl; - - public CollectorInfo(JavaVersionRange javaVersionRange, String commonName, Set<String> collectorDistinctNames, String referenceUrl) { - this.javaVersionRange = requireNonNull(javaVersionRange); - this.commonName = requireNonNull(commonName); - this.collectorDistinctNames = new HashSet<>(requireNonNull(collectorDistinctNames)); - this.referenceUrl = requireNonNull(referenceUrl); - } - - public JavaVersionRange getJavaVersionRange() { - return javaVersionRange; - } - - public String getCommonName() { - return commonName; - } - - public Set<String> getCollectorDistinctNames() { - return new HashSet<>(collectorDistinctNames); - } - - public String getReferenceUrl() { - return referenceUrl; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - CollectorInfo that = (CollectorInfo) o; - - return Objects.equals(javaVersionRange, that.javaVersionRange) - && Objects.equals(commonName, that.commonName) - && Objects.equals(collectorDistinctNames, that.collectorDistinctNames) - && Objects.equals(referenceUrl, that.referenceUrl); - } - - @Override - public int hashCode() { - return Objects.hash(javaVersionRange, commonName, collectorDistinctNames, referenceUrl); - } -}
--- a/plugins/vm-gc/common/src/main/java/com/redhat/thermostat/vm/gc/common/params/Error.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.params; - -public class Error extends AbstractValidationError { - - Error(int lineNumber, int columnNumber, String message, String gcParamsMappingXmlFilePath) { - super(lineNumber, columnNumber, message, gcParamsMappingXmlFilePath); - } - - @Override - public String getName() { - return this.getClass().getSimpleName(); - } - -}
--- a/plugins/vm-gc/common/src/main/java/com/redhat/thermostat/vm/gc/common/params/FatalError.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.params; - -public class FatalError extends AbstractValidationError { - - FatalError(int lineNumber, int columnNumber, String message, String gcParamsMappingXmlFilePath) { - super(lineNumber, columnNumber, message, gcParamsMappingXmlFilePath); - } - - @Override - public String getName() { - return this.getClass().getSimpleName(); - } - -}
--- a/plugins/vm-gc/common/src/main/java/com/redhat/thermostat/vm/gc/common/params/GcParam.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,87 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.params; - -import java.util.Objects; - -import static java.util.Objects.requireNonNull; - -public class GcParam { - - private final String flag; - private final String description; - private final JavaVersionRange javaVersionRange; - - public GcParam(String flag, String description, JavaVersionRange javaVersionRange) { - this.flag = requireNonNull(flag); - this.description = requireNonNull(description); - this.javaVersionRange = requireNonNull(javaVersionRange); - } - - public String getFlag() { - return flag; - } - - public String getDescription() { - return description; - } - - public JavaVersionRange getJavaVersionRange() { - return javaVersionRange; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - GcParam gcParam = (GcParam) o; - - return Objects.equals(flag, gcParam.flag) - && Objects.equals(description, gcParam.description) - && Objects.equals(javaVersionRange, gcParam.javaVersionRange); - } - - @Override - public int hashCode() { - return Objects.hash(flag, description, javaVersionRange); - } -}
--- a/plugins/vm-gc/common/src/main/java/com/redhat/thermostat/vm/gc/common/params/GcParamsMapper.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,146 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.params; - -import com.redhat.thermostat.common.utils.LoggingUtils; -import com.redhat.thermostat.shared.locale.Translate; -import com.redhat.thermostat.vm.gc.common.GcCommonNameMapper; -import com.redhat.thermostat.vm.gc.common.internal.LocaleResources; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.logging.Logger; - -public enum GcParamsMapper { - - INSTANCE; - - static final String XML_RESOURCE_URL = "/com/redhat/thermostat/vm/gc/common/gc-params-mapping.xml"; - - private final Translate<LocaleResources> translator = LocaleResources.createLocalizer(); - private final Logger logger = LoggingUtils.getLogger(GcParamsMapper.class); - private final Map<GcCommonNameMapper.CollectorCommonName, Collector> paramsMap = new HashMap<>(); - private final Set<GcParam> commonParams = new HashSet<>(); - - GcParamsMapper() { - validateGcParamsMapping(); - parseGcParamsMapping(); - } - - void validateGcParamsMapping() { - InputStream xmlStream; - try { - xmlStream = getXmlStream(); - GcParamsMappingValidator validator = new GcParamsMappingValidator(); - validator.validate(XML_RESOURCE_URL, xmlStream); - } catch (URISyntaxException | FileNotFoundException e) { - logger.warning(translator.localize( - LocaleResources.VALIDATION_FAILED, - XML_RESOURCE_URL, - e.getLocalizedMessage()) - .getContents()); - } catch (GcParamsMappingValidatorException e) { - ValidationErrorsFormatter formatter = new ValidationErrorsFormatter(); - logger.warning(translator.localize( - LocaleResources.VALIDATION_FAILED, - XML_RESOURCE_URL, - formatter.format(e.getAllErrors())) - .getContents()); - } - } - - InputStream getXmlStream() throws URISyntaxException { - return this.getClass().getResourceAsStream(XML_RESOURCE_URL); - } - - private void parseGcParamsMapping() { - try { - GcParamsParser parser = new GcParamsParser(getXmlStream()); - GcParamsParser.ParseResult parseResult = parser.parse(); - for (Collector collector : parseResult.getCollectors()) { - GcCommonNameMapper commonNameMapper = new GcCommonNameMapper(); - paramsMap.put(commonNameMapper.mapToCommonName(collector.getCollectorInfo().getCollectorDistinctNames()), collector); - } - commonParams.addAll(parseResult.getGcCommonParams()); - } catch (URISyntaxException | IOException | GcParamsParser.GcParamsParseException e) { - logger.warning("Failed to parse " + XML_RESOURCE_URL + " : " + e.getLocalizedMessage()); - } - } - - List<Collector> getCollectors() { - return new ArrayList<>(paramsMap.values()); - } - - Set<GcParam> getCommonParams() { - return new HashSet<>(commonParams); - } - - public List<GcParam> getParams(GcCommonNameMapper.CollectorCommonName collectorCommonName, JavaVersionRange javaVersionRange) { - Objects.requireNonNull(collectorCommonName); - Objects.requireNonNull(javaVersionRange); - if (!paramsMap.containsKey(collectorCommonName)) { - return Collections.emptyList(); - } - Collector collector = paramsMap.get(collectorCommonName); - if (collector == null || !collector.getCollectorInfo().getJavaVersionRange().contains(javaVersionRange)) { - return Collections.emptyList(); - } - List<GcParam> params = new ArrayList<>(); - for (GcParam param : collector.getGcParams()) { - if (param.getJavaVersionRange().contains(javaVersionRange)) { - params.add(param); - } - } - params.addAll(commonParams); - return params; - } - - public static GcParamsMapper getInstance() { - return INSTANCE; - } - -}
--- a/plugins/vm-gc/common/src/main/java/com/redhat/thermostat/vm/gc/common/params/GcParamsMappingValidator.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.params; - -import org.xml.sax.SAXException; - -import javax.xml.XMLConstants; -import javax.xml.transform.stream.StreamSource; -import javax.xml.validation.Schema; -import javax.xml.validation.SchemaFactory; -import javax.xml.validation.Validator; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; - -public class GcParamsMappingValidator { - - static final String XSD_RESOURCE_URL = "/com/redhat/thermostat/vm/gc/common/gc-params-mapping.xsd"; - - public void validate(String path, InputStream gcParamsMappingXmlStream) throws GcParamsMappingValidatorException, FileNotFoundException { - URL schemaUrl = GcParamsMappingValidator.class.getResource(XSD_RESOURCE_URL); - SchemaFactory schemaFactory = - SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); - GcParamsMappingValidatorErrorHandler handler = new GcParamsMappingValidatorErrorHandler(path); - - try { - Schema schema = schemaFactory.newSchema(schemaUrl); - Validator validator = schema.newValidator(); - validator.setErrorHandler(handler); - validator.validate(new StreamSource(gcParamsMappingXmlStream)); - } catch (SAXException exception) { - throw new GcParamsMappingValidatorException( - "gc-params-mapping.xml not well-formed XML", path, - handler.getErrors(), handler.getWarnings(), - handler.getFatalErrors(), exception); - } catch (FileNotFoundException fnfe) { - throw fnfe; - } catch (IOException ioe) { - throw new GcParamsMappingValidatorException( - ioe.getLocalizedMessage(), path, handler.getErrors(), - handler.getWarnings(), handler.getFatalErrors(), ioe); - } - - // We've registered an exception handler, so validation issues do not throw - // exceptions unless the xml file itself is not valid. Let's ask the handler - // if there were issues so we can throw an exception accordingly. - if (handler.hasValidationIssues()) { - throw new GcParamsMappingValidatorException( - "Failed to validate gc-params-mapping.xml", path, - handler.getErrors(), handler.getWarnings(), - handler.getFatalErrors()); - } - } - -} \ No newline at end of file
--- a/plugins/vm-gc/common/src/main/java/com/redhat/thermostat/vm/gc/common/params/GcParamsMappingValidatorErrorHandler.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,110 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.params; - -import java.util.ArrayList; -import java.util.List; - -import org.xml.sax.ErrorHandler; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; - -public class GcParamsMappingValidatorErrorHandler implements ErrorHandler { - - private final String gcParamsMappingXmlFilePath; - private final List<ValidationIssue> warnings; - private final List<ValidationIssue> errors; - private final List<ValidationIssue> fatalErrors; - - public GcParamsMappingValidatorErrorHandler(String gcParamsMappingXmlFilePath) { - this.gcParamsMappingXmlFilePath = gcParamsMappingXmlFilePath; - warnings = new ArrayList<>(); - errors = new ArrayList<>(); - fatalErrors = new ArrayList<>(); - } - - @Override - public void warning(SAXParseException exception) throws SAXException { - Warning newWarning = new Warning(exception.getLineNumber(), - exception.getColumnNumber(), - exception.getLocalizedMessage(), - gcParamsMappingXmlFilePath); - warnings.add(newWarning); - } - - @Override - public void error(SAXParseException exception) throws SAXParseException { - Error newError = new Error(exception.getLineNumber(), - exception.getColumnNumber(), - exception.getLocalizedMessage(), - gcParamsMappingXmlFilePath); - errors.add(newError); - } - - @Override - public void fatalError(SAXParseException exception) throws SAXParseException { - // Fatal errors will be reported just when no validation warnings and errors happened. - // In this way we avoid wrong messages of bad form for files that have wrong tags not closed properly - if (errors.size() == 0 && warnings.size() == 0) { - FatalError newFatalError = new FatalError(exception.getLineNumber(), - exception.getColumnNumber(), - exception.getLocalizedMessage(), - gcParamsMappingXmlFilePath); - fatalErrors.add(newFatalError); - } - } - - public List<ValidationIssue> getWarnings() { - return warnings; - } - - public List<ValidationIssue> getErrors() { - return errors; - } - - public List<ValidationIssue> getFatalErrors() { - return fatalErrors; - } - - public boolean hasValidationIssues() { - return errors.size() > 0 || - warnings.size() > 0 || - fatalErrors.size() > 0; - } - -} -
--- a/plugins/vm-gc/common/src/main/java/com/redhat/thermostat/vm/gc/common/params/GcParamsMappingValidatorException.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,148 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.params; - -import java.util.ArrayList; -import java.util.List; - -/** - * Thrown if there were schema validation issues or other problems in a - * gc-params-mapping.xml - * - */ -public class GcParamsMappingValidatorException extends Exception { - - private static final long serialVersionUID = 1L; - private final String xmlFilePath; - private final List<ValidationIssue> warnings; - private final List<ValidationIssue> errors; - private final List<ValidationIssue> fatals; - - /** - * Constructor. - * - * Calls - * {@link #GcParamsMappingValidatorException(String, String, List, List, List, Throwable)} - * with a null cause. - */ - public GcParamsMappingValidatorException(String message, String xmlFilePath, - List<ValidationIssue> errors, List<ValidationIssue> warnings, - List<ValidationIssue> fatals) { - this(message, xmlFilePath, errors, warnings, fatals, null); - } - - /** - * Constructor. - * - * @param message - * A descriptive message. - * @param xmlFilePath - * The gc-params-mapping.xml file path which caused this exception to - * be thrown. - * @param errors - * The list of schema validation errors. - * @param warnings - * The list of (validation) warnings. - * @param fatals - * The list of fatal (validation) errors. - * @param cause - * The underlying exception. May be null. - */ - public GcParamsMappingValidatorException(String message, String xmlFilePath, - List<ValidationIssue> errors, List<ValidationIssue> warnings, - List<ValidationIssue> fatals, Throwable cause) { - super(message); - this.xmlFilePath = xmlFilePath; - this.warnings = warnings; - this.errors = errors; - this.fatals = fatals; - } - - /** - * - * @return The list of all validation issues. - */ - public List<ValidationIssue> getAllErrors() { - List<ValidationIssue> errorsList = new ArrayList<>(); - errorsList.addAll(warnings); - errorsList.addAll(errors); - errorsList.addAll(fatals); - return errorsList; - } - - /** - * - * @return The gc-params-mapping.xml file which failed validation. - */ - public String getXmlFilePath() { - return xmlFilePath; - } - - /** - * Conditions that are not errors or fatal errors as defined by the XML - * recommendation. - * - * @return The list of (validation) warnings. - */ - public List<ValidationIssue> getWarnings() { - return warnings; - } - - /** - * Each validation issue corresponds to the definition of "error" in section - * 1.2 of the W3C XML 1.0 Recommendation. - * - * @return The list of violations of schema validity constraints. - */ - public List<ValidationIssue> getErrors() { - return errors; - } - - /** - * Each validation issue corresponds to the definition of "fatal error" in - * section 1.2 of the W3C XML 1.0 Recommendation. - * - * @return The list of fatal (i.e. non-recoverable) errors. Fatal issues may - * occur if the gc-params-mapping.xml violates well-formedness - * constraints. - */ - public List<ValidationIssue> getFatals() { - return fatals; - } - -} -
--- a/plugins/vm-gc/common/src/main/java/com/redhat/thermostat/vm/gc/common/params/GcParamsParser.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,317 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.params; - -import com.redhat.thermostat.common.Pair; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.ErrorHandler; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class GcParamsParser { - - private static final String ROOT_NODE_NAME = "gc-params-mapping"; - private static final String COMMON_PARAMS_NODE_NAME = "common"; - private static final String COLLECTOR_NODE_NAME = "collector"; - private static final String COLLECTOR_INFO_NODE_NAME = "collector-info"; - private static final String GC_PARAMS_NODE_NAME = "gc-params"; - private static final String VERSION_NODE_NAME = "version"; - private static final String COMMON_NAME_NODE_NAME = "common-name"; - private static final String COLLECTOR_DISTINCT_NAMES_NODE_NAME = "collector-distinct-names"; - private static final String COLLECTOR_DISTINCT_NAME_NODE_NAME = "collector-name"; - private static final String REFERENCE_URL_NODE_NAME = "url"; - private static final String GC_PARAM_NODE_NAME = "gc-param"; - private static final String FLAG_NODE_NAME = "flag"; - private static final String DESCRIPTION_NODE_NAME = "description"; - - private final InputStream xmlStream; - - public GcParamsParser(InputStream xmlStream) { - this.xmlStream = xmlStream; - } - - public ParseResult parse() throws GcParamsParseException, IOException { - return parse(xmlStream); - } - - static ParseResult parse(InputStream inputStream) throws GcParamsParseException { - try { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setIgnoringComments(true); - DocumentBuilder builder = factory.newDocumentBuilder(); - builder.setErrorHandler(new GcParamsParserErrorHandler()); - Document xmlDoc = builder.parse(inputStream); - Node rootNode = xmlDoc.getFirstChild(); - if (rootNode == null) { - throw new GcParamsParseException("Invalid document, could not identify root node"); - } - return parseRootElement(rootNode); - } catch (ParserConfigurationException | SAXException | IOException e) { - throw new GcParamsParseException(e); - } - } - - static ParseResult parseRootElement(Node rootNode) { - List<Collector> collectors = new ArrayList<>(); - Set<GcParam> commonParams = new HashSet<>(); - if (rootNode.getNodeName().equals(ROOT_NODE_NAME)) { - NodeList nodes = rootNode.getChildNodes(); - for (int i = 0; i < nodes.getLength(); i++) { - Node node = nodes.item(i); - if (node.getNodeName().equals(COLLECTOR_NODE_NAME)) { - collectors.add(parseCollector(node)); - } else if (node.getNodeName().equals(COMMON_PARAMS_NODE_NAME)) { - commonParams.addAll(parseCommonParams(node)); - } - } - } - return new ParseResult(collectors, commonParams); - } - - static Set<GcParam> parseCommonParams(Node gcCommonParamsNode) { - Set<GcParam> gcCommonParams = new HashSet<>(); - if (gcCommonParamsNode.getNodeName().equals(COMMON_PARAMS_NODE_NAME)) { - NodeList nodes = gcCommonParamsNode.getChildNodes(); - for (int i = 0; i < nodes.getLength(); i++) { - Node node = nodes.item(i); - if (node.getNodeName().equals(GC_PARAMS_NODE_NAME)) { - JavaVersionRange allJavaVersionRange - = new JavaVersionRange(JavaVersionRange.VersionPoints.MINIMUM_VERSION, true, - JavaVersionRange.VersionPoints.MAXIMUM_VERSION, true); - gcCommonParams.addAll(parseGcParams(node, allJavaVersionRange)); - } - } - } - return gcCommonParams; - } - - static Collector parseCollector(Node collectorNode) { - CollectorInfo collectorInfo = null; - Set<GcParam> gcParams = Collections.emptySet(); - if (collectorNode.getNodeName().equals(COLLECTOR_NODE_NAME)) { - NodeList nodes = collectorNode.getChildNodes(); - for (int i = 0; i < nodes.getLength(); i++) { - Node node = nodes.item(i); - if (node.getNodeName().equals(COLLECTOR_INFO_NODE_NAME)) { - collectorInfo = parseCollectorInfo(node); - } else if (node.getNodeName().equals(GC_PARAMS_NODE_NAME)) { - gcParams = parseGcParams(node, collectorInfo.getJavaVersionRange()); - } - } - } - return new Collector(collectorInfo, gcParams); - } - - static CollectorInfo parseCollectorInfo(Node collectorInfoNode) { - JavaVersionRange javaVersionRange = null; - String commonName = ""; - Set<String> collectorDistinctNames = Collections.emptySet(); - String referenceUrl = ""; - if (collectorInfoNode.getNodeName().equals(COLLECTOR_INFO_NODE_NAME)) { - NodeList nodes = collectorInfoNode.getChildNodes(); - for (int i = 0; i < nodes.getLength(); i++) { - Node node = nodes.item(i); - if (node.getNodeName().equals(VERSION_NODE_NAME)) { - javaVersionRange = parseVersion(node); - } else if (node.getNodeName().equals(COMMON_NAME_NODE_NAME)) { - commonName = parseCommonName(node); - } else if (node.getNodeName().equals(COLLECTOR_DISTINCT_NAMES_NODE_NAME)) { - collectorDistinctNames = parseDistinctNames(node); - } else if (node.getNodeName().equals(REFERENCE_URL_NODE_NAME)) { - referenceUrl = parseReferenceUrl(node); - } - } - } - return new CollectorInfo(javaVersionRange, commonName, collectorDistinctNames, referenceUrl); - } - - static JavaVersionRange parseVersion(Node versionNode) { - JavaVersionRange javaVersionRange = null; - if (versionNode.getNodeName().equals(VERSION_NODE_NAME)) { - try { - javaVersionRange = JavaVersionRange.fromString(versionNode.getTextContent()); - } catch (JavaVersionRange.InvalidJavaVersionFormatException e) { - throw new GcParamsParseException(e); - } - } - return javaVersionRange; - } - - static String parseCommonName(Node commonNameNode) { - String commonName = ""; - if (commonNameNode.getNodeName().equals(COMMON_NAME_NODE_NAME)) { - commonName = commonNameNode.getTextContent(); - } - return commonName; - } - - static Set<String> parseDistinctNames(Node distinctNamesNode) { - Set<String> distinctNames = new HashSet<>(); - if (distinctNamesNode.getNodeName().equals(COLLECTOR_DISTINCT_NAMES_NODE_NAME)) { - NodeList nodes = distinctNamesNode.getChildNodes(); - for (int i = 0; i < nodes.getLength(); i++) { - Node node = nodes.item(i); - if (node.getNodeName().equals(COLLECTOR_DISTINCT_NAME_NODE_NAME)) { - distinctNames.add(parseDistinctName(node)); - } - } - } - return distinctNames; - } - - static String parseDistinctName(Node distinctNameNode) { - String distinctName = ""; - if (distinctNameNode.getNodeName().equals(COLLECTOR_DISTINCT_NAME_NODE_NAME)) { - distinctName = distinctNameNode.getTextContent(); - } - return distinctName; - } - - static String parseReferenceUrl(Node referenceUrlNode) { - String referenceUrl = ""; - if (referenceUrlNode.getNodeName().equals(REFERENCE_URL_NODE_NAME)) { - referenceUrl = referenceUrlNode.getTextContent(); - } - return referenceUrl; - } - - static Set<GcParam> parseGcParams(Node gcParamsNode, JavaVersionRange inheritedJavaVersionRange) { - Set<GcParam> gcParams = new HashSet<>(); - if (gcParamsNode.getNodeName().equals(GC_PARAMS_NODE_NAME)) { - NodeList nodes = gcParamsNode.getChildNodes(); - for (int i = 0; i < nodes.getLength(); i++) { - Node node = nodes.item(i); - if (node.getNodeName().equals(GC_PARAM_NODE_NAME)) { - gcParams.add(parseGcParam(node, inheritedJavaVersionRange)); - } - } - } - return gcParams; - } - - static GcParam parseGcParam(Node gcParamNode, JavaVersionRange inheritedJavaVersionRange) { - String flag = ""; - String description = ""; - JavaVersionRange javaVersionRange = inheritedJavaVersionRange; - if (gcParamNode.getNodeName().equals(GC_PARAM_NODE_NAME)) { - NodeList nodes = gcParamNode.getChildNodes(); - for (int i = 0; i < nodes.getLength(); i++) { - Node node = nodes.item(i); - if (node.getNodeName().equals(FLAG_NODE_NAME)) { - flag = parseFlag(node); - } else if (node.getNodeName().equals(DESCRIPTION_NODE_NAME)) { - description = parseDescription(node); - } else if (node.getNodeName().equals(VERSION_NODE_NAME)) { - javaVersionRange = parseVersion(node); - } - } - } - return new GcParam(flag, description, javaVersionRange); - } - - static String parseFlag(Node flagNode) { - String flag = ""; - if (flagNode.getNodeName().equals(FLAG_NODE_NAME)) { - flag = flagNode.getTextContent(); - } - return flag; - } - - static String parseDescription(Node descriptionNode) { - String description = ""; - if (descriptionNode.getNodeName().equals(DESCRIPTION_NODE_NAME)) { - description = descriptionNode.getTextContent(); - } - return description.trim().replaceAll("\\s+", " "); - } - - public static class ParseResult extends Pair<List<Collector>, Set<GcParam>> { - - ParseResult(List<Collector> collectors, Set<GcParam> gcCommonParams) { - super(collectors, gcCommonParams); - } - - public List<Collector> getCollectors() { - return super.getFirst(); - } - - public Set<GcParam> getGcCommonParams() { - return super.getSecond(); - } - - } - - private static class GcParamsParserErrorHandler implements ErrorHandler { - @Override - public void warning(SAXParseException e) throws SAXException { - // no-op - } - - @Override - public void error(SAXParseException e) throws SAXException { - throw e; - } - - @Override - public void fatalError(SAXParseException e) throws SAXException { - throw e; - } - } - - public static class GcParamsParseException extends RuntimeException { - public GcParamsParseException(String message) { - super(message); - } - - public GcParamsParseException(Throwable cause) { - super(cause); - } - } -}
--- a/plugins/vm-gc/common/src/main/java/com/redhat/thermostat/vm/gc/common/params/JavaVersionRange.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,398 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.params; - -import java.util.Objects; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import static java.util.Objects.requireNonNull; - -/** - * Models a range of Java versions, using maven version format: - * https://maven.apache.org/enforcer/enforcer-rules/versionRanges.html - * - * A single, exact version number of "w.x.y.z" is considered as a short form for the range "[w.x.y.z,w.x.y.z]" - */ -public class JavaVersionRange implements Comparable<JavaVersionRange> { - - private static final String LBRACK = "([\\[\\(])"; - private static final String RBRACK = "([\\]\\)])"; - private static final String NUM = "([0-9]+)"; - private static final String DOT = "\\."; - // Allow for '_' and '.' as delimiters; Do *not* use "-" as - // delimiter since that is reserved for the pre-release snippet. - private static final String UPDATE_DELIMITER = "[._]"; - private static final String COMMA = ","; - private static final String UPDATE_PATTERN = UPDATE_DELIMITER + NUM; - private static final String OPTIONAL_UPDATE_PATTERN = "(?:" + UPDATE_PATTERN + ")?"; // non-capturing group - private static final String PRE_RELEASE_PATTERN = "-([0-9a-zA-Z]+)"; - private static final String OPTIONAL_PRE_RELEASE_PATTERN = "(?:" + PRE_RELEASE_PATTERN + ")?"; // non-capturing group - private static final String OPTIONAL_VENDOR_PATTERN = OPTIONAL_PRE_RELEASE_PATTERN; // non-capturing group - private static final String OPTIONAL_SUFFIX = "(" + OPTIONAL_UPDATE_PATTERN + OPTIONAL_PRE_RELEASE_PATTERN + OPTIONAL_VENDOR_PATTERN + ")"; - private static final String SINGLE_VERSION_PATTERN_STRING = NUM + DOT + NUM + DOT + NUM + OPTIONAL_SUFFIX; - private static final String VERSION_PATTERN_STRING = LBRACK + "?" + "(" + SINGLE_VERSION_PATTERN_STRING + ")" + RBRACK + "?"; - private static final String RANGE_PATTERN_STRING = LBRACK + "(" + SINGLE_VERSION_PATTERN_STRING + ")?" + COMMA - + "(" + SINGLE_VERSION_PATTERN_STRING + ")?" + RBRACK; - private static final Pattern VERSION_PATTERN = Pattern.compile(VERSION_PATTERN_STRING); - private static final Pattern RANGE_PATTERN = Pattern.compile(RANGE_PATTERN_STRING); - - private final boolean lowerInclusive, upperInclusive; - private final VersionPoints lowerBound, upperBound; - - public JavaVersionRange(int major, int minor, int micro, int update) { - this(new VersionPoints(major, minor, micro, update)); - } - - public JavaVersionRange(VersionPoints versionPoints) { - this(versionPoints, true, versionPoints, true); - } - - public JavaVersionRange(VersionPoints lowerBound, boolean lowerInclusive, VersionPoints upperBound, boolean upperInclusive) { - this.lowerBound = requireNonNull(lowerBound); - this.upperBound = requireNonNull(upperBound); - this.lowerInclusive = lowerInclusive; - this.upperInclusive = upperInclusive; - if (lowerBound.compareTo(upperBound) > 0) { - throw new InvalidJavaVersionFormatException("Range must ascend"); - } - if (lowerBound.equals(upperBound) && !isLowerBoundInclusive() && !isUpperBoundInclusive()) { - throw new InvalidJavaVersionFormatException("Range is empty: " + this); - } - } - - public static JavaVersionRange fromString(String javaVersionString) { - validateFormat(javaVersionString); - Matcher singleVersionMatcher = VERSION_PATTERN.matcher(javaVersionString); - if (singleVersionMatcher.matches()) { - VersionPoints points = VersionPoints.fromString(singleVersionMatcher.group(2)); - String leftBracket = singleVersionMatcher.group(1); - String rightBracket = singleVersionMatcher.group(10); - if (leftBracket == null && rightBracket == null) { - return new JavaVersionRange(points); - } else if (leftBracket != null && rightBracket != null) { - return new JavaVersionRange(points, isInclusive(leftBracket.charAt(0)), points, isInclusive(rightBracket.charAt(0))); - } else { - throw new InvalidJavaVersionFormatException("Unmatched bracket in version string: " + javaVersionString); - } - } else { - Matcher rangeVersionMatcher = RANGE_PATTERN.matcher(javaVersionString); - if (rangeVersionMatcher.matches()) { - String lower = rangeVersionMatcher.group(2); - String upper = rangeVersionMatcher.group(10); - VersionPoints lowerBound, upperBound; - if (lower == null && upper == null) { - throw new InvalidJavaVersionFormatException("Cannot specify a range without any bounds"); - } else if (lower == null) { - lowerBound = VersionPoints.MINIMUM_VERSION; - upperBound = VersionPoints.fromString(upper); - } else if (upper == null) { - lowerBound = VersionPoints.fromString(lower); - upperBound = VersionPoints.MAXIMUM_VERSION; - } else { - lowerBound = VersionPoints.fromString(lower); - upperBound = VersionPoints.fromString(upper); - } - String leftBracket = rangeVersionMatcher.group(1); - String rightBracket = rangeVersionMatcher.group(18); - return new JavaVersionRange(lowerBound, isInclusive(leftBracket.charAt(0)), upperBound, isInclusive(rightBracket.charAt(0))); - } else { - throw new InvalidJavaVersionFormatException(javaVersionString); - // shouldn't reach here - if it doesn't match either pattern then validateFormat should have caught it already - } - } - } - - static boolean isInclusive(char brack) { - if (brack == '[' || brack == ']') { - return true; - } else if (brack == '(' || brack == ')') { - return false; - } else { - throw new IllegalArgumentException(Character.toString(brack)); - } - } - - public boolean isRange() { - return !lowerBound.equals(upperBound); - } - - public JavaVersionRange getLowerBound() { - return new JavaVersionRange(lowerBound); - } - - public JavaVersionRange getUpperBound() { - return new JavaVersionRange(upperBound); - } - - public boolean isLowerBoundInclusive() { - return lowerInclusive; - } - - public boolean isUpperBoundInclusive() { - return upperInclusive; - } - - public boolean contains(JavaVersionRange other) { - if (!isRange()) { - return this.equals(other); - } - - final int lower = lowerBound.compareTo(other.lowerBound); - final int upper = upperBound.compareTo(other.upperBound); - - if (lower > 0 || upper < 0) { - return false; - } - - if (lower == 0) { - return isLowerBoundInclusive(); - } - - if (upper == 0) { - return isUpperBoundInclusive(); - } - - return true; - } - - @Override - public int compareTo(JavaVersionRange javaVersionRange) { - if (this.equals(javaVersionRange)) { - return 0; - } - if (javaVersionRange == null) { - return 1; - } - if (isRange() && javaVersionRange.isRange()) { - return -1; - } - - return lowerBound.compareTo(javaVersionRange.lowerBound); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - JavaVersionRange javaVersionRange = (JavaVersionRange) o; - - return lowerBound.equals(javaVersionRange.lowerBound) && upperBound.equals(javaVersionRange.upperBound) - && isLowerBoundInclusive() == javaVersionRange.isLowerBoundInclusive() - && isUpperBoundInclusive() == javaVersionRange.isUpperBoundInclusive(); - } - - @Override - public int hashCode() { - return Objects.hash(lowerBound, upperBound, lowerInclusive, upperInclusive); - } - - @Override - public String toString() { - StringBuilder sb = new StringBuilder(); - - if (isLowerBoundInclusive()) { - sb.append('['); - } else { - sb.append('('); - } - - sb.append(lowerBound.toString()); - if (isRange()) { - sb.append(','); - sb.append(upperBound.toString()); - } - - if (isUpperBoundInclusive()) { - sb.append(']'); - } else { - sb.append(')'); - } - - return sb.toString(); - } - - static void validateFormat(String rawVersion) { - if (rawVersion == null) { - throw new InvalidJavaVersionFormatException(null); - } - Matcher singleVersionMatcher = VERSION_PATTERN.matcher(rawVersion); - Matcher rangeMatcher = RANGE_PATTERN.matcher(rawVersion); - if (!(singleVersionMatcher.matches() || rangeMatcher.matches())) { - throw new InvalidJavaVersionFormatException(rawVersion); - } - } - - public static class VersionPoints implements Comparable<VersionPoints> { - - static final VersionPoints MINIMUM_VERSION = new VersionPoints(0, 0, 0, 0); - static final VersionPoints MAXIMUM_VERSION = new VersionPoints(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE); - - private final int major; - private final int minor; - private final int micro; - private final int update; - private final String preRelease; - - public VersionPoints(int major, int minor, int micro, int update) { - this(major, minor, micro, update, ""); - } - - private VersionPoints(int major, int minor, int micro, int update, String preReleaseString) { - this.major = requirePositive(major); - this.minor = requirePositive(minor); - this.micro = requirePositive(micro); - this.update = requirePositive(update); - this.preRelease = Objects.requireNonNull(preReleaseString); - } - - static int requirePositive(int i) { - if (i < 0) { - throw new IllegalArgumentException("Negative arguments are not permitted"); - } - return i; - } - - static VersionPoints fromString(String string) { - Matcher matcher = Pattern.compile(SINGLE_VERSION_PATTERN_STRING).matcher(string); - if (!matcher.matches()) { - throw new InvalidJavaVersionFormatException(string); - } - int major = Integer.parseInt(matcher.group(1)); - int minor = Integer.parseInt(matcher.group(2)); - int micro = Integer.parseInt(matcher.group(3)); - String optionalSuffix = matcher.group(4); // contains both, update and pre-release - String updateStr = matcher.group(5); - String preRelease = matcher.group(6); - if (isNullOrEmpty(optionalSuffix)) { - // Neither update nor pre-release in version string - return new VersionPoints(major, minor, micro, 0); - } - if (isNullOrEmpty(updateStr)) { - // No update provided but pre-release given - return new VersionPoints(major, minor, micro, 0, preRelease); - } - if (isNullOrEmpty(preRelease)) { - // Update given, but no pre-release - int update = Integer.parseInt(updateStr); - return new VersionPoints(major, minor, micro, update); - } - // Both update and pre-release given - int update = Integer.parseInt(updateStr); - return new VersionPoints(major, minor, micro, update, preRelease); - } - - private static boolean isNullOrEmpty(String matchedString) { - return matchedString == null || matchedString.isEmpty(); - } - - public int getMajor() { - return major; - } - - public int getMinor() { - return minor; - } - - public int getMicro() { - return micro; - } - - public int getUpdate() { - return update; - } - - public String getPreRelease() { - return preRelease; - } - - @Override - public int compareTo(VersionPoints versionPoints) { - int majorComparison = Integer.compare(getMajor(), versionPoints.getMajor()); - if (majorComparison != 0) { - return majorComparison; - } - int minorComparison = Integer.compare(getMinor(), versionPoints.getMinor()); - if (minorComparison != 0) { - return minorComparison; - } - int microComparison = Integer.compare(getMicro(), versionPoints.getMicro()); - if (microComparison != 0) { - return microComparison; - } - return Integer.compare(getUpdate(), versionPoints.getUpdate()); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - VersionPoints that = (VersionPoints) o; - - return Objects.equals(major, that.major) - && Objects.equals(minor, that.minor) - && Objects.equals(micro, that.micro) - && Objects.equals(update, that.update); - } - - @Override - public int hashCode() { - return Objects.hash(major, minor, micro, update); - } - - @Override - public String toString() { - return getMajor() + "." - + getMinor() + "." - + getMicro() + "." - + getUpdate() + - (getPreRelease().isEmpty() ? "" : "-" + getPreRelease()); - } - } - - public static class InvalidJavaVersionFormatException extends RuntimeException { - public InvalidJavaVersionFormatException(String message) { - super("Invalid version string: " + message); - } - } -}
--- a/plugins/vm-gc/common/src/main/java/com/redhat/thermostat/vm/gc/common/params/ValidationErrorsFormatter.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,137 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.params; - -import com.redhat.thermostat.shared.locale.Translate; -import com.redhat.thermostat.vm.gc.common.internal.LocaleResources; - -import java.io.BufferedReader; -import java.io.FileReader; -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Formats XML validation issues to strings. - * - * @see GcParamsMappingValidatorException - */ -public class ValidationErrorsFormatter { - - private enum ErrorType { - WARNING, - ERROR, - FATALERROR; - } - - private Map<ErrorType, LocaleResources> translateKeys; - private static final Translate<LocaleResources> translator = LocaleResources.createLocalizer(); - - public ValidationErrorsFormatter() { - - translateKeys = new HashMap<>(); - translateKeys.put(ErrorType.ERROR, LocaleResources.VALIDATION_ERROR); - translateKeys.put(ErrorType.WARNING, LocaleResources.VALIDATION_WARNING); - translateKeys.put(ErrorType.FATALERROR, LocaleResources.VALIDATION_FATAL_ERROR); - - } - - public String format(List<ValidationIssue> list) { - StringBuilder outputBuilder = new StringBuilder(); - for (ValidationIssue ave : list) { - outputBuilder.append(formatError(ave)); - } - return outputBuilder.toString(); - } - - private StringBuilder formatError(ValidationIssue ave) { - StringBuilder builder = new StringBuilder(); - - String LS = System.lineSeparator(); - String firstLine = null; - String secondLine = null; - String thirdLine = null; - String errorLine = null; - String pointer = ""; - String absolutePath = ave.getXmlFilePath(); - - try { - BufferedReader br = new BufferedReader(new FileReader(absolutePath)); - for (int i = 1; i < ave.getLineNumber()-3; i++) { - br.readLine(); - } - firstLine = br.readLine(); - secondLine = br.readLine(); - thirdLine = br.readLine(); - errorLine = br.readLine(); - - for (int j = 1; j < ave.getColumnNumber()-1; j++) { - pointer = pointer.concat(" "); - } - pointer = pointer.concat("^"); - br.close(); - } catch (IOException exception) { - // if br fails to close - } - - builder.append(translator.localize( - translateKeys.get(ErrorType.valueOf(ave.getClass().getSimpleName().toUpperCase())), - absolutePath, - Integer.toString(ave.getLineNumber()), - Integer.toString(ave.getColumnNumber())).getContents()); - - builder.append(formatMessage(ave.getMessage())).append(LS).append(LS); - builder.append(firstLine).append(LS); - builder.append(secondLine).append(LS); - builder.append(thirdLine).append(LS); - builder.append(errorLine).append(LS); - builder.append(pointer).append(LS); - - return builder; - } - - private String formatMessage(String message) { - String[] arguments = message.split("\"http://icedtea.classpath.org/thermostat/gc-params-mapping/v1.0\":"); - StringBuilder sb = new StringBuilder(); - for (String argument : arguments) { - sb.append(argument); - } - return sb.toString(); - } - -} \ No newline at end of file
--- a/plugins/vm-gc/common/src/main/java/com/redhat/thermostat/vm/gc/common/params/ValidationIssue.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,70 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.params; - -/** - * Represents XML schema validation issues. - * - */ -public interface ValidationIssue { - - /** - * - * @return The line number where the issue occurred. - */ - int getLineNumber(); - - /** - * - * @return The column number where the issue occurred. - */ - int getColumnNumber(); - - /** - * - * @return A message describing the issue. - */ - String getMessage(); - - /** - * - * @return The xml file path which caused the issue. - */ - String getXmlFilePath(); - -} -
--- a/plugins/vm-gc/common/src/main/java/com/redhat/thermostat/vm/gc/common/params/Warning.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.params; - -public class Warning extends AbstractValidationError { - - Warning(int lineNumber, int columnNumber, String message, String gcParamsMappingXmlFilePath) { - super(lineNumber, columnNumber, message, gcParamsMappingXmlFilePath); - } - - @Override - public String getName() { - return this.getClass().getSimpleName(); - } - -}
--- a/plugins/vm-gc/common/src/main/resources/com/redhat/thermostat/vm/gc/common/gc-params-mapping.xml Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,737 +0,0 @@ -<?xml version="1.0"?> -<!-- - - Copyright 2012-2017 Red Hat, Inc. - - This file is part of Thermostat. - - Thermostat is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 2, or (at your - option) any later version. - - Thermostat is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Thermostat; see the file COPYING. If not see - <http://www.gnu.org/licenses/>. - - Linking this code with other modules is making a combined work - based on this code. Thus, the terms and conditions of the GNU - General Public License cover the whole combination. - - As a special exception, the copyright holders of this code give - you permission to link this code with independent modules to - produce an executable, regardless of the license terms of these - independent modules, and to copy and distribute the resulting - executable under terms of your choice, provided that you also - meet, for each linked independent module, the terms and conditions - of the license of that module. An independent module is a module - which is not derived from or based on this code. If you modify - this code, you may extend this exception to your version of the - library, but you are not obligated to do so. If you do not wish - to do so, delete this exception statement from your version. - ---> -<gc-params-mapping xmlns="http://icedtea.classpath.org/thermostat/gc-params-mapping/v1.0" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://icedtea.classpath.org/thermostat/gc-params-mapping/v1.0 gc-params-mapping.xsd"> - - <!-- Reference documentation --> - <!-- http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html --> - <!-- http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/G1GettingStarted/index.html --> - <!-- http://www.slideshare.net/SimoneBordet/g1-garbage-collector-details-and-tuning --> - <!-- http://www.oracle.com/technetwork/articles/java/g1gc-1984535.html --> - <!-- http://icedtea.classpath.org/hg/icedtea7-forest/hotspot/file/aea5b566bfab/src/share/vm/gc_implementation/g1/g1_globals.hpp --> - - <common> - <gc-params> - <gc-param> - <flag>PrintGC</flag> - <description>Print messages when garbage collection takes place</description> - </gc-param> - <gc-param> - <flag>PrintGCDetails</flag> - <description>Print more details in garbage collection messages</description> - </gc-param> - <gc-param> - <flag>PrintGCTimeStamps</flag> - <description>Print timestamps in garbage collection messages</description> - </gc-param> - <gc-param> - <flag>UseGCLogFileRotation</flag> - <description>Enable GC log file rotation. Requires -Xloggc:filename, which enables logging GC messages to - file - </description> - </gc-param> - <gc-param> - <flag>NumberOfGClogFiles</flag> - <description>The number of rotating log files to use. Must be greater than or equal to 1. The default is 1. - </description> - </gc-param> - <gc-param> - <flag>GCLogFileSize</flag> - <description>The maximum log file size in bytes after which the log files will be rotated. Must be greater - than or equal to 8K. The default is 8K. - </description> - </gc-param> - </gc-params> - </common> - - <collector> - <collector-info> - <version>[1.4.2.0,]</version> - <common-name>Serial Collector</common-name> - <collector-distinct-names> - <collector-name>MSC</collector-name> - <collector-name>Copy</collector-name> - </collector-distinct-names> - <url>http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#available_collectors</url> - </collector-info> - <gc-params> - <gc-param> - <flag>UseSerialGC</flag> - <description>Use serial garbage collection</description> - </gc-param> - <gc-param> - <flag>ScavengeBeforeFullGC</flag> - <description>Do garbage collection on young generations before performing full GC cycles</description> - </gc-param> - <gc-param> - <flag>UseGCOverheadLimit</flag> - <description>Limit the proportion of time that the VM will spend in garbage collection before an OutOfMemory - error is thrown - </description> - <version>[1.6.0.0,]</version> - </gc-param> - <gc-param> - <flag>MaxHeapFreeRatio</flag> - <description>The maximum percentage of heap size free after a garbage collection cycle to avoid heap - shrinking. The default is 70 - </description> - </gc-param> - <gc-param> - <flag>MinHeapFreeRatio</flag> - <description>The minimum percentage of heap size free after a garbage collection cycle to avoid heap - expansion. The default is 40 - </description> - </gc-param> - <gc-param> - <flag>MaxNewSize</flag> - <description>The maximum size of the new generation, in bytes. Since 1.4, this is computed as a function of - NewRatio - </description> - </gc-param> - <gc-param> - <flag>MaxPermSize</flag> - <description>The maximum size of the permanent generation, in bytes. Since 5.0, 64-bit VMs are scaled 30% - larger - </description> - <version>[1.4.2.0,1.8.0.0)</version> - </gc-param> - <gc-param> - <flag>NewRatio</flag> - <description>Ratio of old and new generation sizes. The default is 2</description> - </gc-param> - <gc-param> - <flag>NewSize</flag> - <description>The default size of the new generation, in bytes. Since 5.0, 64-bit VMs are scaled 30% larger - </description> - </gc-param> - <gc-param> - <flag>SurvivorRatio</flag> - <description>Ratio of eden and survivor space. The default is 8</description> - </gc-param> - <gc-param> - <flag>TargetSurvivorRatio</flag> - <description>The target percentage of survivor space in use after a scavenge</description> - </gc-param> - </gc-params> - </collector> - - <collector> - <collector-info> - <version>[1.6.0.14,]</version> - <common-name>Garbage-First Collector (G1)</common-name> - <collector-distinct-names> - <collector-name>G1 incremental collections</collector-name> - </collector-distinct-names> - <url>http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#available_collectors</url> - </collector-info> - <gc-params> - <gc-param> - <flag>UseG1GC</flag> - <description>use the G1 Garbage Collector</description> - </gc-param> - <gc-param> - <flag>MaxGCPauseMillis</flag> - <description>the max GC pause time goal in milliseconds that G1 will attempt to meet. The default is 200 - </description> - </gc-param> - <gc-param> - <flag>InitiatingHeapOccupancyParent</flag> - <description>percentage of total heap occupancy at which a GC cycle will be triggered. The default is 45 - </description> - </gc-param> - <gc-param> - <flag>GCPauseIntervalMillis</flag> - <description>the time interval over which GC pauses totaling up to MaxGCPauseMillis may take place</description> - </gc-param> - <gc-param> - <flag>NewRatio</flag> - <description>ratio of old a new generation sizes. The default is 2</description> - </gc-param> - <gc-param> - <flag>SurvivorRatio</flag> - <description>Ratio of eden and survivor space. The default is 8</description> - </gc-param> - <gc-param> - <flag>MaxTenuringThreshold</flag> - <description>Maximum value for threshold of object tenuring. The default is 15</description> - </gc-param> - <gc-param> - <flag>MaxNewSize</flag> - <description>The maximum size of the new generation, in bytes. Since 1.4, this is computed as a function of - NewRatio - </description> - </gc-param> - <gc-param> - <flag>MaxPermSize</flag> - <description>The maximum size of the permanent generation, in bytes. Since 5.0, 64-bit VMs are scaled 30% - larger - </description> - <version>[1.6.0.14,1.8.0.0)</version> - </gc-param> - <gc-param> - <flag>ParallelGCThreads</flag> - <description>The number of threads to use during the parallel phase of GC</description> - </gc-param> - <gc-param> - <flag>ConcGCThreads</flag> - <description>The number of concurrent GC threads to use</description> - </gc-param> - <gc-param> - <flag>UseGCOverheadLimit</flag> - <description>Limit the proportion of time that the VM will spend in garbage collection before an OutOfMemory - error is thrown - </description> - </gc-param> - <gc-param> - <flag>ScavengeBeforeFullGC</flag> - <description>Do garbage collection on young generations before performing full GC cycles</description> - </gc-param> - <gc-param> - <flag>MaxHeapFreeRatio</flag> - <description>The maximum percentage of heap size free after a garbage collection cycle to avoid heap - shrinking. The default is 70 - </description> - </gc-param> - <gc-param> - <flag>MinHeapFreeRatio</flag> - <description>The minimum percentage of heap size free after a garbage collection cycle to avoid heap - expansion. The default is 40 - </description> - </gc-param> - <gc-param> - <flag>NewSize</flag> - <description>The default size of the new generation, in bytes. Since 5.0, 64-bit VMs are scaled 30% - larger - </description> - </gc-param> - <gc-param> - <flag>TargetSurvivorRatio</flag> - <description>The target percentage of survivor space in use after a scavenge</description> - </gc-param> - <gc-param> - <flag>G1ConcMarkStepDurationMillis</flag> - <description>The target duration of individual concurrent marking steps</description> - </gc-param> - <gc-param> - <flag>G1ConcRSHotCardLimit</flag> - <description>The threshold that defines a "hot card"</description> - </gc-param> - <gc-param> - <flag>G1ConcRSLogCacheSize</flag> - <description>Log base 2 of the size of concurrent Remembered Set "hot card" cache</description> - </gc-param> - <gc-param> - <flag>G1ConcRefinementGreenZone</flag> - <description>The number of update buffers that are left in the queue by the concurrent processing threads</description> - </gc-param> - <gc-param> - <flag>G1ConcRefinementYellowZone</flag> - <description>Number of enqueued update buffers that will trigger concurrent processing</description> - </gc-param> - <gc-param> - <flag>G1ConcRefinementRedZone</flag> - <description>Number of enqueued update buffers that will trigger concurrent processing - instead of enqueueing them</description> - </gc-param> - <gc-param> - <flag>G1UseAdaptiveConcRefinement</flag> - <description>Select green, yellow, and red zone sizes adaptively to meet the pause time requirements</description> - </gc-param> - <gc-param> - <flag>G1ConcRefinementServiceIntervalMillis</flag> - <description>The last concurrent refinement thread wakes up every specified number of milliseconds to do miscellaneous work</description> - </gc-param> - <gc-param> - <flag>G1ConcRefinementThreads</flag> - <description>The number of threads to use for concurrently updating GC remembered sets. If not set then the default is ParallelGCThreads + 1</description> - </gc-param> - <gc-param> - <flag>G1ConcRefinementThresholdStep</flag> - <description>Each time the remembered set update queue increases by this amount, activate the next refinement thread, if available</description> - </gc-param> - <gc-param> - <flag>G1ConfidencePercent</flag> - <description>Confidence level for MMU/pause predictions</description> - </gc-param> - <gc-param> - <flag>G1MarkingOverheadPercent</flag> - <description>Overhead of concurrent marking</description> - </gc-param> - <gc-param> - <flag>G1UseConcMarkReferenceProcessing</flag> - <description>If true, enable reference discovery during concurrent marking and reference processing at the end - of remark</description> - </gc-param> - <gc-param> - <flag>G1HeapRegionSize</flag> - <description>The size of G1 heap subdivisions. Minimum 1Mb, maximum 32Mb</description> - </gc-param> - <gc-param> - <flag>G1HeapWastePercent</flag> - <description>The maximum threshold of heap space which is permitted to be wasted. GC cycles will not take - place when the reclaimable space as a percentage is below this threshold. The default is 10 percent</description> - </gc-param> - <gc-param> - <flag>G1MixedGCCountTarget</flag> - <description>The number of "mixed" garbage collection cycles to perform after a marking cycle. The default is 8</description> - </gc-param> - <gc-param> - <flag>G1MixedGCLiveThresholdPercent</flag> - <description>The percent of "live" objects in old generation regions under which a mixed GC will be performed. - The default is 85</description> - </gc-param> - <gc-param> - <flag>G1HeapWastePercent</flag> - <description>The threshold percentage of wasted heap space. The default is 5</description> - </gc-param> - <gc-param> - <flag>G1RSetRegionEntries</flag> - <description>The maximum number of regions</description> - </gc-param> - <gc-param> - <flag>G1RSetScanBlockSize</flag> - <description>Size of a work unit of cards claimed by a worker thread during Remembered Set scanning</description> - </gc-param> - <gc-param> - <flag>G1RSetSparseRegionEntries</flag> - <description>Maximum number of entries per region in a sparse table</description> - </gc-param> - <gc-param> - <flag>G1RSetUpdatingPauseTimePercent</flag> - <description>A target percentage of time that is allowed to be spent on processing Remembered Set update buffers during the collection pause</description> - </gc-param> - <gc-param> - <flag>G1RefProcDrainInterval</flag> - <description>The number of discovered reference objects to process before draining concurrent marking work queues</description> - </gc-param> - <gc-param> - <flag>G1ReservePercent</flag> - <description>The percentage of amount of heap space reserved to reduce promotion failure. The default is 10</description> - </gc-param> - <gc-param> - <flag>G1SATBBufferEnqueueingThresholdPercent</flag> - <description>Before enqueueing them, each mutator thread tries to do some - filtering on the SATB buffers it generates. If post-filtering - the percentage of retained entries is over this threshold - the buffer will be enqueued for processing. A value of 0 - specifies that mutator threads should not do such filtering</description> - </gc-param> - <gc-param> - <flag>G1SATBBufferSize</flag> - <description>Number of entries in a SATB log buffer</description> - </gc-param> - <gc-param> - <flag>G1UpdateBufferSize</flag> - <description>Size of an update buffer</description> - </gc-param> - <gc-param> - <flag>G1ExpandByPercentOfAvailable</flag> - <description>When expanding, the percentage of uncommitted space to claim</description> - </gc-param> - </gc-params> - </collector> - - <collector> - <collector-info> - <version>[1.4.1.0,]</version> - <common-name>Parallel Collector</common-name> - <collector-distinct-names> - <collector-name>PSParallelCompact</collector-name> - <collector-name>PSScavenge</collector-name> - </collector-distinct-names> - <url>http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#available_collectors</url> - </collector-info> - <gc-params> - <gc-param> - <flag>UseParallelGC</flag> - <description>Use parallel garbage collection for the young generation</description> - </gc-param> - <gc-param> - <flag>UseParallelOldGC</flag> - <description>Use parallel garbage collection for the both the young and old generation (automatically enables UseParallelGC)</description> - <version>[1.5.0.6,]</version> - </gc-param> - <gc-param> - <flag>UseGCOverheadLimit</flag> - <description>Limit the proportion of time that the VM will spend in garbage collection before an OutOfMemory - error is thrown</description> - <version>[1.6.0.0,]</version> - </gc-param> - <gc-param> - <flag>ScavengeBeforeFullGC</flag> - <description>Do garbage collection on young generations before performing full GC cycles</description> - </gc-param> - <gc-param> - <flag>MaxHeapFreeRatio</flag> - <description>The maximum percentage of heap size free after a garbage collection cycle to avoid heap - shrinking. The default is 70</description> - </gc-param> - <gc-param> - <flag>MinHeapFreeRatio</flag> - <description>The minimum percentage of heap size free after a garbage collection cycle to avoid heap - expansion. The default is 40</description> - </gc-param> - <gc-param> - <flag>MaxNewSize</flag> - <description>The maximum size of the new generation, in bytes. Since 1.4, this is computed as a function of - NewRatio</description> - </gc-param> - <gc-param> - <flag>MaxPermSize</flag> - <description>The maximum size of the permanent generation, in bytes. Since 5.0, 64-bit VMs are scaled 30% - larger</description> - <version>[1.4.1.0,1.8.0.0)</version> - </gc-param> - <gc-param> - <flag>NewRatio</flag> - <description>ratio of old a new generation sizes. The default is 2</description> - </gc-param> - <gc-param> - <flag>NewSize</flag> - <description>The default size of the new generation, in bytes. Since 5.0, 64-bit VMs are scaled 30% larger</description> - </gc-param> - <gc-param> - <flag>SurvivorRatio</flag> - <description>Ratio of eden and survivor space. The default is 8</description> - </gc-param> - <gc-param> - <flag>TargetSurvivorRatio</flag> - <description>The target percentage of survivor space in use after a scavenge</description> - </gc-param> - <gc-param> - <flag>ParallelGCThreads</flag> - <description>The number of threads to use during the parallel phase of GC</description> - </gc-param> - </gc-params> - </collector> - - <collector> - <collector-info> - <version>[1.4.1.0,]</version> - <common-name>Concurrent Collector (Concurrent Mark and Sweep)</common-name> - <collector-distinct-names> - <collector-name>CMS</collector-name> - <collector-name>PCopy</collector-name> - </collector-distinct-names> - <url>http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#available_collectors</url> - </collector-info> - <gc-params> - <gc-param> - <flag>UseConcMarkSweepGC</flag> - <description>Use the Concurrent Mark and Sweep collector for the old generation</description> - </gc-param> - <gc-param> - <flag>UseGCOverheadLimit</flag> - <description>Limit the proportion of time that the VM will spend in garbage collection before an OutOfMemory - error is thrown</description> - <version>[1.6.0.0,]</version> - </gc-param> - <gc-param> - <flag>ScavengeBeforeFullGC</flag> - <description>Do garbage collection on young generations before performing full GC cycles</description> - </gc-param> - <gc-param> - <flag>MaxHeapFreeRatio</flag> - <description>The maximum percentage of heap size free after a garbage collection cycle to avoid heap - shrinking. The default is 70</description> - </gc-param> - <gc-param> - <flag>MinHeapFreeRatio</flag> - <description>The minimum percentage of heap size free after a garbage collection cycle to avoid heap - expansion. The default is 40</description> - </gc-param> - <gc-param> - <flag>MaxNewSize</flag> - <description>The maximum size of the new generation, in bytes. Since 1.4, this is computed as a function of - NewRatio</description> - </gc-param> - <gc-param> - <flag>MaxPermSize</flag> - <description>The maximum size of the permanent generation, in bytes. Since 5.0, 64-bit VMs are scaled 30% - larger</description> - <version>[1.4.1.0,1.8.0.0)</version> - </gc-param> - <gc-param> - <flag>NewRatio</flag> - <description>ratio of old a new generation sizes. The default is 2</description> - </gc-param> - <gc-param> - <flag>NewSize</flag> - <description>The default size of the new generation, in bytes. Since 5.0, 64-bit VMs are scaled 30% - larger</description> - </gc-param> - <gc-param> - <flag>SurvivorRatio</flag> - <description>Ratio of eden and survivor space. The default is 8</description> - </gc-param> - <gc-param> - <flag>TargetSurvivorRatio</flag> - <description>The target percentage of survivor space in use after a scavenge</description> - </gc-param> - </gc-params> - </collector> - - <collector> - <collector-info> - <version>[1.0.0.0,]</version> - <common-name>Mark Sweep Compact Collector</common-name> - <collector-distinct-names> - <collector-name>MSC</collector-name> - <collector-name>PCopy</collector-name> - </collector-distinct-names> - <url>http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#available_collectors</url> - </collector-info> - <gc-params> - <gc-param> - <flag>UseGCOverheadLimit</flag> - <description>Limit the proportion of time that the VM will spend in garbage collection before an OutOfMemory - error is thrown - </description> - <version>[1.6.0.0,]</version> - </gc-param> - <gc-param> - <flag>ScavengeBeforeFullGC</flag> - <description>Do garbage collection on young generations before performing full GC cycles</description> - <version>[1.4.1.0,]</version> - </gc-param> - <gc-param> - <flag>MaxHeapFreeRatio</flag> - <description>The maximum percentage of heap size free after a garbage collection cycle to avoid heap - shrinking. The default is 70 - </description> - </gc-param> - <gc-param> - <flag>MinHeapFreeRatio</flag> - <description>The minimum percentage of heap size free after a garbage collection cycle to avoid heap - expansion. The default is 40 - </description> - </gc-param> - <gc-param> - <flag>MaxNewSize</flag> - <description>The maximum size of the new generation, in bytes. Since 1.4, this is computed as a function of - NewRatio - </description> - </gc-param> - <gc-param> - <flag>MaxPermSize</flag> - <description>The maximum size of the permanent generation, in bytes. Since 5.0, 64-bit VMs are scaled 30% - larger - </description> - <version>[1.0.0.0,1.8.0.0)</version> - </gc-param> - <gc-param> - <flag>NewRatio</flag> - <description>ratio of old a new generation sizes. The default is 2</description> - </gc-param> - <gc-param> - <flag>NewSize</flag> - <description>The default size of the new generation, in bytes. Since 5.0, 64-bit VMs are scaled 30% - larger - </description> - </gc-param> - <gc-param> - <flag>SurvivorRatio</flag> - <description>Ratio of eden and survivor space. The default is 8</description> - </gc-param> - <gc-param> - <flag>TargetSurvivorRatio</flag> - <description>The target percentage of survivor space in use after a scavenge</description> - </gc-param> - </gc-params> - </collector> - - <collector> - <collector-info> - <version>[1.8.0.0,]</version> - <common-name>Shenandoah Collector</common-name> - <collector-distinct-names> - <collector-name>Shenandoah concurrent phases</collector-name> - <collector-name>Shenandoah pauses</collector-name> - <collector-name>Shenandoah full GC pauses</collector-name> - </collector-distinct-names> - <url>http://hg.openjdk.java.net/shenandoah/jdk8u/hotspot/file/c1b5450e17dd/src/share/vm/gc_implementation/shenandoah/shenandoah_globals.hpp</url> - </collector-info> - <gc-params> - <gc-param> - <flag>UseShenandoahGC</flag> - <description>Use the Shenandoah garbage collector. Default is false</description> - </gc-param> - <gc-param> - <flag>ShenandoahAllocReserveRegions</flag> - <description> - How many regions should be kept as allocation reserve, before - Shenandoah attempts to grow the heap. Default is 10 - </description> - </gc-param> - <gc-param> - <flag>ShenandoahAllocationThreshold</flag> - <description> - Sets the number of bytes allocated since last GC cycle before - a region can enter the concurrent marking - phase. Applies to Shenandoah GC dynamic Heuristic mode only - (ignored otherwise) - </description> - </gc-param> - <gc-param> - <flag>ShenandoahFreeThreshold</flag> - <description> - Set the percentage of heap free in relation to the total - capacity before a region can enter the concurrent marking - phase. Applies to Shenandoah GC dynamic Heuristic mode only - (ignored otherwise). Default is 25 - </description> - </gc-param> - <gc-param> - <flag>ShenandoahGCHeuristics</flag> - <description> - The heuristics to use in Shenandoah GC; possible values: - statusquo, aggressive, halfway, lazy, dynamic. Default is - dynamic - </description> - </gc-param> - <gc-param> - <flag>ShenandoahGCVerbose</flag> - <description> - Verbose information about the Shenandoah garbage collector. - Default is false - </description> - </gc-param> - <gc-param> - <flag>ShenandoahGarbageThreshold</flag> - <description> - Sets the percentage of garbage a region need to contain before - it can be marked for collection. Applies to - Shenandoah GC dynamic Heuristic mode only (ignored otherwise). - Default is 60 - </description> - </gc-param> - <gc-param> - <flag>ShenandoahHeapRegionSize</flag> - <description> - Size of the Shenandoah regions - </description> - </gc-param> - <gc-param> - <flag>ShenandoahInitialFreeThreshold</flag> - <description> - Set the percentage of heap free in relation to the total - capacity before a region can enter the concurrent marking - phase. Applies to Shenandoah GC dynamic Heuristic mode only - (ignored otherwise). Default is 50 - </description> - </gc-param> - <gc-param> - <flag>ShenandoahLogConfig</flag> - <description> - Log information about Shenandoah's configuration settings. - Default is false - </description> - </gc-param> - <gc-param> - <flag>ShenandoahOptimizeFinals</flag> - <description>Optimize barriers on final and stable fields/arrays.</description> - </gc-param> - <gc-param> - <flag>ShenandoahPrintCollectionSet</flag> - <description> - Print the collection set before each GC phase. Default is false - </description> - </gc-param> - <gc-param> - <flag>ShenandoahProcessReferences</flag> - <description> - Enable processing of (soft/weak/..) references in Shenandoah. - Default is true - </description> - </gc-param> - <gc-param> - <flag>ShenandoahReadBarrier</flag> - <description> - Turn on/off read barriers in Shenandoah. Default is true - </description> - </gc-param> - <gc-param> - <flag>ShenandoahReadBarrier</flag> - <description> - Turn on/off read barriers in Shenandoah. Default is true - </description> - </gc-param> - <gc-param> - <flag>ShenandoahTargetHeapOccupancy</flag> - <description> - Sets the target maximum percentage occupance of the heap we - would like to maintain. - Shenandoah GC newadaptive Heuristic mode only. Default is 80 - </description> - </gc-param> - <gc-param> - <flag>ShenandoahTraceFullGC</flag> - <description> - Trace Shenandoah full GC. Defaut is false - </description> - </gc-param> - <gc-param> - <flag>ShenandoahTraceHumongous</flag> - <description> - Trace Shenandoah humongous objects. Default is false - </description> - </gc-param> - <gc-param> - <flag>ShenandoahTracePhases</flag> - <description> - Trace Shenandoah GC phases. Default is false - </description> - </gc-param> - <gc-param> - <flag>ShenandoahWarnings</flag> - <description> - Print Shenandoah related warnings. Useful for Shenandoah developers. Default is false - </description> - </gc-param> - <gc-param> - <flag>ShenandoahWriteBarrier</flag> - <description> - Turn on/off write barriers in Shenandoah. Default is true - </description> - </gc-param> - </gc-params> - </collector> - -</gc-params-mapping>
--- a/plugins/vm-gc/common/src/main/resources/com/redhat/thermostat/vm/gc/common/gc-params-mapping.xsd Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,118 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Copyright 2012-2015 Red Hat, Inc. - - This file is part of Thermostat. - - Thermostat is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 2, or (at your - option) any later version. - - Thermostat is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Thermostat; see the file COPYING. If not see - <http://www.gnu.org/licenses/>. - - Linking this code with other modules is making a combined work - based on this code. Thus, the terms and conditions of the GNU - General Public License cover the whole combination. - - As a special exception, the copyright holders of this code give - you permission to link this code with independent modules to - produce an executable, regardless of the license terms of these - independent modules, and to copy and distribute the resulting - executable under terms of your choice, provided that you also - meet, for each linked independent module, the terms and conditions - of the license of that module. An independent module is a module - which is not derived from or based on this code. If you modify - this code, you may extend this exception to your version of the - library, but you are not obligated to do so. If you do not wish - to do so, delete this exception statement from your version. - ---> -<xs:schema xmlns="http://icedtea.classpath.org/thermostat/gc-params-mapping/v1.0" - xmlns:xs="http://www.w3.org/2001/XMLSchema" - targetNamespace="http://icedtea.classpath.org/thermostat/gc-params-mapping/v1.0" - elementFormDefault="qualified"> - - <xs:element name="version" type="xs:string"/> - <xs:element name="common-name" type="xs:string"/> - <xs:element name="collector-name" type="xs:string"/> - <xs:element name="flag" type="xs:string"/> - <xs:element name="description" type="xs:string"/> - <xs:element name="url" type="xs:string"/> - - <xs:element name="gc-params-mapping"> - <xs:complexType> - <xs:sequence> - <xs:element ref="common" minOccurs="1" maxOccurs="1"/> - <xs:element ref="collector" minOccurs="1" maxOccurs="unbounded"/> - </xs:sequence> - </xs:complexType> - </xs:element> - - <xs:element name="common"> - <xs:complexType> - <xs:sequence> - <xs:element ref="gc-params" minOccurs="1" maxOccurs="1"/> - </xs:sequence> - </xs:complexType> - </xs:element> - - <xs:element name="collector"> - <xs:complexType> - <xs:sequence> - <xs:element ref="collector-info"/> - <xs:element ref="gc-params"/> - </xs:sequence> - </xs:complexType> - </xs:element> - - <xs:element name="collector-info"> - <xs:complexType> - <xs:sequence> - <xs:element ref="version"/> - <xs:element ref="common-name"/> - <xs:element ref="collector-distinct-names"/> - <xs:element ref="url"/> - </xs:sequence> - </xs:complexType> - </xs:element> - - <xs:element name="collector-distinct-names"> - <xs:annotation> - <xs:documentation>See GcCommonNameMapper.java - </xs:documentation> - </xs:annotation> - <xs:complexType> - <xs:sequence> - <xs:element ref="collector-name" minOccurs="1" maxOccurs="unbounded"/> - </xs:sequence> - </xs:complexType> - </xs:element> - - <xs:element name="gc-params"> - <xs:complexType> - <xs:sequence> - <xs:element ref="gc-param" minOccurs="0" maxOccurs="unbounded"/> - </xs:sequence> - </xs:complexType> - </xs:element> - - <xs:element name="gc-param"> - <xs:complexType> - <xs:sequence> - <xs:element ref="flag"/> - <xs:element ref="description"/> - <xs:element ref="version" minOccurs="0"/> - </xs:sequence> - </xs:complexType> - </xs:element> - -</xs:schema> \ No newline at end of file
--- a/plugins/vm-gc/common/src/main/resources/com/redhat/thermostat/vm/gc/common/locale/strings.properties Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -VALIDATION_FAILED = Validation failed for file {0} : {1} -VALIDATION_WARNING = Warning in file {0}:{1}.{2} -VALIDATION_ERROR = Error in file {0}:{1}.{2} -VALIDATION_FATAL_ERROR = Fatal error in file {0}:{1}.{2}
--- a/plugins/vm-gc/common/src/test/java/com/redhat/thermostat/vm/gc/common/GcCommonNameMapperTest.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common; - -import static org.junit.Assert.assertEquals; - -import java.util.HashSet; -import java.util.Set; - -import com.redhat.thermostat.vm.gc.common.GcCommonNameMapper; -import org.junit.Test; - -import com.redhat.thermostat.vm.gc.common.GcCommonNameMapper.CollectorCommonName; - -public class GcCommonNameMapperTest { - - private static final GcCommonNameMapper mapper = new GcCommonNameMapper(); - - @Test - public void testMappings() { - Set<String> distinctSet = getDistinctColNames("CMS", "PCopy"); - CollectorCommonName actual = mapper.mapToCommonName(distinctSet); - assertEquals("'CMS' + 'PCopy' should map to concurrent collector", - CollectorCommonName.CONCURRENT_COLLECTOR, actual); - distinctSet = getDistinctColNames("PCopy", "MSC"); - actual = mapper.mapToCommonName(distinctSet); - assertEquals("'MSC' + 'PCopy' should map to MS Compact GC", - CollectorCommonName.MARK_SWEEP_COMPACT, actual); - distinctSet = getDistinctColNames("G1 incremental collections"); - actual = mapper.mapToCommonName(distinctSet); - assertEquals("'G1 incremental collections' should map to G1", - CollectorCommonName.G1, actual); - distinctSet = getDistinctColNames("PSParallelCompact", "PSScavenge"); - actual = mapper.mapToCommonName(distinctSet); - assertEquals("'PSParallelCompact' + 'PSScavenge' should map to parallel collector", - CollectorCommonName.PARALLEL_COLLECTOR, actual); - distinctSet = getDistinctColNames("MSC", "Copy"); - actual = mapper.mapToCommonName(distinctSet); - assertEquals("'MSC' + 'Copy' should map to serial collector", - CollectorCommonName.SERIAL_COLLECTOR, actual); - distinctSet = getDistinctColNames("Shenandoah concurrent phases", - "Shenandoah pauses", - "Shenandoah full GC pauses"); - actual = mapper.mapToCommonName(distinctSet); - assertEquals("Should map to shenandoah GC", - CollectorCommonName.SHENANDOAH, actual); - } - - @Test - public void testHumanReadableNames() { - assertEquals("Parallel Collector", CollectorCommonName.PARALLEL_COLLECTOR.getHumanReadableString()); - assertEquals("Serial Collector", CollectorCommonName.SERIAL_COLLECTOR.getHumanReadableString()); - assertEquals("Garbage-First Collector (G1)", CollectorCommonName.G1.getHumanReadableString()); - assertEquals("Concurrent Collector (Concurrent Mark and Sweep)", CollectorCommonName.CONCURRENT_COLLECTOR.getHumanReadableString()); - assertEquals("Mark Sweep Compact Collector", CollectorCommonName.MARK_SWEEP_COMPACT.getHumanReadableString()); - assertEquals("Shenandoah Collector", CollectorCommonName.SHENANDOAH.getHumanReadableString()); - assertEquals("Unknown Collector", CollectorCommonName.UNKNOWN_COLLECTOR.getHumanReadableString()); - } - - @Test - public void testUnknownCollector() { - Set<String> distinctSet = getDistinctColNames("Me_Dont_Know_Sub-Collector"); - CollectorCommonName actual = mapper.mapToCommonName(distinctSet); - assertEquals("Some random set should map to unknown collector", - CollectorCommonName.UNKNOWN_COLLECTOR, actual); - distinctSet = getDistinctColNames("foo", "bar"); - actual = mapper.mapToCommonName(distinctSet); - assertEquals("Some random set should map to unknown collector", - CollectorCommonName.UNKNOWN_COLLECTOR, actual); - } - - private Set<String> getDistinctColNames(String ... vals) { - Set<String> retval = new HashSet<>(); - for (String val: vals) { - retval.add(val); - } - return retval; - } -}
--- a/plugins/vm-gc/common/src/test/java/com/redhat/thermostat/vm/gc/common/internal/LocaleResourcesTest.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.internal; - -import com.redhat.thermostat.testutils.AbstractLocaleResourcesTest; -import com.redhat.thermostat.vm.gc.common.internal.LocaleResources; - -public class LocaleResourcesTest extends AbstractLocaleResourcesTest<LocaleResources> { - - @Override - protected Class<LocaleResources> getEnumClass() { - return LocaleResources.class; - } - - @Override - protected String getResourceBundle() { - return LocaleResources.RESOURCE_BUNDLE; - } - -} -
--- a/plugins/vm-gc/common/src/test/java/com/redhat/thermostat/vm/gc/common/internal/VmGcStatDAOImplTest.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,114 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.internal; - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyListOf; -import static org.mockito.Matchers.anyString; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import java.util.Arrays; - -import org.eclipse.jetty.client.api.ContentResponse; -import org.eclipse.jetty.http.HttpMethod; -import org.eclipse.jetty.http.HttpStatus; -import org.junit.Before; -import org.junit.Test; - -import com.redhat.thermostat.agent.http.HttpRequestService; -import com.redhat.thermostat.common.config.experimental.ConfigurationInfoSource; -import com.redhat.thermostat.common.plugins.PluginConfiguration; -import com.redhat.thermostat.vm.gc.common.internal.VmGcStatDAOImpl.ConfigurationCreator; -import com.redhat.thermostat.vm.gc.common.internal.VmGcStatDAOImpl.JsonHelper; -import com.redhat.thermostat.vm.gc.common.model.VmGcStat; - -public class VmGcStatDAOImplTest { - - private static final String AGENT_ID = "some-agent"; - private static final String JSON = "{\"this\":\"is\",\"also\":\"JSON\"}"; - private static final String GATEWAY_URL = "http://example.com/jvm-gc"; - - private VmGcStat stat; - private JsonHelper jsonHelper; - private VmGcStatDAOImpl dao; - - private HttpRequestService httpRequestService; - - @Before - public void setup() throws Exception { - stat = new VmGcStat(); - stat.setAgentId(AGENT_ID); - stat.setTimeStamp(1234l); - stat.setWallTime(4000l); - stat.setRunCount(1000l); - stat.setVmId("Vm-1"); - stat.setCollectorName("Collector"); - - jsonHelper = mock(JsonHelper.class); - when(jsonHelper.toJson(anyListOf(VmGcStat.class))).thenReturn(JSON); - - ConfigurationInfoSource source = mock(ConfigurationInfoSource.class); - PluginConfiguration config = mock(PluginConfiguration.class); - when(config.getGatewayURL()).thenReturn(GATEWAY_URL); - ConfigurationCreator creator = mock(ConfigurationCreator.class); - when(creator.create(source)).thenReturn(config); - - httpRequestService = mock(HttpRequestService.class); - ContentResponse contentResponse = mock(ContentResponse.class); - when(httpRequestService.sendHttpRequest(anyString(), anyString(), any(HttpMethod.class))).thenReturn(contentResponse); - when(contentResponse.getStatus()).thenReturn(HttpStatus.OK_200); - - dao = new VmGcStatDAOImpl(jsonHelper, creator, source); - dao.bindHttpRequestService(httpRequestService); - } - - @Test - public void verifyAddVmGcStat() throws Exception { - dao.activate(); - dao.putVmGcStat(stat); - - verify(jsonHelper).toJson(eq(Arrays.asList(stat))); - - verify(httpRequestService.sendHttpRequest(JSON, GATEWAY_URL, HttpMethod.POST), times(1)); - } - -} -
--- a/plugins/vm-gc/common/src/test/java/com/redhat/thermostat/vm/gc/common/internal/VmGcStatTypeAdapterTest.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,62 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.internal; - -import static org.junit.Assert.assertEquals; - -import java.util.Arrays; - -import org.junit.Test; - -import com.redhat.thermostat.vm.gc.common.model.VmGcStat; - -public class VmGcStatTypeAdapterTest { - - @Test - public void testWrite() throws Exception { - VmGcStatTypeAdapter typeAdapter = new VmGcStatTypeAdapter(); - VmGcStat stat = new VmGcStat(); - stat.setAgentId("1"); - stat.setVmId("2"); - stat.setTimeStamp(100l); - stat.setCollectorName("Collector"); - stat.setRunCount(10l); - stat.setWallTime(200l); - assertEquals("[{\"agentId\":\"1\",\"jvmId\":\"2\",\"timeStamp\":{\"$numberLong\":\"100\"},\"collectorName\":\"Collector\",\"runCount\":{\"$numberLong\":\"10\"},\"wallTimeInMicros\":{\"$numberLong\":\"200\"}}]", - typeAdapter.toJson(Arrays.asList(stat))); - } -}
--- a/plugins/vm-gc/common/src/test/java/com/redhat/thermostat/vm/gc/common/model/VmGcStatTest.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.model; - -import com.redhat.thermostat.testutils.DataObjectTest; - -public class VmGcStatTest extends DataObjectTest { - - @Override - public Class<?>[] getDataClasses() { - return new Class[] { VmGcStat.class }; - } -} -
--- a/plugins/vm-gc/common/src/test/java/com/redhat/thermostat/vm/gc/common/params/CollectorInfoTest.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.params; - -import org.junit.Test; - -import java.util.HashSet; -import java.util.Set; - -import static org.junit.Assert.assertTrue; - -public class CollectorInfoTest { - - private static final JavaVersionRange JAVA_VERSION = new JavaVersionRange(new JavaVersionRange.VersionPoints(1, 8, 0, 45)); - private static final String COMMON_NAME = "COMMON_NAME"; - private static final Set<String> COLLECTOR_DISTINCT_NAMES = new HashSet<String>() {{ - add("COLLECTOR1"); - add("COLLECTOR2"); - }}; - private static final String REFERENCE_URL = "http://example.com"; - - @Test - public void testGetters() { - CollectorInfo collectorInfo = new CollectorInfo(JAVA_VERSION, COMMON_NAME, COLLECTOR_DISTINCT_NAMES, REFERENCE_URL); - assertTrue(JAVA_VERSION.toString(), JAVA_VERSION.equals(collectorInfo.getJavaVersionRange())); - assertTrue(COMMON_NAME, COMMON_NAME.equals(collectorInfo.getCommonName())); - assertTrue(COLLECTOR_DISTINCT_NAMES.toString(), COLLECTOR_DISTINCT_NAMES.equals(collectorInfo.getCollectorDistinctNames())); - assertTrue(REFERENCE_URL, REFERENCE_URL.equals(collectorInfo.getReferenceUrl())); - } - - @Test(expected = NullPointerException.class) - public void testNullVersionDisallowed() { - new CollectorInfo(null, COMMON_NAME, COLLECTOR_DISTINCT_NAMES, REFERENCE_URL); - } - - @Test(expected = NullPointerException.class) - public void testNullCommonNameDisallowed() { - new CollectorInfo(JAVA_VERSION, null, COLLECTOR_DISTINCT_NAMES, REFERENCE_URL); - } - - @Test(expected = NullPointerException.class) - public void testNullCollectorDistinctNamesDisallowed() { - new CollectorInfo(JAVA_VERSION, COMMON_NAME, null, REFERENCE_URL); - } - - @Test(expected = NullPointerException.class) - public void testNullReferenceUrlDisallowed() { - new CollectorInfo(JAVA_VERSION, COMMON_NAME, COLLECTOR_DISTINCT_NAMES, null); - } - - -}
--- a/plugins/vm-gc/common/src/test/java/com/redhat/thermostat/vm/gc/common/params/CollectorTest.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,74 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.params; - -import org.junit.Test; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -import static org.junit.Assert.assertTrue; - -public class CollectorTest { - - private static final String COMMON_NAME = "COMMON_NAME"; - private static final Set<String> DISTINCT_COLLECTOR_NAMES = new HashSet<>(Arrays.asList("COLLECTOR1", "COLLECTOR2")); - private static final JavaVersionRange JAVA_VERSION = new JavaVersionRange(new JavaVersionRange.VersionPoints(1, 8, 0, 45)); - private static final Set<GcParam> GC_PARAMS = new HashSet<GcParam>() {{ - add(new GcParam("-XXflag", "Description", new JavaVersionRange(new JavaVersionRange.VersionPoints(1, 9, 0, 10)))); - }}; - private static final String REFERENCE_URL = "http://example.com"; - private static final CollectorInfo COLLECTOR_INFO = new CollectorInfo(JAVA_VERSION, COMMON_NAME, DISTINCT_COLLECTOR_NAMES, REFERENCE_URL); - - @Test - public void testGetters() { - Collector collector = new Collector(COLLECTOR_INFO, GC_PARAMS); - assertTrue(COLLECTOR_INFO.toString(), COLLECTOR_INFO.equals(collector.getCollectorInfo())); - assertTrue(GC_PARAMS.toString(), GC_PARAMS.equals(collector.getGcParams())); - } - - @Test(expected = NullPointerException.class) - public void testNullCollectorInfoDisallowed() { - new Collector(null, GC_PARAMS); - } - - @Test(expected = NullPointerException.class) - public void testNullGcParamsDisallowed() { - new Collector(COLLECTOR_INFO, null); - } -}
--- a/plugins/vm-gc/common/src/test/java/com/redhat/thermostat/vm/gc/common/params/GcParamTest.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.params; - -import org.junit.Test; - -import static org.junit.Assert.assertTrue; - -public class GcParamTest { - - private static final String FLAG = "-XXflag"; - private static final String DESCRIPTION = "A short description of -XXflag"; - private static final JavaVersionRange JAVA_VERSION = new JavaVersionRange(new JavaVersionRange.VersionPoints(1, 8, 0, 45)); - - @Test - public void testGetters() { - GcParam param = new GcParam(FLAG, DESCRIPTION, JAVA_VERSION); - assertTrue(FLAG, param.getFlag().equals(FLAG)); - assertTrue(DESCRIPTION, param.getDescription().equals(DESCRIPTION)); - assertTrue(JAVA_VERSION.toString(), param.getJavaVersionRange().equals(JAVA_VERSION)); - } - - @Test(expected = NullPointerException.class) - public void testNullFlagDisallowed() { - new GcParam(null, DESCRIPTION, JAVA_VERSION); - } - - @Test(expected = NullPointerException.class) - public void testNullDescriptionDisallowed() { - new GcParam(FLAG, null, JAVA_VERSION); - } - - @Test(expected = NullPointerException.class) - public void testNullVersionDisallowed() { - new GcParam(FLAG, DESCRIPTION, null); - } -}
--- a/plugins/vm-gc/common/src/test/java/com/redhat/thermostat/vm/gc/common/params/GcParamsMapperTest.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,105 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.params; - -import com.redhat.thermostat.vm.gc.common.GcCommonNameMapper; -import org.junit.Test; - -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.net.URISyntaxException; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -public class GcParamsMapperTest { - - public static final JavaVersionRange JAVA_VERSION = new JavaVersionRange(new JavaVersionRange.VersionPoints(1, 8, 0, 45)); - private final GcParamsMapper paramsMapper = GcParamsMapper.getInstance(); - - @Test - public void testXsdValidatesXml() { - Exception ex = null; - String exceptionMessage = null; - try { - InputStream stream = paramsMapper.getXmlStream(); - GcParamsMappingValidator validator = new GcParamsMappingValidator(); - validator.validate(GcParamsMapper.XML_RESOURCE_URL, stream); - } catch (GcParamsMappingValidatorException e) { - ValidationErrorsFormatter formatter = new ValidationErrorsFormatter(); - exceptionMessage = formatter.format(e.getAllErrors()); - ex = e; - } catch (FileNotFoundException | URISyntaxException e) { - exceptionMessage = e.getMessage(); - ex = e; - } - assertTrue(exceptionMessage, ex == null); - } - - @Test - public void testUnknownHasNoParams() { - List<GcParam> params = paramsMapper.getParams(GcCommonNameMapper.CollectorCommonName.UNKNOWN_COLLECTOR, JAVA_VERSION); - assertEquals(0, params.size()); - } - - @Test - public void testNoEmptyFlags() { - List<Collector> collectors = paramsMapper.getCollectors(); - for (Collector collector : collectors) { - for (GcParam param : collector.getGcParams()) { - String flag = param.getFlag(); - assertFalse(collector.getCollectorInfo().getCommonName(), flag == null || flag.isEmpty()); - } - } - } - - @Test - public void testTunableVersionsContainedByCollectorVersions() { - List<Collector> collectors = paramsMapper.getCollectors(); - for (Collector collector : collectors) { - JavaVersionRange collectorVersion = collector.getCollectorInfo().getJavaVersionRange(); - for (GcParam param : collector.getGcParams()) { - JavaVersionRange paramVersion = param.getJavaVersionRange(); - assertTrue(collector.getCollectorInfo().getCommonName() + " - " + param.getFlag() + " lower", collectorVersion.contains(paramVersion.getLowerBound())); - assertTrue(collector.getCollectorInfo().getCommonName() + " - " + param.getFlag() + " upper", collectorVersion.contains(paramVersion.getUpperBound())); - } - } - } - -}
--- a/plugins/vm-gc/common/src/test/java/com/redhat/thermostat/vm/gc/common/params/GcParamsMappingValidatorTest.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,212 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.params; - -import org.junit.Test; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileWriter; -import java.io.IOException; - -import static org.junit.Assert.fail; - -public class GcParamsMappingValidatorTest { - - @Test - public void validateEmptyGcParamsMapping() throws IOException { - String config = "<?xml version=\"1.0\"?>\n"; - File testFile = createFile("testSystemId", config); - GcParamsMappingValidator validator = new GcParamsMappingValidator(); - try { - validator.validate("testSystemId", new FileInputStream(testFile)); - fail("should not come here"); - } catch (GcParamsMappingValidatorException e) { - //pass - } finally { - testFile.delete(); - } - } - - @Test - public void canValidateGcParamsMappingXMLMultipleTimes() throws Exception { - try { - String config = "<v1:gc-params-mapping xmlns:v1=\"http://icedtea.classpath.org/thermostat/gc-params-mapping/v1.0\">\n" + - " <v1:common>\n" + - " <v1:gc-params>" + - " <v1:gc-param>" + - " <v1:flag>string</v1:flag>" + - " <v1:description>string</v1:description>" + - " </v1:gc-param>" + - " </v1:gc-params>" + - " </v1:common>" + - " <!--1 or more repetitions:-->\n" + - " <v1:collector>\n" + - " <v1:collector-info>\n" + - " <v1:version>string</v1:version>\n" + - " <v1:common-name>string</v1:common-name>\n" + - " <v1:collector-distinct-names>\n" + - " <!--1 or more repetitions:-->\n" + - " <v1:collector-name>string</v1:collector-name>\n" + - " </v1:collector-distinct-names>\n" + - " <v1:url>string</v1:url>\n" + - " </v1:collector-info>\n" + - " <v1:gc-params>\n" + - " <!--Zero or more repetitions:-->\n" + - " <v1:gc-param>\n" + - " <v1:flag>string</v1:flag>\n" + - " <v1:description>string</v1:description>\n" + - " <!--Optional:-->\n" + - " <v1:version>string</v1:version>\n" + - " </v1:gc-param>\n" + - " </v1:gc-params>\n" + - " </v1:collector>\n" + - "</v1:gc-params-mapping>"; - File testFile = createFile("testSystemId", config); - GcParamsMappingValidator validator = new GcParamsMappingValidator(); - validator.validate("testSystemId", new FileInputStream(testFile)); - - // Second validation on the same file - validator.validate("testSystemId", new FileInputStream(testFile)); - testFile.delete(); - } catch (GcParamsMappingValidatorException e) { - fail("should not reach here, gc-params-mapping.xml should be validated according to schema"); - } - } - - @Test - public void validationFailsOnInvalidGcParamsMappingFile() throws Exception { - String config = "<v1:gc-params-mapping xmlns:v1=\"http://icedtea.classpath.org/thermostat/gc-params-mapping/v1.0\">\n" + - " <v1:common>\n" + - " <v1:gc-params>" + - " <v1:gc-param>" + - " <v1:flag>string</v1:flag>" + - " <v1:description>string</v1:description>" + - " </v1:gc-param>" + - " </v1:gc-params>" + - " </v1:common>" + - " <!--1 or more repetitions:-->\n" + - " <v1:collector>\n" + - " <v1:collector-info>\n" + - " <!-- <v1:version>string</v1:version> -->\n" + - " <v1:common-name>string</v1:common-name>\n" + - " <v1:collector-distinct-names>\n" + - " <!--1 or more repetitions:-->\n" + - " <v1:collector-name>string</v1:collector-name>\n" + - " </v1:collector-distinct-names>\n" + - " <v1:url>string</v1:url>\n" + - " </v1:collector-info>\n" + - " <v1:gc-params>\n" + - " <!--Zero or more repetitions:-->\n" + - " <v1:gc-param>\n" + - " <!-- <v1:flag>string</v1:flag> -->\n" + - " <v1:description>string</v1:description>\n" + - " <!--Optional:-->\n" + - " <v1:version>string</v1:version>\n" + - " </v1:gc-param>\n" + - " </v1:gc-params>\n" + - " </v1:collector>\n" + - "</v1:gc-params-mapping>"; - - File testFile = createFile("testSystemId", config); - GcParamsMappingValidator validator = new GcParamsMappingValidator(); - try { - validator.validate("testSystemId", new FileInputStream(testFile)); - fail("gc-params-mapping.xml should not validate according to schema"); - } catch (GcParamsMappingValidatorException e) { - //pass - } finally { - testFile.delete(); - } - } - - @Test - public void canValidateCorrectFile() throws IOException { - String config = "<v1:gc-params-mapping xmlns:v1=\"http://icedtea.classpath.org/thermostat/gc-params-mapping/v1.0\">\n" + - " <v1:common>\n" + - " <v1:gc-params>" + - " <v1:gc-param>" + - " <v1:flag>string</v1:flag>" + - " <v1:description>string</v1:description>" + - " </v1:gc-param>" + - " </v1:gc-params>" + - " </v1:common>" + - " <v1:collector>\n" + - " <v1:collector-info>\n" + - " <v1:version>1.0.0_0:1.8.0_45</v1:version>\n" + - " <v1:common-name>G1</v1:common-name>\n" + - " <v1:collector-distinct-names>\n" + - " <v1:collector-name>G1 garbage collection</v1:collector-name>\n" + - " </v1:collector-distinct-names>\n" + - " <v1:url>http://example.com</v1:url>\n" + - " </v1:collector-info>\n" + - " <v1:gc-params>\n" + - " <v1:gc-param>\n" + - " <v1:flag>-XXUseG1GC</v1:flag>\n" + - " <v1:description>Enable G1 collector</v1:description>\n" + - " <v1:version>1.0.0_0:1.8.0_45</v1:version>\n" + - " </v1:gc-param>\n" + - " <v1:gc-param>\n" + - " <v1:flag>-XXExtremePerformanceFlag</v1:flag>\n" + - " <v1:description>Turbo Super Ultra Charged Performance</v1:description>\n" + - " <v1:version>1.2.0_0:1.8.0_45</v1:version>\n" + - " </v1:gc-param>\n" + - " </v1:gc-params>\n" + - " </v1:collector>\n" + - "</v1:gc-params-mapping>"; - - File testFile = createFile("testSystemId", config); - GcParamsMappingValidator validator = new GcParamsMappingValidator(); - try { - validator.validate("testSystemId", new FileInputStream(testFile)); - } catch (GcParamsMappingValidatorException e) { - fail("should not reach here, gc-params-mapping.xml should be validated according to schema"); - } finally { - testFile.delete(); - } - } - - private File createFile(String fileName, String contents) throws IOException { - FileWriter fstream = new FileWriter(fileName); - BufferedWriter out = new BufferedWriter(fstream); - out.write(contents); - out.close(); - return new File(fileName); - } - -}
--- a/plugins/vm-gc/common/src/test/java/com/redhat/thermostat/vm/gc/common/params/GcParamsParserTest.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,397 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.params; - -import org.junit.Test; - -import java.io.ByteArrayInputStream; -import java.io.UnsupportedEncodingException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -public class GcParamsParserTest { - - private static final String SINGLE_COLLECTOR_CONFIG = "<gc-params-mapping xmlns=\"http://icedtea.classpath.org/thermostat/gc-params-mapping/v1.0\"\n" + - " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + - " xsi:schemaLocation=\"http://icedtea.classpath.org/thermostat/plugins/v1.0 gc-params-mapping.xsd\">\n" + - " <common>\n" + - " <gc-params>\n" + - " <gc-param>\n" + - " <flag>PrintGC</flag>\n" + - " <description>Print messages when garbage collection takes place</description>\n" + - " </gc-param>\n" + - " <gc-param>\n" + - " <flag>PrintGCDetails</flag>\n" + - " <description>Print more details in garbage collection messages</description>\n" + - " </gc-param>\n" + - " </gc-params>\n" + - " </common>" + - " <collector>\n" + - " <collector-info>\n" + - " <version>[1.0.0.0,1.8.0.45]</version>\n" + - " <common-name>Garbage-First Collector (G1)</common-name>\n" + - " <collector-distinct-names>\n" + - " <collector-name>G1 incremental collections</collector-name>\n" + - " </collector-distinct-names>\n" + - " <url>http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#available_collectors</url>\n" + - " </collector-info>\n" + - " <gc-params>\n" + - " <gc-param>\n" + - " <flag>G1ConcMarkStepDurationMillis</flag>\n" + - " <description>Description Text</description>\n" + - " <version>[1.5.0.31,1.8.0.45]</version>" + - " </gc-param>\n" + - " <gc-param>\n" + - " <flag>G1ConcRSHotCardLimit</flag>\n" + - " <description></description>\n" + - " </gc-param>\n" + - " <gc-param>\n" + - " <flag>G1ConcRSLogCacheSize</flag>\n" + - " <description></description>\n" + - " </gc-param>\n" + - " <gc-param>\n" + - " <flag>G1ConcRefinementGreenZone</flag>\n" + - " <description></description>\n" + - " </gc-param>\n" + - " <gc-param>\n" + - " <flag>G1ConcRefinementRedZone</flag>\n" + - " <description></description>\n" + - " </gc-param>\n" + - " <gc-param>\n" + - " <flag>G1ConcRefinementServiceIntervalMillis</flag>\n" + - " <description></description>\n" + - " </gc-param>\n" + - " <gc-param>\n" + - " <flag>G1ConcRefinementThreads</flag>\n" + - " <description></description>\n" + - " </gc-param>\n" + - " <gc-param>\n" + - " <flag>G1ConcRefinementThresholdStep</flag>\n" + - " <description></description>\n" + - " </gc-param>\n" + - " <gc-param>\n" + - " <flag>G1ConcRefinementYellowZone</flag>\n" + - " <description></description>\n" + - " </gc-param>\n" + - " <gc-param>\n" + - " <flag>G1ConfidencePercent</flag>\n" + - " <description></description>\n" + - " </gc-param>\n" + - " <gc-param>\n" + - " <flag>G1HeapRegionSize</flag>\n" + - " <description></description>\n" + - " </gc-param>\n" + - " <gc-param>\n" + - " <flag>G1HeapWastePercent</flag>\n" + - " <description></description>\n" + - " </gc-param>\n" + - " <gc-param>\n" + - " <flag>G1MixedGCCountTarget</flag>\n" + - " <description></description>\n" + - " </gc-param>\n" + - " <gc-param>\n" + - " <flag>G1RSetRegionEntries</flag>\n" + - " <description></description>\n" + - " </gc-param>\n" + - " <gc-param>\n" + - " <flag>G1RSetScanBlockSize</flag>\n" + - " <description></description>\n" + - " </gc-param>\n" + - " <gc-param>\n" + - " <flag>G1RSetSparseRegionEntries</flag>\n" + - " <description></description>\n" + - " </gc-param>\n" + - " <gc-param>\n" + - " <flag>G1RSetUpdatingPauseTimePercent</flag>\n" + - " <description></description>\n" + - " </gc-param>\n" + - " <gc-param>\n" + - " <flag>G1RefProcDrainInterval</flag>\n" + - " <description></description>\n" + - " </gc-param>\n" + - " <gc-param>\n" + - " <flag>G1ReservePercent</flag>\n" + - " <description></description>\n" + - " </gc-param>\n" + - " <gc-param>\n" + - " <flag>G1SATBBufferEnqueueingThresholdPercent</flag>\n" + - " <description></description>\n" + - " </gc-param>\n" + - " <gc-param>\n" + - " <flag>G1SATBBufferSize</flag>\n" + - " <description></description>\n" + - " </gc-param>\n" + - " <gc-param>\n" + - " <flag>G1UpdateBufferSize</flag>\n" + - " <description></description>\n" + - " </gc-param>\n" + - " <gc-param>\n" + - " <flag>G1UseAdaptiveConcRefinement</flag>\n" + - " <description></description>\n" + - " </gc-param>\n" + - " <gc-param>\n" + - " <flag>UseG1GC</flag>\n" + - " <description></description>\n" + - " </gc-param>\n" + - " </gc-params>\n" + - " </collector>\n" + - "</gc-params-mapping>"; - - private static final String TWO_COLLECTOR_CONFIG = "<gc-params-mapping xmlns=\"http://icedtea.classpath.org/thermostat/gc-params-mapping/v1.0\"\n" + - " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + - " xsi:schemaLocation=\"http://icedtea.classpath.org/thermostat/plugins/v1.0 gc-params-mapping.xsd\">\n" + - " <common>\n" + - " <gc-params>\n" + - " <gc-param>\n" + - " <flag>PrintGC</flag>\n" + - " <description>Print messages when garbage collection takes place</description>\n" + - " </gc-param>\n" + - " <gc-param>\n" + - " <flag>PrintGCDetails</flag>\n" + - " <description>Print more details in garbage collection messages</description>\n" + - " </gc-param>\n" + - " </gc-params>\n" + - " </common>" + - " <collector>\n" + - " <collector-info>\n" + - " <version>[1.0.0.0,1.8.0.45]</version>\n" + - " <common-name>Garbage-First Collector (G1)</common-name>\n" + - " <collector-distinct-names>\n" + - " <collector-name>G1 incremental collections</collector-name>\n" + - " </collector-distinct-names>\n" + - " <url>http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#available_collectors</url>\n" + - " </collector-info>\n" + - " <gc-params>\n" + - " <gc-param>\n" + - " <flag>G1ConcMarkStepDurationMillis</flag>\n" + - " <description>Description Text</description>\n" + - " <version>[1.5.0.31,1.8.0.45]</version>" + - " </gc-param>\n" + - " </gc-params>\n" + - " </collector>\n" + - " <collector>\n" + - " <collector-info>\n" + - " <version>[1.5.0.31,1.8.0.45]</version>\n" + - " <common-name>Parallel</common-name>\n" + - " <collector-distinct-names>\n" + - " <collector-name>PSParallelCompact</collector-name>\n" + - " <collector-name>PSScavenge</collector-name>\n" + - " </collector-distinct-names>\n" + - " <url>http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#available_collectors</url>\n" + - " </collector-info>\n" + - " <gc-params>\n" + - " <gc-param>\n" + - " <flag>UseParallelGC</flag>\n" + - " <description>Parallel Description Text</description>\n" + - " <version>[1.7.0.41,1.8.0.45]</version>" + - " </gc-param>\n" + - " </gc-params>\n" + - " </collector>\n" + - "</gc-params-mapping>"; - - private static final JavaVersionRange G1_VERSION = new JavaVersionRange(new JavaVersionRange.VersionPoints(1, 0, 0, 0), true, new JavaVersionRange.VersionPoints(1, 8, 0, 45), true); - private static final String G1_COMMON_NAME = "Garbage-First Collector (G1)"; - private static final Set<String> G1_DISTINCT_NAMES = Collections.singleton("G1 incremental collections"); - private static final String G1_REFERENCE_URL = "http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html#available_collectors"; - - private static final String PARALLEL_COMMON_NAME = "Parallel"; - - private static final String MARK_STEP_DURATION_MILLIS_FLAG = "G1ConcMarkStepDurationMillis"; - private static final String MARK_STEP_DURATION_MILLIS_DESCRIPTION = "Description Text"; - private static final JavaVersionRange MARK_STEP_DURATION_MILLIS_VERSION = new JavaVersionRange(new JavaVersionRange.VersionPoints(1, 5, 0, 31), true, new JavaVersionRange.VersionPoints(1, 8, 0, 45), true); - private static final Set<String> PARALLEL_DISTINCT_NAMES = new HashSet<>(Arrays.asList("PSParallelCompact", "PSScavenge")); - private static final JavaVersionRange ALL_JAVA_VERSIONS_RANGE = new JavaVersionRange(JavaVersionRange.VersionPoints.MINIMUM_VERSION, true, JavaVersionRange.VersionPoints.MAXIMUM_VERSION, true); - private static final GcParam PRINT_GC_COMMON_PARAM = new GcParam("PrintGC", "Print messages when garbage collection takes place", ALL_JAVA_VERSIONS_RANGE); - private static final GcParam PRINT_GC_DETAILS_COMMON_PARAM = new GcParam("PrintGCDetails", "Print more details in garbage collection messages", ALL_JAVA_VERSIONS_RANGE); - private static final Set<GcParam> COMMON_PARAMS = new HashSet<>(Arrays.asList(PRINT_GC_COMMON_PARAM, PRINT_GC_DETAILS_COMMON_PARAM)); - - @Test(expected = GcParamsParser.GcParamsParseException.class) - public void testEmptyConfigurationThrowsException() throws UnsupportedEncodingException { - String config = "<?xml version=\"1.0\"?>\n"; - GcParamsParser.parse(new ByteArrayInputStream(config.getBytes("UTF-8"))); - fail("should not reach here"); - } - - @Test - public void testMinimalConfigurationParsesOneCollector() throws UnsupportedEncodingException { - GcParamsParser.ParseResult result = getSingleCollectorResult(); - assertEquals(1, result.getCollectors().size()); - } - - @Test - public void testMinimalConfigurationParsesCorrectCommonParams() throws UnsupportedEncodingException { - GcParamsParser.ParseResult result = getSingleCollectorResult(); - assertNonEmptyResult(result.getGcCommonParams()); - assertEquals(result.getGcCommonParams(), COMMON_PARAMS); - } - - @Test - public void testMinimalConfigurationParsesCorrectCollectorName() throws UnsupportedEncodingException { - GcParamsParser.ParseResult result = getSingleCollectorResult(); - assertNonEmptyResult(result.getCollectors()); - assertEquals(result.getCollectors().get(0).getCollectorInfo().getCommonName(), G1_COMMON_NAME); - } - - @Test - public void testMinimalConfigurationParsesCorrectCollectorDistinctNames() throws UnsupportedEncodingException { - GcParamsParser.ParseResult result = getSingleCollectorResult(); - assertNonEmptyResult(result.getCollectors()); - assertEquals(result.getCollectors().get(0).getCollectorInfo().getCollectorDistinctNames(), G1_DISTINCT_NAMES); - } - - @Test - public void testMinimalConfigurationParsesCorrectCollectorVersion() throws UnsupportedEncodingException { - GcParamsParser.ParseResult result = getSingleCollectorResult(); - assertNonEmptyResult(result.getCollectors()); - assertEquals(result.getCollectors().get(0).getCollectorInfo().getJavaVersionRange(), G1_VERSION); - } - - @Test - public void testMinimalConfigurationParsesCorrectReferenceUrl() throws UnsupportedEncodingException { - GcParamsParser.ParseResult result = getSingleCollectorResult(); - assertNonEmptyResult(result.getCollectors()); - assertEquals(result.getCollectors().get(0).getCollectorInfo().getReferenceUrl(), G1_REFERENCE_URL); - } - - @Test - public void testMinimalConfigurationParsesGcParams() throws UnsupportedEncodingException { - GcParamsParser.ParseResult result = getSingleCollectorResult(); - assertNonEmptyResult(result.getCollectors()); - assertEquals(result.getCollectors().get(0).getGcParams().size(), 24); - } - - @Test - public void testMinimalConfigurationParsesGcParamsVersions() throws UnsupportedEncodingException { - GcParamsParser.ParseResult result = getSingleCollectorResult(); - assertNonEmptyResult(result.getCollectors()); - for (GcParam param : result.getCollectors().get(0).getGcParams()) { - if (param.getFlag().equals(MARK_STEP_DURATION_MILLIS_FLAG)) { - assertEquals(param.getJavaVersionRange(), MARK_STEP_DURATION_MILLIS_VERSION); - } else { - assertEquals(param.getJavaVersionRange(), G1_VERSION); - } - } - } - - @Test - public void testMinimalConfigurationParsesGcParamsDescriptions() throws UnsupportedEncodingException { - GcParamsParser.ParseResult result = getSingleCollectorResult(); - assertNonEmptyResult(result.getCollectors()); - for (GcParam param : result.getCollectors().get(0).getGcParams()) { - if (param.getFlag().equals(MARK_STEP_DURATION_MILLIS_FLAG)) { - assertEquals(param.getDescription(), MARK_STEP_DURATION_MILLIS_DESCRIPTION); - } else { - assertTrue(param.getDescription(), param.getDescription().isEmpty()); - } - } - } - - @Test - public void testTwoCollectorConfigurationParsesCommonParams() throws UnsupportedEncodingException { - GcParamsParser.ParseResult parseResult = getTwoCollectorResult(); - assertNonEmptyResult(parseResult.getGcCommonParams()); - assertEquals(parseResult.getGcCommonParams(), COMMON_PARAMS); - } - - @Test - public void testTwoCollectorConfigurationParsesCollectors() throws UnsupportedEncodingException { - GcParamsParser.ParseResult result = getTwoCollectorResult(); - assertNonEmptyResult(result.getCollectors()); - assertEquals(result.getCollectors().size(), 2); - } - - @Test - public void testTwoCollectorConfigurationParsesCollectorCommonNames() throws UnsupportedEncodingException { - GcParamsParser.ParseResult result = getTwoCollectorResult(); - assertNonEmptyResult(result.getCollectors()); - assertEquals(result.getCollectors().size(), 2); - Set<String> commonNames = new HashSet<>(Arrays.asList(result.getCollectors().get(0).getCollectorInfo().getCommonName(), - result.getCollectors().get(1).getCollectorInfo().getCommonName())); - assertEquals(commonNames, new HashSet<>(Arrays.asList(G1_COMMON_NAME, PARALLEL_COMMON_NAME))); - } - - @Test - public void testTwoCollectorConfigurationParsesCollectorDistinctNames() throws UnsupportedEncodingException { - GcParamsParser.ParseResult result = getTwoCollectorResult(); - assertNonEmptyResult(result.getCollectors()); - assertEquals(result.getCollectors().size(), 2); - for (Collector collector : result.getCollectors()) { - if (collector.getCollectorInfo().getCommonName().equals(G1_COMMON_NAME)) { - assertEquals(G1_DISTINCT_NAMES, collector.getCollectorInfo().getCollectorDistinctNames()); - } else if (collector.getCollectorInfo().getCommonName().equals(PARALLEL_COMMON_NAME)) { - assertEquals(PARALLEL_DISTINCT_NAMES, collector.getCollectorInfo().getCollectorDistinctNames()); - } else { - fail("no other collector should have been parsed"); - } - } - } - - private void assertNonEmptyResult(List<Collector> result) { - failIfEmpty(result, "collectors"); - } - - private void assertNonEmptyResult(Set<GcParam> result) { - failIfEmpty(result, "common params"); - } - - private void failIfEmpty(Collection<?> result, String part) { - if (result.isEmpty()) { - fail(part + " should not be empty"); - } - } - - private GcParamsParser.ParseResult getSingleCollectorResult() throws UnsupportedEncodingException { - return parseHelper(SINGLE_COLLECTOR_CONFIG); - } - - private GcParamsParser.ParseResult getTwoCollectorResult() throws UnsupportedEncodingException { - return parseHelper(TWO_COLLECTOR_CONFIG); - } - - private GcParamsParser.ParseResult parseHelper(String config) throws UnsupportedEncodingException { - return GcParamsParser.parse(new ByteArrayInputStream(config.getBytes("UTF-8"))); - } - -} \ No newline at end of file
--- a/plugins/vm-gc/common/src/test/java/com/redhat/thermostat/vm/gc/common/params/JavaVersionRangeTest.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,400 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.vm.gc.common.params; - -import org.junit.Assert; -import org.junit.Test; - -import com.redhat.thermostat.vm.gc.common.params.JavaVersionRange.VersionPoints; - -import java.util.regex.Pattern; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -public class JavaVersionRangeTest { - - public static final JavaVersionRange.VersionPoints ONE_ZERO_ZERO_U0 = new JavaVersionRange.VersionPoints(1, 0, 0, 0); - public static final JavaVersionRange.VersionPoints ONE_ZERO_ONE_U0 = new JavaVersionRange.VersionPoints(1, 0, 1, 0); - public static final JavaVersionRange.VersionPoints ONE_ONE_ZERO_U10 = new JavaVersionRange.VersionPoints(1, 1, 0, 10); - public static final JavaVersionRange.VersionPoints TWO_ZERO_TEN_U40 = new JavaVersionRange.VersionPoints(2, 0, 10, 40); - static final JavaVersionRange VERSION_ONE_ZERO_ZERO_U0 = new JavaVersionRange(ONE_ZERO_ZERO_U0); - static final JavaVersionRange VERSION_ONE_ZERO_ONE_U0 = new JavaVersionRange(ONE_ZERO_ONE_U0); - static final JavaVersionRange VERSION_ONE_ONE_ZERO_U10 = new JavaVersionRange(ONE_ONE_ZERO_U10); - static final JavaVersionRange VERSION_TWO_ZERO_TEN_U40 = new JavaVersionRange(TWO_ZERO_TEN_U40); - - static final JavaVersionRange SMALL_RANGE = new JavaVersionRange(ONE_ZERO_ZERO_U0, true, ONE_ZERO_ONE_U0, true); - static final JavaVersionRange LARGE_RANGE = new JavaVersionRange(ONE_ZERO_ZERO_U0, true, TWO_ZERO_TEN_U40, true); - - @Test - public void testVendorStringInVersion() { - final String winRawStr = "1.8.0_101-1-comment"; - final String oldRawStr = "1.8.0_101-1"; - final JavaVersionRange winRange = JavaVersionRange.fromString(winRawStr); - final JavaVersionRange oldRange = JavaVersionRange.fromString(oldRawStr); - final String winRangeStr = winRange.toString(); - final String oldRangeStr = oldRange.toString(); - Assert.assertEquals("must strip off '-comment'", oldRangeStr, winRangeStr); - } - - @Test - public void testValidSingleVersionComparisons() { - assertFalse(ONE_ZERO_ZERO_U0 + " = " + ONE_ZERO_ZERO_U0, lessThan(VERSION_ONE_ZERO_ZERO_U0, VERSION_ONE_ZERO_ZERO_U0)); - assertTrue(ONE_ZERO_ZERO_U0 + " < " + ONE_ZERO_ONE_U0, lessThan(VERSION_ONE_ZERO_ZERO_U0, VERSION_ONE_ZERO_ONE_U0)); - assertTrue(ONE_ZERO_ONE_U0 + " < " + ONE_ONE_ZERO_U10, lessThan(VERSION_ONE_ZERO_ONE_U0, VERSION_ONE_ONE_ZERO_U10)); - assertTrue(ONE_ONE_ZERO_U10 + " < " + TWO_ZERO_TEN_U40, lessThan(VERSION_ONE_ONE_ZERO_U10, VERSION_TWO_ZERO_TEN_U40)); - } - - @Test - public void testContains() { - assertTrue(VERSION_ONE_ZERO_ZERO_U0 + " in " + SMALL_RANGE, SMALL_RANGE.contains(VERSION_ONE_ZERO_ZERO_U0)); - assertTrue(VERSION_ONE_ONE_ZERO_U10 + " in " + LARGE_RANGE, LARGE_RANGE.contains(VERSION_ONE_ONE_ZERO_U10)); - assertFalse(VERSION_TWO_ZERO_TEN_U40 + " in " + SMALL_RANGE, SMALL_RANGE.contains(VERSION_TWO_ZERO_TEN_U40)); - assertTrue(VERSION_TWO_ZERO_TEN_U40 + " in " + LARGE_RANGE, LARGE_RANGE.contains(VERSION_TWO_ZERO_TEN_U40)); - assertTrue(SMALL_RANGE + " in " + LARGE_RANGE, LARGE_RANGE.contains(SMALL_RANGE)); - assertFalse(LARGE_RANGE + " in " + SMALL_RANGE, SMALL_RANGE.contains(LARGE_RANGE)); - } - - @Test - public void testIsRange() { - assertTrue(SMALL_RANGE.toString(), SMALL_RANGE.isRange()); - assertTrue(LARGE_RANGE.toString(), LARGE_RANGE.isRange()); - assertFalse(VERSION_ONE_ZERO_ZERO_U0.toString(), VERSION_ONE_ZERO_ZERO_U0.isRange()); - assertFalse(VERSION_TWO_ZERO_TEN_U40.toString(), VERSION_TWO_ZERO_TEN_U40.isRange()); - } - - @Test - public void testGetLowerBound() { - assertEquals(new JavaVersionRange(ONE_ZERO_ZERO_U0), VERSION_ONE_ZERO_ZERO_U0.getLowerBound()); - assertEquals(VERSION_ONE_ZERO_ZERO_U0, VERSION_ONE_ZERO_ZERO_U0.getLowerBound()); - assertEquals(VERSION_ONE_ZERO_ZERO_U0, SMALL_RANGE.getLowerBound()); - } - - @Test - public void testGetUpperBound() { - assertEquals(new JavaVersionRange(ONE_ZERO_ZERO_U0), VERSION_ONE_ZERO_ZERO_U0.getUpperBound()); - assertEquals(VERSION_ONE_ZERO_ZERO_U0, VERSION_ONE_ZERO_ZERO_U0.getUpperBound()); - assertEquals(VERSION_TWO_ZERO_TEN_U40, LARGE_RANGE.getUpperBound()); - } - - @Test - public void testSingleVersionIsShortcutForSameWithComma() { - JavaVersionRange single = JavaVersionRange.fromString("[1.0.0.0]"); - JavaVersionRange pair = JavaVersionRange.fromString("[1.0.0.0,1.0.0.0]"); - assertEquals(single, pair); - } - - @Test - public void testDefaultIsInclusive() { - JavaVersionRange version = new JavaVersionRange(1, 0, 0, 0); - assertTrue(version.isLowerBoundInclusive()); - assertTrue(version.isUpperBoundInclusive()); - } - - @Test - public void testLowerBoundInclusive() { - JavaVersionRange inclusive = new JavaVersionRange(new JavaVersionRange.VersionPoints(2, 0, 0, 0), true, - new JavaVersionRange.VersionPoints(2, 1, 0, 0), false); // [2.0.0.0, 2.1.0.0) - JavaVersionRange exclusive = new JavaVersionRange(new JavaVersionRange.VersionPoints(2, 0, 0, 0), false, - new JavaVersionRange.VersionPoints(2, 1, 0, 0), false); // (2.0.0.0, 2.1.0.0) - JavaVersionRange version = new JavaVersionRange(2, 0, 0, 0); - assertTrue(inclusive.contains(version)); - assertFalse(exclusive.contains(version)); - } - - @Test - public void testUpperBoundInclusive() { - JavaVersionRange inclusive = new JavaVersionRange(new JavaVersionRange.VersionPoints(2, 0, 0, 0), false, - new JavaVersionRange.VersionPoints(2, 1, 0, 0), true); // (2.0.0.0, 2.1.0.0] - JavaVersionRange exclusive = new JavaVersionRange(new JavaVersionRange.VersionPoints(2, 0, 0, 0), false, - new JavaVersionRange.VersionPoints(2, 1, 0, 0), false); // (2.0.0.0, 2.1.0.0) - JavaVersionRange version = new JavaVersionRange(2, 1, 0, 0); - assertTrue(inclusive.contains(version)); - assertFalse(exclusive.contains(version)); - } - - @Test(expected = NumberFormatException.class) - public void testExtremelyLargeVersionNumberCannotBeParsed() { - JavaVersionRange version = JavaVersionRange.fromString("[" + Long.toString((long) Integer.MAX_VALUE + 1) + ".2.3_4" + "]"); - String expectedVersion = "[2147483648.2.3_4]"; - String expectedRange = "[" + expectedVersion + "," + expectedVersion + "]"; - assertEquals(expectedRange, version.toString()); - assertTrue(version.toString() + " = " + version.toString(), version.compareTo(version) == 0); - } - - @Test(expected = NullPointerException.class) - public void testNullNotAccepted() { - new JavaVersionRange(null); - } - - @Test(expected = IllegalArgumentException.class) - public void testNegativeMajorDisallowed() { - new JavaVersionRange.VersionPoints(-1, 0, 0, 0); - } - - @Test(expected = IllegalArgumentException.class) - public void testNegativeMinorDisallowed() { - new JavaVersionRange.VersionPoints(0, -1, 0, 0); - } - - @Test(expected = IllegalArgumentException.class) - public void testNegativeMicroDisallowed() { - new JavaVersionRange.VersionPoints(0, 0, -1, 0); - } - - @Test(expected = IllegalArgumentException.class) - public void testNegativeUpdateDisallowed() { - new JavaVersionRange.VersionPoints(0, 0, 0, -1); - } - - @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) - public void testInvalidTextNotAccepted() { - JavaVersionRange.fromString("INVALID TEXT"); - } - - @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) - public void testInvalidFormatNotAccepted() { - JavaVersionRange.fromString("[1,0,2]"); - } - - @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) - public void testInvalidFormatNotAccepted2() { - JavaVersionRange.fromString("[1#3.3_4]"); - } - - @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) - public void testInvalidFormatNotAccepted3() { - JavaVersionRange.fromString("[1,300,6_3]"); - } - - @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) - public void testInvalidFormatNotAcceptedWithNull() { - JavaVersionRange.fromString(null); - } - - @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) - public void testFromStringDoesNotAcceptNegative() { - JavaVersionRange.fromString("[-1.0.1]"); - } - - @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) - public void testRangeMustAscend() { - JavaVersionRange.fromString("[2.0.0_10,1.0.0_0]"); - } - - @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) - public void testRangeMustAscend2() { - new JavaVersionRange(new JavaVersionRange.VersionPoints(2, 0, 0, 10), true, new JavaVersionRange.VersionPoints(1, 0, 0, 0), true); - } - - @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) - public void testRangeMustNotBeEmpty() { - JavaVersionRange.fromString("(1.0.0.0)"); - } - - @Test - public void testBracketsAreOptionalForSingleVersion() { - JavaVersionRange without = JavaVersionRange.fromString("1.0.0.0"); - JavaVersionRange with = JavaVersionRange.fromString("[1.0.0.0]"); - assertEquals(without, with); - } - - @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) - public void testMismatchedBracketsForSingleVersion() { - JavaVersionRange.fromString("[1.0.0.0"); - } - - @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) - public void testMismatchedBracketsForSingleVersion2() { - JavaVersionRange.fromString("1.0.0.0]"); - } - - @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) - public void testBracketsAreNotOptionalForRanges() { - JavaVersionRange.fromString("1.0.0.0,2.0.0.0"); - } - - @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) - public void testBracketsAreNotOptionalForRanges2() { - JavaVersionRange.fromString("[1.0.0.0,2.0.0.0"); - } - - @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) - public void testBracketsAreNotOptionalForRanges3() { - JavaVersionRange.fromString("1.0.0.0,2.0.0.0]"); - } - - @Test - public void testUnboundedUpperBound() { - int max = Integer.MAX_VALUE; - JavaVersionRange unbounded = JavaVersionRange.fromString("[1.0.0.0,]"); - assertTrue(unbounded.isLowerBoundInclusive()); - assertTrue(unbounded.isUpperBoundInclusive()); - assertTrue(unbounded.getLowerBound().equals(new JavaVersionRange(1, 0, 0, 0))); - assertTrue(unbounded.getUpperBound().equals(new JavaVersionRange(max, max, max, max))); - } - - @Test - public void testUnboundedLowerBound() { - JavaVersionRange unbounded = JavaVersionRange.fromString("[,1.0.0.0]"); - assertTrue(unbounded.isLowerBoundInclusive()); - assertTrue(unbounded.isUpperBoundInclusive()); - assertTrue(unbounded.getLowerBound().equals(new JavaVersionRange(0, 0, 0, 0))); - assertTrue(unbounded.getUpperBound().equals(new JavaVersionRange(1, 0, 0, 0))); - } - - @Test - public void testUnboundedUpperBoundExclusiveLowerBound() { - JavaVersionRange version = JavaVersionRange.fromString("(1.2.0.0,)"); - JavaVersionRange one = JavaVersionRange.fromString("1.0.0.0"); - JavaVersionRange two = JavaVersionRange.fromString("1.2.0.0"); - JavaVersionRange three = JavaVersionRange.fromString("1.3.0.0"); - assertFalse(version.contains(one)); - assertFalse(version.contains(two)); - assertTrue(version.contains(three)); - } - - @Test - public void testUnboundedLowerBoundExclusiveUpperBound() { - JavaVersionRange version = JavaVersionRange.fromString("[,1.8.0.0)"); - JavaVersionRange two = JavaVersionRange.fromString("1.2.0.0"); - JavaVersionRange seven = JavaVersionRange.fromString("1.7.0.0"); - JavaVersionRange lateSeven = JavaVersionRange.fromString("1.7.0.81"); - JavaVersionRange eight = JavaVersionRange.fromString("1.8.0.0"); - JavaVersionRange lateEight = JavaVersionRange.fromString("1.8.0_51"); - assertTrue(version.contains(two)); - assertTrue(version.contains(seven)); - assertTrue(version.contains(lateSeven)); - assertFalse(version.contains(eight)); - assertFalse(version.contains(lateEight)); - } - - @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) - public void testVersionsRequiredOnAtLeastOneSideOfCommaWithBrackets() { - JavaVersionRange.fromString("[,]"); - } - - @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) - public void testVersionsRequiredOnBothSidesOfCommaWithoutBrackets() { - JavaVersionRange.fromString("1.0.0.0,"); - } - - @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) - public void testVersionsRequiredOnBothSidesOfCommaWithoutBrackets2() { - JavaVersionRange.fromString(",1.0.0.0"); - } - - @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) - public void testVersionsRequiredOnBothSidesOfCommaWithoutBrackets3() { - JavaVersionRange.fromString(","); - } - - @Test - public void testUnderscoreEquivalentToDot() { - JavaVersionRange score = JavaVersionRange.fromString("1.2.3_4"); - JavaVersionRange dot = JavaVersionRange.fromString("1.2.3.4"); - assertEquals(score, dot); - } - - @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) - public void testScoreOnlyAllowedAsFinalSeparator() { - JavaVersionRange.fromString("1_2.3.4"); - } - - @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) - public void testScoreOnlyAllowedAsFinalSeparator2() { - JavaVersionRange.fromString("1.2_3.4"); - } - - @Test - public void canParseCustomBuiltJDKVersion() { - testJDKVersion("1.7.0-internal"); // a custom JDK 7 build has this version string - testJDKVersion("1.7.0"); - testJDKVersion("1.8.0"); - testJDKVersion("1.8.0.55-internal"); - } - - @Test - public void testVersionPointsFromString() { - VersionPoints points = VersionPoints.fromString("1.7.0-internal"); - assertEquals(1, points.getMajor()); - assertEquals(7, points.getMinor()); - assertEquals(0, points.getMicro()); - assertEquals(0, points.getUpdate()); - assertEquals("internal", points.getPreRelease()); - assertEquals("1.7.0.0-internal", points.toString()); - - points = VersionPoints.fromString("1.7.0"); - assertEquals(1, points.getMajor()); - assertEquals(7, points.getMinor()); - assertEquals(0, points.getMicro()); - assertEquals(0, points.getUpdate()); - assertEquals("", points.getPreRelease()); - assertEquals("1.7.0.0", points.toString()); - - points = VersionPoints.fromString("1.8.1_55-b20"); - assertEquals(1, points.getMajor()); - assertEquals(8, points.getMinor()); - assertEquals(1, points.getMicro()); - assertEquals(55, points.getUpdate()); - assertEquals("b20", points.getPreRelease()); - assertEquals("1.8.1.55-b20", points.toString()); - } - - @Test(expected = JavaVersionRange.InvalidJavaVersionFormatException.class) - public void shouldFailToParseVersionPointsForIrregularVersion() { - VersionPoints.fromString("1.7.0|30-internal"); // illegal update separator - } - - private void testJDKVersion(String jdkVersion) { - JavaVersionRange version = null; - try { - version = JavaVersionRange.fromString(jdkVersion); - // pass - } catch (JavaVersionRange.InvalidJavaVersionFormatException e) { - fail("Expected to be able to parse " + jdkVersion); - } - assertFalse(version.isRange()); - } - - private static boolean lessThan(JavaVersionRange a, JavaVersionRange b) { - return a.compareTo(b) < 0; - } - -}
--- a/plugins/vm-gc/distribution/assemblies/plugin-assembly.xml Fri Jun 23 10:25:42 2017 -0400 +++ b/plugins/vm-gc/distribution/assemblies/plugin-assembly.xml Fri Jun 23 11:45:40 2017 -0400 @@ -48,9 +48,7 @@ <dependencySets> <dependencySet> <includes> - <include>com.redhat.thermostat:thermostat-vm-gc-common</include> <include>com.redhat.thermostat:thermostat-vm-gc-agent</include> - <include>com.redhat.thermostat:thermostat-gc-remote-collector-common</include> <include>com.redhat.thermostat:thermostat-gc-remote-collector-command</include> </includes> <useProjectArtifact>false</useProjectArtifact>
--- a/plugins/vm-gc/distribution/thermostat-plugin.xml Fri Jun 23 10:25:42 2017 -0400 +++ b/plugins/vm-gc/distribution/thermostat-plugin.xml Fri Jun 23 11:45:40 2017 -0400 @@ -43,9 +43,7 @@ <extension> <name>agent</name> <bundles> - <bundle><symbolic-name>com.redhat.thermostat.vm.gc.common</symbolic-name><version>${project.version}</version></bundle> <bundle><symbolic-name>com.redhat.thermostat.vm.gc.agent</symbolic-name><version>${project.version}</version></bundle> - <bundle><symbolic-name>com.redhat.thermostat.gc.remote.common.command</symbolic-name><version>${project.version}</version></bundle> <bundle><symbolic-name>com.redhat.thermostat.gc.remote.command</symbolic-name><version>${project.version}</version></bundle> </bundles> </extension>
--- a/plugins/vm-gc/pom.xml Fri Jun 23 10:25:42 2017 -0400 +++ b/plugins/vm-gc/pom.xml Fri Jun 23 11:45:40 2017 -0400 @@ -52,10 +52,8 @@ <modules> <module>agent</module> - <module>common</module> <module>distribution</module> <module>remote-collector-command</module> - <module>remote-collector-common</module> </modules> </project>
--- a/plugins/vm-gc/remote-collector-command/pom.xml Fri Jun 23 10:25:42 2017 -0400 +++ b/plugins/vm-gc/remote-collector-command/pom.xml Fri Jun 23 11:45:40 2017 -0400 @@ -77,12 +77,7 @@ <artifactId>org.osgi.compendium</artifactId> <scope>provided</scope> </dependency> - - <dependency> - <groupId>com.redhat.thermostat</groupId> - <artifactId>thermostat-gc-remote-collector-common</artifactId> - <version>${project.version}</version> - </dependency> + <dependency> <groupId>com.redhat.thermostat</groupId> <artifactId>thermostat-agent-core</artifactId>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plugins/vm-gc/remote-collector-command/src/main/java/com/redhat/thermostat/gc/remote/command/GCAction.java Fri Jun 23 11:45:40 2017 -0400 @@ -0,0 +1,46 @@ +/* + * Copyright 2012-2017 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.gc.remote.command; + +public enum GCAction { + + REQUEST_GC; + + public static final String VM_PID = "VM_PID"; + public static final String RECEIVER = "com.redhat.thermostat.gc.remote.command.GCRequestReceiver"; +} +
--- a/plugins/vm-gc/remote-collector-command/src/main/java/com/redhat/thermostat/gc/remote/command/GCRequestReceiver.java Fri Jun 23 10:25:42 2017 -0400 +++ b/plugins/vm-gc/remote-collector-command/src/main/java/com/redhat/thermostat/gc/remote/command/GCRequestReceiver.java Fri Jun 23 11:45:40 2017 -0400 @@ -52,7 +52,6 @@ import com.redhat.thermostat.common.utils.LoggingUtils; import com.redhat.thermostat.gc.remote.command.internal.GC; import com.redhat.thermostat.gc.remote.command.internal.GCException; -import com.redhat.thermostat.gc.remote.common.command.GCAction; @Component @Service(value = RequestReceiver.class)
--- a/plugins/vm-gc/remote-collector-common/pom.xml Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - - Copyright 2012-2017 Red Hat, Inc. - - This file is part of Thermostat. - - Thermostat is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published - by the Free Software Foundation; either version 2, or (at your - option) any later version. - - Thermostat is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Thermostat; see the file COPYING. If not see - <http://www.gnu.org/licenses/>. - - Linking this code with other modules is making a combined work - based on this code. Thus, the terms and conditions of the GNU - General Public License cover the whole combination. - - As a special exception, the copyright holders of this code give - you permission to link this code with independent modules to - produce an executable, regardless of the license terms of these - independent modules, and to copy and distribute the resulting - executable under terms of your choice, provided that you also - meet, for each linked independent module, the terms and conditions - of the license of that module. An independent module is a module - which is not derived from or based on this code. If you modify - this code, you may extend this exception to your version of the - library, but you are not obligated to do so. If you do not wish - to do so, delete this exception statement from your version. - ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>com.redhat.thermostat</groupId> - <artifactId>thermostat-vm-gc</artifactId> - <version>1.99.12-SNAPSHOT</version> - </parent> - - <artifactId>thermostat-gc-remote-collector-common</artifactId> - <packaging>bundle</packaging> - - <name>Thermostat Remote GC Plugin Common Client API</name> - - <build> - <plugins> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <extensions>true</extensions> - <configuration> - <instructions> - <Bundle-Vendor>Red Hat, Inc.</Bundle-Vendor> - <Bundle-SymbolicName>com.redhat.thermostat.gc.remote.common.command</Bundle-SymbolicName> - <Export-Package> - com.redhat.thermostat.gc.remote.common.command - </Export-Package> - <!-- Do not autogenerate uses clauses in Manifests --> - <_nouses>true</_nouses> - </instructions> - </configuration> - </plugin> - </plugins> - </build> - -</project> -
--- a/plugins/vm-gc/remote-collector-common/src/main/java/com/redhat/thermostat/gc/remote/common/command/GCAction.java Fri Jun 23 10:25:42 2017 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -/* - * Copyright 2012-2017 Red Hat, Inc. - * - * This file is part of Thermostat. - * - * Thermostat is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published - * by the Free Software Foundation; either version 2, or (at your - * option) any later version. - * - * Thermostat is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Thermostat; see the file COPYING. If not see - * <http://www.gnu.org/licenses/>. - * - * Linking this code with other modules is making a combined work - * based on this code. Thus, the terms and conditions of the GNU - * General Public License cover the whole combination. - * - * As a special exception, the copyright holders of this code give - * you permission to link this code with independent modules to - * produce an executable, regardless of the license terms of these - * independent modules, and to copy and distribute the resulting - * executable under terms of your choice, provided that you also - * meet, for each linked independent module, the terms and conditions - * of the license of that module. An independent module is a module - * which is not derived from or based on this code. If you modify - * this code, you may extend this exception to your version of the - * library, but you are not obligated to do so. If you do not wish - * to do so, delete this exception statement from your version. - */ - -package com.redhat.thermostat.gc.remote.common.command; - -public enum GCAction { - - REQUEST_GC; - - public static final String VM_PID = "VM_PID"; - public static final String RECEIVER = "com.redhat.thermostat.gc.remote.command.GCRequestReceiver"; -} -