Skip to content

Commit

Permalink
Merge pull request #18 from sw-maestro-kumofactory/feature/#17-blueprint
Browse files Browse the repository at this point in the history
Feature/#17 blueprint
  • Loading branch information
nookcoder committed Jul 17, 2023
2 parents c07c75d + 3014a89 commit a4281ef
Show file tree
Hide file tree
Showing 27 changed files with 752 additions and 28 deletions.
37 changes: 21 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.12'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
id 'java'
id 'org.springframework.boot' version '2.7.12'
id 'io.spring.dependency-management' version '1.0.15.RELEASE'
}

group = 'com.kumofactory'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

configurations {
compileOnly {
extendsFrom annotationProcessor
}
compileOnly {
extendsFrom annotationProcessor
}
}

repositories {
mavenCentral()
mavenCentral()
}

dependencies {
developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
compileOnly 'org.projectlombok:lombok:1.18.24'
annotationProcessor 'org.projectlombok:lombok:1.18.24'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'mysql:mysql-connector-java:8.0.33'
implementation 'org.springframework.boot:spring-boot-starter-validation'
compileOnly 'org.projectlombok:lombok:1.18.24'
implementation 'io.jsonwebtoken:jjwt-api:0.11.5'

implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.2'
implementation group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.2'
implementation group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.2'
annotationProcessor 'org.projectlombok:lombok:1.18.24'

implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.2'
implementation group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.2'
implementation group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.2'
}

tasks.named('test') {
useJUnitPlatform()
useJUnitPlatform()
}
6 changes: 5 additions & 1 deletion src/main/java/com/kumofactory/cloud/CloudApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;

