Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion kanban-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ dependencies {
compile 'org.springframework:spring-context-support:5.0.7.RELEASE'
compile 'net.sf.ehcache:ehcache-core:2.6.11'

// compile 'org.liquibase:liquibase-core:3.6.2'
compile 'org.springframework.boot:spring-boot-starter-actuator'
// compile 'io.micrometer:micrometer-spring-legacy:1.0.6'

// compile 'io.micrometer:micrometer-registry-atlas:1.0.6'

//compile 'org.liquibase:liquibase-core:3.6.2'

compile('org.springframework.boot:spring-boot-starter-data-jpa:1.5.8.RELEASE')
runtime('com.h2database:h2')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ru.otus.spring.hw.kanban;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Service;
import ru.otus.spring.hw.kanban.repository.BoardRepository;


@Service
@Slf4j
public class BoardHealthCheck implements HealthIndicator {
@Autowired
BoardRepository boardRepository;

@Override
public Health health() {
if (boardRepository.findAll().size() > 2) {
return Health.up().build();
}
log.warn("Not enough boards!!");
return Health.down().build();
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package ru.otus.spring.hw.kanban;

import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.system.DiskSpaceHealthIndicatorProperties;
import org.springframework.boot.actuate.system.DiskSpaceHealthIndicator;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.security.crypto.password.PasswordEncoder;
import ru.otus.spring.hw.kanban.security.UserAccount;
import ru.otus.spring.hw.kanban.security.UserAccountRepository;

import javax.annotation.PostConstruct;
import java.io.File;


@SpringBootApplication(scanBasePackages = "ru.otus.spring.hw.kanban")
Expand All @@ -19,6 +25,19 @@ public static void main(String[] args) {
SpringApplication.run(KanbanApplication.class, args);
}

@Bean
JvmThreadMetrics threadMetrics(){
return new JvmThreadMetrics();
}

@Bean
DiskSpaceHealthIndicator diskSpaceHealthIndicator(
@Value("${health.disk.filepath}") String filepath,
@Value("${health.disk.threshold}") long threshold) {
File path = new File(filepath);
return new DiskSpaceHealthIndicator(path, threshold);
}


@Autowired
UserAccountRepository repository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package ru.otus.spring.hw.kanban.controllers;

import io.micrometer.core.annotation.Timed;
import io.micrometer.core.instrument.Metrics;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import ru.otus.spring.hw.kanban.dto.BoardDTO;
Expand All @@ -8,37 +11,47 @@
import java.util.List;

@RestController
@Slf4j
@Timed
public class BoardController {


private final BoardService boardService;



@Autowired
public BoardController(BoardService boardService) {
log.info("BoardController constructor called!");
this.boardService = boardService;
}

@GetMapping(value = "/boards")
@Timed(value = "boards.getall")
public List<BoardDTO> getBoards() {
return boardService.findAll();
}

@PostMapping("/boards")
@Timed(value = "boards.create")
BoardDTO newBoard(@RequestBody BoardDTO newBoard) {
return boardService.create(newBoard);
}

@GetMapping("/boards/{id}")
@Timed(value = "boards.getbyid")
public BoardDTO getBoard(@PathVariable int id) {
return boardService.find(id);
}

@PutMapping("/boards/{id}")
@Timed(value = "boards.update")
BoardDTO updateBoard(@RequestBody BoardDTO boardDTO, @PathVariable Long id) {
return boardService.update(boardDTO);
}

@DeleteMapping("/boards/{id}")
@Timed(value = "boards.delete")
void deleteBoard(@PathVariable int id) {
boardService.deleteById(id);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ru.otus.spring.hw.kanban.controllers;

import io.micrometer.core.annotation.Timed;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import ru.otus.spring.hw.kanban.dto.StageDTO;
Expand All @@ -19,32 +20,38 @@ public StageController(StageService stageService) {
}

@GetMapping(value = "/stages")
@Timed(value = "stages.get")
public List<StageDTO> getStages() {
return stageService.findAll();
}

@GetMapping(value = "/boards/{id}/stages")
@Timed(value = "stages.getbyboard")
public List<StageDTO> getStagesByBoard(@PathVariable int id) {
return stageService.findByBoard(id);
}


@PostMapping("/stages")
@Timed(value = "stages.create")
StageDTO newStage(@RequestBody StageDTO newStage) {
return stageService.create(newStage);
}

@GetMapping("/stages/{id}")
@Timed(value = "stages.getbyid")
public StageDTO getStage(@PathVariable int id) {
return stageService.find(id);
}

@PutMapping("/stages/{id}")
@Timed(value = "stages.update")
StageDTO updateStage(@RequestBody StageDTO stageDTO, @PathVariable Long id) {
return stageService.update(stageDTO);
}

@DeleteMapping("/stages/{id}")
@Timed(value = "stages.delete")
void deleteStage(@PathVariable int id) {
stageService.deleteById(id);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ru.otus.spring.hw.kanban.controllers;

import io.micrometer.core.annotation.Timed;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PostFilter;
import org.springframework.security.access.prepost.PreFilter;
Expand All @@ -22,6 +23,7 @@ public TaskController(TaskService taskService) {

@GetMapping(value = "/stages/{id}/tasks")
@PostFilter("hasPermission(filterObject,'READ')")
@Timed(value = "tasks.getbystage")
public List<TaskDTO> getTasksByStage(@PathVariable int id) {
return taskService.findAllByStage(id);
}
Expand All @@ -32,22 +34,26 @@ public List<TaskDTO> getTasks() {
}

@PostMapping("/tasks")
@Timed(value = "tasks.create")
TaskDTO newTask(Principal principal, @RequestBody TaskDTO newTask) {
newTask.username = principal.getName();
return taskService.create(newTask);
}

@GetMapping("/tasks/{id}")
@Timed(value = "tasks.getbyid")
public TaskDTO getTask(@PathVariable int id) {
return taskService.find(id);
}

@PutMapping("/tasks/{id}")
@Timed(value = "tasks.update")
TaskDTO updateTask(@RequestBody TaskDTO taskDTO, @PathVariable Long id) {
return taskService.update(taskDTO);
}

@DeleteMapping("/tasks/{id}")
@Timed(value = "tasks.delete")
void deleteTask(@PathVariable int id) {
taskService.deleteById(id);
}
Expand Down
6 changes: 5 additions & 1 deletion kanban-server/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ spring.datasource.username=sa
spring.datasource.password=
spring.jpa.hibernate.ddl-auto=none
logging.level.org.springframework.security=DEBUG
#server.port=8090
#server.port=8090
logging.file=kanbanapp.log
management.endpoints.web.exposure.include=*
health.disk.filepath=/media/dk/0C783DB1783D9A82
health.disk.threshold=1000