From 2d92a2715eafc0758865f53dd4d7316b1c9c25da Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Sun, 23 Sep 2018 19:30:51 +0200 Subject: [PATCH] #89 Removal of the spring-petclinic-monitoring module --- pom.xml | 6 -- spring-petclinic-customers-service/pom.xml | 5 - .../CustomersServiceApplication.java | 3 - .../customers/web/OwnerResource.java | 4 - .../petclinic/customers/web/PetResource.java | 4 - spring-petclinic-monitoring/pom.xml | 31 ------ .../monitoring/CallMonitoringAspect.java | 96 ------------------- .../petclinic/monitoring/Monitored.java | 29 ------ .../monitoring/MonitoringConfig.java | 33 ------- 9 files changed, 211 deletions(-) delete mode 100644 spring-petclinic-monitoring/pom.xml delete mode 100644 spring-petclinic-monitoring/src/main/java/org/springframework/samples/petclinic/monitoring/CallMonitoringAspect.java delete mode 100644 spring-petclinic-monitoring/src/main/java/org/springframework/samples/petclinic/monitoring/Monitored.java delete mode 100644 spring-petclinic-monitoring/src/main/java/org/springframework/samples/petclinic/monitoring/MonitoringConfig.java diff --git a/pom.xml b/pom.xml index 90dfbeeae..becca656b 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,6 @@ spring-petclinic-config-server spring-petclinic-discovery-server spring-petclinic-api-gateway - spring-petclinic-monitoring spring-petclinic-tracing-server @@ -56,11 +55,6 @@ import - - org.springframework.samples.petclinic.monitoring - spring-petclinic-monitoring - ${project.version} - org.assertj assertj-core diff --git a/spring-petclinic-customers-service/pom.xml b/spring-petclinic-customers-service/pom.xml index 856d60cbc..a4fbcaf4f 100644 --- a/spring-petclinic-customers-service/pom.xml +++ b/spring-petclinic-customers-service/pom.xml @@ -20,11 +20,6 @@ - - - org.springframework.samples.petclinic.monitoring - spring-petclinic-monitoring - diff --git a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/CustomersServiceApplication.java b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/CustomersServiceApplication.java index 4a7838bcf..3c757c9d4 100644 --- a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/CustomersServiceApplication.java +++ b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/CustomersServiceApplication.java @@ -18,15 +18,12 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.context.annotation.Import; -import org.springframework.samples.petclinic.monitoring.MonitoringConfig; /** * @author Maciej Szarlinski */ @EnableDiscoveryClient @SpringBootApplication -@Import(MonitoringConfig.class) public class CustomersServiceApplication { public static void main(String[] args) { diff --git a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/web/OwnerResource.java b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/web/OwnerResource.java index 4cdac535e..da748d0fa 100644 --- a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/web/OwnerResource.java +++ b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/web/OwnerResource.java @@ -17,11 +17,9 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.samples.petclinic.customers.model.Owner; import org.springframework.samples.petclinic.customers.model.OwnerRepository; -import org.springframework.samples.petclinic.monitoring.Monitored; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; @@ -48,7 +46,6 @@ class OwnerResource { */ @PostMapping @ResponseStatus(HttpStatus.CREATED) - @Monitored public void createOwner(@Valid @RequestBody Owner owner) { ownerRepository.save(owner); } @@ -73,7 +70,6 @@ public List findAll() { * Update Owner */ @PutMapping(value = "/{ownerId}") - @Monitored public Owner updateOwner(@PathVariable("ownerId") int ownerId, @Valid @RequestBody Owner ownerRequest) { final Optional owner = ownerRepository.findById(ownerId); diff --git a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/web/PetResource.java b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/web/PetResource.java index e196ca882..c657ca370 100644 --- a/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/web/PetResource.java +++ b/spring-petclinic-customers-service/src/main/java/org/springframework/samples/petclinic/customers/web/PetResource.java @@ -17,10 +17,8 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.samples.petclinic.customers.model.*; -import org.springframework.samples.petclinic.monitoring.Monitored; import org.springframework.web.bind.annotation.*; import java.util.List; @@ -48,7 +46,6 @@ public List getPetTypes() { @PostMapping("/owners/{ownerId}/pets") @ResponseStatus(HttpStatus.NO_CONTENT) - @Monitored public void processCreationForm( @RequestBody PetRequest petRequest, @PathVariable("ownerId") int ownerId) { @@ -63,7 +60,6 @@ public void processCreationForm( @PutMapping("/owners/*/pets/{petId}") @ResponseStatus(HttpStatus.NO_CONTENT) - @Monitored public void processUpdateForm(@RequestBody PetRequest petRequest) { int petId = petRequest.getId(); Pet pet = findPetById(petId); diff --git a/spring-petclinic-monitoring/pom.xml b/spring-petclinic-monitoring/pom.xml deleted file mode 100644 index d7c27b4d0..000000000 --- a/spring-petclinic-monitoring/pom.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - 4.0.0 - - org.springframework.samples.petclinic.monitoring - spring-petclinic-monitoring - jar - Spring PetClinic monitoring utilities - - - org.springframework.samples - spring-petclinic-microservices - 2.0.4 - - - - - - org.springframework - spring-context - - - - - org.aspectj - aspectjweaver - - - diff --git a/spring-petclinic-monitoring/src/main/java/org/springframework/samples/petclinic/monitoring/CallMonitoringAspect.java b/spring-petclinic-monitoring/src/main/java/org/springframework/samples/petclinic/monitoring/CallMonitoringAspect.java deleted file mode 100644 index 44c4f06b2..000000000 --- a/spring-petclinic-monitoring/src/main/java/org/springframework/samples/petclinic/monitoring/CallMonitoringAspect.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2002-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.samples.petclinic.monitoring; - -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; -import org.springframework.jmx.export.annotation.ManagedAttribute; -import org.springframework.jmx.export.annotation.ManagedOperation; -import org.springframework.jmx.export.annotation.ManagedResource; -import org.springframework.util.StopWatch; - -/** - * Simple aspect that monitors call count and call invocation time. It uses JMX annotations and therefore can be - * monitored using any JMX console such as the jConsole - * - * @author Rob Harrop - * @author Juergen Hoeller - * @author Michael Isvy - * @since 2.5 - */ -@ManagedResource(objectName = "petclinic:type=CallMonitor") -@Aspect -public class CallMonitoringAspect { - - private boolean enabled = true; - - private int callCount = 0; - - private long accumulatedCallTime = 0; - - @ManagedAttribute - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - @ManagedAttribute - public boolean isEnabled() { - return enabled; - } - - @ManagedOperation - public void reset() { - this.callCount = 0; - this.accumulatedCallTime = 0; - } - - @ManagedAttribute - public int getCallCount() { - return callCount; - } - - @ManagedAttribute - public long getCallTime() { - if (this.callCount > 0) { - return this.accumulatedCallTime / this.callCount; - } else { - return 0; - } - } - - - @Around("@annotation(Monitored)") - public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable { - if (this.enabled) { - StopWatch sw = new StopWatch(joinPoint.toShortString()); - - sw.start("invoke"); - try { - return joinPoint.proceed(); - } finally { - sw.stop(); - synchronized (this) { - this.callCount++; - this.accumulatedCallTime += sw.getTotalTimeMillis(); - } - } - } else { - return joinPoint.proceed(); - } - } - -} diff --git a/spring-petclinic-monitoring/src/main/java/org/springframework/samples/petclinic/monitoring/Monitored.java b/spring-petclinic-monitoring/src/main/java/org/springframework/samples/petclinic/monitoring/Monitored.java deleted file mode 100644 index 8e71606eb..000000000 --- a/spring-petclinic-monitoring/src/main/java/org/springframework/samples/petclinic/monitoring/Monitored.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2002-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.samples.petclinic.monitoring; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * @author Maciej Szarlinski - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface Monitored { -} diff --git a/spring-petclinic-monitoring/src/main/java/org/springframework/samples/petclinic/monitoring/MonitoringConfig.java b/spring-petclinic-monitoring/src/main/java/org/springframework/samples/petclinic/monitoring/MonitoringConfig.java deleted file mode 100644 index 38150a0d2..000000000 --- a/spring-petclinic-monitoring/src/main/java/org/springframework/samples/petclinic/monitoring/MonitoringConfig.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2002-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.samples.petclinic.monitoring; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.EnableAspectJAutoProxy; - -/** - * @author Maciej Szarlinski - */ -@Configuration -@EnableAspectJAutoProxy -public class MonitoringConfig { - - @Bean - CallMonitoringAspect callMonitoringAspect() { - return new CallMonitoringAspect(); - } -}