-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…ambda [FEAT] 사진 업로드 때, 새로운 맴버가 그룹에 들어갈 때, 얼굴 인식 로직
- Loading branch information
Showing
18 changed files
with
174 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/FaceVectorRepository.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
src/main/java/com/umc/naoman/domain/photo/elasticsearch/repository/PhotoEsRepository.java
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
...java/com/umc/naoman/domain/photo/elasticsearch/repository/SampleFaceVectorRepository.java
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
src/main/java/com/umc/naoman/domain/photo/elasticsearch/service/PhotoEsService.java
This file was deleted.
Oops, something went wrong.
13 changes: 0 additions & 13 deletions
13
src/main/java/com/umc/naoman/domain/photo/elasticsearch/service/PhotoEsServiceImpl.java
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
src/main/java/com/umc/naoman/domain/photo/service/FaceDetectionService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.umc.naoman.domain.photo.service; | ||
|
||
import java.util.List; | ||
|
||
public interface FaceDetectionService { | ||
|
||
void detectFaceUploadPhoto(List<String> photoNameList, Long shareGroupId); | ||
void detectFaceJoinShareGroup(Long memberId, Long shareGroupId); | ||
} |
81 changes: 81 additions & 0 deletions
81
src/main/java/com/umc/naoman/domain/photo/service/FaceDetectionServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.umc.naoman.domain.photo.service; | ||
import com.amazonaws.services.lambda.AWSLambda; | ||
import com.amazonaws.services.lambda.model.InvocationType; | ||
import com.amazonaws.services.lambda.model.InvokeRequest; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.umc.naoman.domain.shareGroup.service.ShareGroupService; | ||
import com.umc.naoman.global.error.BusinessException; | ||
import com.umc.naoman.global.error.code.AwsLambdaErrorCode; | ||
import lombok.*; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class FaceDetectionServiceImpl implements FaceDetectionService { | ||
@Value("${spring.lambda.function.detect_face_upload_photo}") | ||
private String detectFaceUploadPhotoLambda; | ||
@Value("${spring.lambda.function.detect_face_join_share_group}") | ||
private String detectFaceJoinShareGroupLambda; | ||
private final AWSLambda awsLambda; | ||
private final ObjectMapper objectMapper = new ObjectMapper(); | ||
private final ShareGroupService shareGroupService; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
private class DetectFacePhotoPayload { | ||
private List<String> photoNameList; | ||
private List<Long> memberIdList; | ||
private Long shareGroupId; | ||
} | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
private class DetectFaceShareGroupPayload { | ||
private Long memberId; | ||
private Long shareGroupId; | ||
} | ||
|
||
@Override | ||
public void detectFaceUploadPhoto(List<String> photoNameList, Long shareGroupId) { | ||
List<Long> memberIdList = shareGroupService.findProfileListByShareGroupId(shareGroupId).stream() | ||
.map(profile -> profile.getMember().getId()) | ||
.collect(Collectors.toList()); | ||
DetectFacePhotoPayload payLoad = new DetectFacePhotoPayload(photoNameList, memberIdList, shareGroupId); | ||
String lambdaPayload = null; | ||
|
||
try { | ||
lambdaPayload = objectMapper.writeValueAsString(payLoad); | ||
} catch (JsonProcessingException e) { | ||
throw new BusinessException(AwsLambdaErrorCode.AWS_JsonProcessing_Exception, e); | ||
} | ||
InvokeRequest invokeRequest = new InvokeRequest() | ||
.withInvocationType(InvocationType.Event) //비동기 호출 | ||
.withFunctionName(detectFaceUploadPhotoLambda) | ||
.withPayload(lambdaPayload); | ||
|
||
awsLambda.invoke(invokeRequest); | ||
} | ||
|
||
@Override | ||
public void detectFaceJoinShareGroup(Long memberId, Long shareGroupId) { | ||
DetectFaceShareGroupPayload payLoad = new DetectFaceShareGroupPayload(memberId, shareGroupId); | ||
String lambdaPayload = null; | ||
|
||
try { | ||
lambdaPayload = objectMapper.writeValueAsString(payLoad); | ||
} catch (JsonProcessingException e) { | ||
throw new BusinessException(AwsLambdaErrorCode.AWS_JsonProcessing_Exception, e); | ||
} | ||
InvokeRequest invokeRequest = new InvokeRequest() | ||
.withInvocationType(InvocationType.Event) //비동기 호출 | ||
.withFunctionName(detectFaceJoinShareGroupLambda) | ||
.withPayload(lambdaPayload); | ||
|
||
awsLambda.invoke(invokeRequest); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/umc/naoman/global/config/AsyncConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.umc.naoman.global.config; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.AsyncConfigurer; | ||
import org.springframework.scheduling.annotation.EnableAsync; | ||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
|
||
import java.util.concurrent.Executor; | ||
|
||
@EnableAsync | ||
@Configuration | ||
public class AsyncConfig implements AsyncConfigurer { | ||
|
||
@Override | ||
public Executor getAsyncExecutor() { | ||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); | ||
executor.setCorePoolSize(10); | ||
executor.setMaxPoolSize(20); | ||
executor.setQueueCapacity(30); | ||
executor.setKeepAliveSeconds(30); | ||
executor.setThreadNamePrefix("async-"); | ||
executor.initialize(); | ||
return executor; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/com/umc/naoman/global/error/code/AwsLambdaErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.umc.naoman.global.error.code; | ||
|
||
import com.umc.naoman.global.error.ErrorCode; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public enum AwsLambdaErrorCode implements ErrorCode { | ||
AWS_JsonProcessing_Exception(500, "EA000", "AWS Lambda JsonProcessingException 발생"), | ||
; | ||
|
||
private final int status; | ||
private final String code; | ||
private final String message; | ||
} |