Skip to content

Commit

Permalink
Merge pull request #69 from Ivan-Bobrov/feature/53-blocked-threads-in…
Browse files Browse the repository at this point in the history
…tegration-points

Feature/53 blocked threads integration points
  • Loading branch information
sckoenig authored Jul 1, 2024
2 parents 64e0aab + b7b2780 commit 4b5c864
Show file tree
Hide file tree
Showing 27 changed files with 313 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docker-compose.vm2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ services:
container_name: vets-service
environment:
- HOST=141.22.10.82
- SPRING_PROFILES_ACTIVE=vm
- SPRING_PROFILES_ACTIVE=vm, chaos-monkey
deploy:
resources:
limits:
Expand Down
4 changes: 2 additions & 2 deletions scripts/chaos/attacks_enable_latency.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"latencyActive": true,
"latencyRangeStart" : 1000,
"latencyRangeEnd" : 10000
"latencyRangeStart" : 5000,
"latencyRangeEnd" : 15000
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.springframework.samples.petclinic.api.application;

import lombok.RequiredArgsConstructor;
import org.springframework.samples.petclinic.api.dto.CourseDetails;
import org.springframework.samples.petclinic.api.dto.OwnerDetails;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
Expand All @@ -36,4 +37,11 @@ public Mono<OwnerDetails> getOwner(final int ownerId) {
.retrieve()
.bodyToMono(OwnerDetails.class);
}