@SpringBootApplication
public class CloudApplication {

public static void main(String[] args) { SpringApplication.run(CloudApplication.class, args); }
public static void main(String[] args) {
SpringApplication.run(CloudApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.kumofactory.cloud.blueprint;

import com.kumofactory.cloud.blueprint.domain.aws.AwsBluePrint;
import com.kumofactory.cloud.blueprint.dto.aws.AwsBluePrintDto;
import com.kumofactory.cloud.blueprint.service.AwsBlueprintService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/blueprint")
@Slf4j
public class BlueprintController {
private final Logger logger = LoggerFactory.getLogger(BlueprintController.class);
private final AwsBlueprintService awsBlueprintService;

// TODO : 토큰에서 유저 정보 가져오는 로직 추가
// TODO : blueprint list 주는 api 추가
// TODO : blueprint id 값으로 blueprint 가져오는 api 추가
@GetMapping("/aws")
public AwsBluePrintDto getAwsBlueprint() {
try {
AwsBluePrintDto awsBlueprint = awsBlueprintService.getAwsBlueprint();
return awsBlueprint;
} catch (RuntimeException e) {
return null;
}
}

@PostMapping("/aws")
public String createAwsBlueprint(@RequestBody AwsBluePrintDto awsBluePrintDto) {
awsBlueprintService.store(awsBluePrintDto);
return "hello-world";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.kumofactory.cloud.blueprint.domain;

import com.kumofactory.cloud.blueprint.dto.ComponentDotDto;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.util.Date;

@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class ComponentDot {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@CreationTimestamp
private Date created_at;
@UpdateTimestamp
private Date updated_at;

private Integer x; // 점의 x 좌표
private Integer y; // 점의 y 좌표
private String componentId; // 점이 속한 컴포넌트의 id

public static ComponentDot createComponentDot(ComponentDotDto componentDotDto) {
ComponentDot componentDot = new ComponentDot();
componentDot.setComponentId(componentDotDto.getComponentId());
componentDot.setX(componentDotDto.getX());
componentDot.setY(componentDotDto.getY());
return componentDot;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.kumofactory.cloud.blueprint.domain;

import com.kumofactory.cloud.blueprint.domain.aws.AwsBluePrint;
import com.kumofactory.cloud.blueprint.dto.ComponentLineDto;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.*;
import java.util.Date;

@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class ComponentLine {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@CreationTimestamp
private Date created_at;
@UpdateTimestamp
private Date updated_at;

private String ui_id; // Client 에서 생성하는 uuid
@OneToOne(cascade = CascadeType.ALL)
private ComponentDot source;
@OneToOne(cascade = CascadeType.ALL)
private ComponentDot destination;
@ManyToOne
private AwsBluePrint bluePrint;

public static ComponentLine createComponentLink(ComponentLineDto lineDto, AwsBluePrint bluePrint) {
ComponentLine componentLink = new ComponentLine();
componentLink.setUi_id(lineDto.getId());
componentLink.setSource(ComponentDot.createComponentDot(lineDto.getSrc()));
componentLink.setDestination(ComponentDot.createComponentDot(lineDto.getDst()));
componentLink.setBluePrint(bluePrint);
return componentLink;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.kumofactory.cloud.blueprint.domain.aws;

import com.kumofactory.cloud.blueprint.domain.ComponentLine;
import com.kumofactory.cloud.member.domain.Member;

import java.util.Date;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

@Entity
@Getter
@Setter
@NoArgsConstructor
public class AwsBluePrint {

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

@CreationTimestamp
private Date created_at;
@UpdateTimestamp
private Date updated_at;

private String name; // 블루프린트 이름

@ManyToOne
private Member member;

@OneToMany(mappedBy = "bluePrint", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
private List<AwsComponent> cspComponents;

@OneToMany(mappedBy = "bluePrint", cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
private List<ComponentLine> lines;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.kumofactory.cloud.blueprint.domain.aws;

import com.kumofactory.cloud.blueprint.dto.aws.AwsComponentDto;

import java.util.Date;
import java.util.List;
import javax.persistence.*;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

@Entity
@Getter
@Setter
@NoArgsConstructor
public class AwsComponent {

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

@CreationTimestamp
private Date created_at;
@UpdateTimestamp
private Date updated_at;

@Column(unique = true)
private String ui_id; // Client 에서 생성하는 uuid

@Enumerated(EnumType.STRING)
private AwsComponentType type; // Component 타입 (vm, vpc, subnet, ...)

// Component 의 좌측 상단 좌표
private Integer position_x;
private Integer position_y;

@ManyToOne
private AwsBluePrint bluePrint;

// ============== 생성함수 ================= //
public static AwsComponent createAwsComponent(AwsComponentDto awsComponentDto,
AwsBluePrint awsBluePrint) {
AwsComponent awsComponent = new AwsComponent();
awsComponent.setUi_id(awsComponentDto.getId());
awsComponent.setPosition_x(awsComponentDto.getX());
awsComponent.setPosition_y(awsComponentDto.getY());
awsComponent.setType(awsComponentDto.getType());
awsComponent.setBluePrint(awsBluePrint);
return awsComponent;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.kumofactory.cloud.blueprint.domain.aws;

public enum AwsComponentType {
VPC, SUBNET, ELB, EC2, EFS, WAF, ROUTE53, NAT_GATEWAY, RDS,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.kumofactory.cloud.blueprint.dto;

import com.kumofactory.cloud.blueprint.domain.ComponentDot;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class ComponentDotDto {
private Integer x;
private Integer y;
private String componentId;

public static ComponentDotDto mapper(ComponentDot componentDot) {
ComponentDotDto componentDotDto = new ComponentDotDto();
componentDotDto.setX(componentDot.getX());
componentDotDto.setY(componentDot.getY());
componentDotDto.setComponentId(componentDot.getComponentId());
return componentDotDto;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.kumofactory.cloud.blueprint.dto;

import com.kumofactory.cloud.blueprint.domain.ComponentLine;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class ComponentLineDto {
private String id; // Client 에서 생성하는 uuid
private ComponentDotDto src;
private ComponentDotDto dst;

public static ComponentLineDto mapper(ComponentLine componentLink) {
ComponentLineDto componentLinkDto = new ComponentLineDto();
componentLinkDto.setId(componentLink.getUi_id());
componentLinkDto.setSrc(ComponentDotDto.mapper(componentLink.getSource()));
componentLinkDto.setDst(ComponentDotDto.mapper(componentLink.getDestination()));
return componentLinkDto;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.kumofactory.cloud.blueprint.dto.aws;

import com.kumofactory.cloud.blueprint.domain.ComponentLine;
import com.kumofactory.cloud.blueprint.domain.aws.AwsComponent;
import com.kumofactory.cloud.blueprint.dto.ComponentLineDto;

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

import lombok.Data;


@Data
public class AwsBluePrintDto {

private String name;
private List<AwsComponentDto> components;
private List<ComponentLineDto> links;

public static List<AwsComponentDto> awsComponentDtosMapper(List<AwsComponent> awsComponentDtos) {
List<AwsComponentDto> awsComponentDtoList = new ArrayList<>();
for (AwsComponent awsComponent : awsComponentDtos) {
awsComponentDtoList.add(AwsComponentDto.mapper(awsComponent));
}
return awsComponentDtoList;
}

public static List<ComponentLineDto> componentLinkDtoListMapper(List<ComponentLine> componentLinks) {
List<ComponentLineDto> componentLinkDtoList = new ArrayList<>();
for (ComponentLine pointLink : componentLinks) {
componentLinkDtoList.add(ComponentLineDto.mapper(pointLink));
}
return componentLinkDtoList;
}
}
Loading

0 comments on commit a4281ef

Please sign in to comment.