public Mono<CourseDetails> getCourse(final int courseId) {
return webClientBuilder.build().get()
.uri("http://customers-service/courses/{courseId}", courseId)
.retrieve()
.bodyToMono(CourseDetails.class);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package org.springframework.samples.petclinic.api.application;

import jdk.jfr.Category;
import lombok.RequiredArgsConstructor;
import org.springframework.samples.petclinic.api.dto.OwnerDetails;
import org.springframework.samples.petclinic.api.dto.InstructorDetails;
import org.springframework.samples.petclinic.api.dto.VetDetails;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;
Expand All @@ -20,4 +19,11 @@ public Mono<VetDetails> getVet(final int vetId) {
.retrieve()
.bodyToMono(VetDetails.class);
}

public Mono<InstructorDetails> getInstructor(final int id) {
return webClientBuilder.build().get()
.uri("http://vets-service/vets/{vetId}", id)
.retrieve()
.bodyToMono(InstructorDetails.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.springframework.samples.petclinic.api.application.CustomersServiceClient;
import org.springframework.samples.petclinic.api.application.VetServiceClient;
import org.springframework.samples.petclinic.api.application.VisitsServiceClient;
import org.springframework.samples.petclinic.api.dto.CourseDetails;
import org.springframework.samples.petclinic.api.dto.InstructorDetails;
import org.springframework.samples.petclinic.api.dto.OwnerDetails;
import org.springframework.samples.petclinic.api.dto.VetDetails;
import org.springframework.samples.petclinic.api.dto.Visits;
Expand All @@ -47,6 +49,22 @@ public class ApiGatewayController {

private final ReactiveCircuitBreakerFactory cbFactory;

@GetMapping(value = "/courses/{courseId}")
public Mono<CourseDetails> getCourseDetails(final @PathVariable int courseId) {
return customersServiceClient.getCourse(courseId)
.flatMap(course ->
vetServiceClient.getInstructor(course.getInstructorId())
.map(addInstructorToCourse(course))
);
}

private Function<InstructorDetails, CourseDetails> addInstructorToCourse(CourseDetails course) {
return instructor -> {
course.setInstructorDetails(instructor);
return course;
};
}

@GetMapping(value = "owners/{ownerId}")
public Mono<OwnerDetails> getOwnerDetails(final @PathVariable int ownerId) {
return customersServiceClient.getOwner(ownerId)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.springframework.samples.petclinic.api.dto;

import lombok.Data;

@Data
public class CourseDetails {

private Integer id;

private String name;

private String description;

private Integer instructorId;

private InstructorDetails instructorDetails;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.springframework.samples.petclinic.api.dto;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class InstructorDetails {
private Integer id = null;

private String firstName = null;

private String lastName = null;

private List<Specialty> specialties = new ArrayList<>();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.springframework.samples.petclinic.api.dto;

import lombok.Data;

@Data
public class Specialty {
private String name;
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@
<script src="/scripts/vet-list/vet-list.controller.js"></script>
<script src="/scripts/vet-list/vet-list.component.js"></script>

<script src="/scripts/course-list/course-list.js"></script>
<script src="/scripts/course-list/course-list.controller.js"></script>
<script src="/scripts/course-list/course-list.component.js"></script>

<script src="/scripts/course-details/course-details.js"></script>
<script src="/scripts/course-details/course-details.controller.js"></script>
<script src="/scripts/course-details/course-details.component.js"></script>

<script src="/scripts/infrastructure/infrastructure.js"></script>
<script src="/scripts/infrastructure/httpErrorHandlingInterceptor.js"></script>
</head>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* App Module */
var petClinicApp = angular.module('petClinicApp', [
'ui.router', 'infrastructure', 'layoutNav', 'layoutFooter', 'layoutWelcome',
'ownerList', 'ownerDetails', 'vetDetails', 'ownerForm', 'petForm', 'visits', 'petFiles', 'vetList']);
'ownerList', 'ownerDetails', 'vetDetails', 'ownerForm', 'petForm', 'visits', 'petFiles', 'vetList', 'courseDetails', 'courseList']);

petClinicApp.config(['$stateProvider', '$urlRouterProvider', '$locationProvider', '$httpProvider', function(
$stateProvider, $urlRouterProvider, $locationProvider, $httpProvider) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

angular.module('courseDetails')
.component('courseDetails', {
templateUrl: 'scripts/course-details/course-details.template.html',
controller: 'CourseDetailsController'
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

angular.module('courseDetails')
.controller('CourseDetailsController', ['$http', '$stateParams', function ($http, $stateParams) {
var self = this;

$http.get('api/gateway/courses/' + $stateParams.courseId).then(function (resp) {
self.course = resp.data;
});
}]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

angular.module('courseDetails', ['ui.router'])
.config(['$stateProvider', function ($stateProvider) {
$stateProvider
.state('courseDetails', {
parent: 'app',
url: '/courses/details/:courseId',
template: '<course-details></course-details>'
})
}]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<h2>Course Details</h2>

<table class="table table-striped">
<tr>
<th>Name</th>
<td>{{$ctrl.course.name}}</td>
</tr>
<tr>
<th>Description</th>
<td>{{$ctrl.course.description}}</td>
</tr>
<tr>
<th>Instructor</th>
<td> {{$ctrl.course.instructorDetails.firstName}} {{$ctrl.course.instructorDetails.lastName}}</td>
</tr>

</table>






Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';

angular.module('courseList')
.component('courseList', {
templateUrl: 'scripts/course-list/course-list.template.html',
controller: 'CourseListController'
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

angular.module('courseList')
.controller('CourseListController', ['$http', function ($http) {
var self = this;

$http.get('api/customer/courses').then(function (resp) {
self.courses = resp.data;
});
}]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

angular.module('courseList', ['ui.router'])
.config(['$stateProvider', function ($stateProvider) {
$stateProvider
.state('courses', {
parent: 'app',
url: '/courses',
template: '<course-list></course-list>'
})
}]);
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<h2>Courses</h2>

<form onsubmit="javascript:void(0)" style="max-width: 20em; margin-top: 2em;">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search Filter" ng-model="$ctrl.query" />
</div>
</form>

<table class="table table-striped">
<thead>
<tr>
<th>Course No</th>
<th>Course Name</th>
</tr>
</thead>

<tr ng-repeat="course in $ctrl.courses | filter:$ctrl.query track by course.id">
<td>{{course.id}}</td>
<td>
<a ui-sref="courseDetails({ courseId: course.id })">
{{course.name}}
</a>
</td>

</tr>
</table>
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
</ul>
</li>

<li ui-sref-active="active">
<a ui-sref="courses" title="courses">
<span class="glyphicon glyphicon-book" aria-hidden="true"></span>
<span>Courses</span>
</a>
</li>

<li ui-sref-active="active">
<a ui-sref="vets" title="veterinarians">
<span class="glyphicon glyphicon-th-list" aria-hidden="true"></span>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.springframework.samples.petclinic.customers.model;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import lombok.Getter;
import lombok.Setter;
import org.springframework.core.style.ToStringCreator;

@Entity
@Table(name = "courses")
public class Course {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Getter
private Integer id;

@Getter
@Setter
@Column(name = "name")
@NotBlank
private String name;

@Getter
@Setter
@Column(name = "description")
@NotBlank
private String description;

@Getter
@Setter
@Column(name = "instructor")
private int instructorId;

@Override
public String toString() {
return new ToStringCreator(this)
.append("id", this.getId())
.append("name", this.getName())
.append("description", this.getDescription())
.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.springframework.samples.petclinic.customers.model;

import org.springframework.data.jpa.repository.JpaRepository;

/**
* Repository class for <code>Course</code> domain objects All method names are compliant with Spring Data naming
* conventions so this interface can easily be extended for Spring Data See here: http://static.springsource.org/spring-data/jpa/docs/current/reference/html/jpa.repositories.html#jpa.query-methods.query-creation
*/
public interface CourseRepository extends JpaRepository<Course, Integer> {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.springframework.samples.petclinic.customers.web;

import io.micrometer.core.annotation.Timed;
import jakarta.validation.constraints.Min;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.samples.petclinic.customers.model.Course;
import org.springframework.samples.petclinic.customers.model.CourseRepository;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;

@RequestMapping("/courses")
@RestController
@Timed("petclinic.course")
@RequiredArgsConstructor
@Slf4j
class CourseResource {

record CourseDto (int id, String name){}
private final CourseRepository courseRepository;

@GetMapping(value = "/{courseId}")
public Optional<Course> findCourse(@PathVariable("courseId") @Min(1) int courseId) {
return courseRepository.findById(courseId);
}

@GetMapping
public List<CourseDto> findAll() {
return courseRepository.findAll().stream().map(course -> new CourseDto(course.getId(), course.getName())).toList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ INSERT INTO pets VALUES (10, 'Mulligan', '2007-02-24', 2, 8);
INSERT INTO pets VALUES (11, 'Freddy', '2010-03-09', 5, 9);
INSERT INTO pets VALUES (12, 'Lucky', '2010-06-24', 2, 10);
INSERT INTO pets VALUES (13, 'Sly', '2012-06-08', 1, 10);

INSERT INTO courses VALUES(1, 'Erste Hilfe beim Hund', 'Lernen Sie die grundlegenden Erste-Hilfe-Techniken für Hunde. Der Kurs umfasst die Behandlung von Wunden, das Erkennen von Vergiftungen und das richtige Verhalten in Notfällen.', 4);
INSERT INTO courses VALUES(2, 'Katzenverhalten verstehen', 'Dieser Kurs hilft Ihnen, das Verhalten Ihrer Katze besser zu verstehen. Themen sind Kommunikation, Spielverhalten und wie man unerwünschtes Verhalten korrigiert.', 5);
INSERT INTO courses VALUES(3, 'Gesundheitsvorsorge für Haustiere', 'Erfahren Sie, wie Sie die Gesundheit Ihres Haustiers durch regelmäßige Vorsorgeuntersuchungen und Impfungen schützen können. Der Kurs umfasst auch Parasitenbekämpfung und Zahngesundheit.', 3);
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,11 @@ ALTER TABLE pets ADD CONSTRAINT fk_pets_owners FOREIGN KEY (owner_id) REFERENCES
ALTER TABLE pets ADD CONSTRAINT fk_pets_types FOREIGN KEY (type_id) REFERENCES types (id);
ALTER TABLE files ADD CONSTRAINT fk_files_pet FOREIGN KEY (pet_id) REFERENCES pets (id);
CREATE INDEX pets_name ON pets (name);

CREATE TABLE courses (
id INTEGER IDENTITY PRIMARY KEY,
name VARCHAR(256) NOT NULL,
description CLOB NOT NULL,
instructor INTEGER NOT NULL
);
CREATE INDEX course_name ON courses (name);
Loading

0 comments on commit 4b5c864

Please sign in to comment.