-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from opensergo/app-detail
app detail page
- Loading branch information
Showing
32 changed files
with
1,350 additions
and
539 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
105 changes: 105 additions & 0 deletions
105
...ard-server/src/main/java/io/opensergo/dashboard/controller/service/ServiceController.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,105 @@ | ||
package io.opensergo.dashboard.controller.service; | ||
|
||
import com.alibaba.csp.sentinel.dashboard.domain.PagedResult; | ||
import com.alibaba.csp.sentinel.dashboard.domain.Result; | ||
import com.google.protobuf.InvalidProtocolBufferException; | ||
import com.google.protobuf.util.JsonFormat; | ||
import io.opensergo.dashboard.domain.application.MetadataEntity; | ||
import io.opensergo.dashboard.repository.application.ApplicationRepository; | ||
import io.opensergo.dashboard.repository.application.MetadataRepository; | ||
import io.opensergo.dashboard.vo.service.MethodItem; | ||
import io.opensergo.dashboard.vo.service.ServiceItem; | ||
import io.opensergo.proto.service_contract.v1.MethodDescriptor; | ||
import io.opensergo.proto.service_contract.v1.ReportMetadataRequest; | ||
import io.opensergo.proto.service_contract.v1.ServiceDescriptor; | ||
import io.opensergo.proto.service_contract.v1.ServiceMetadata; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.*; | ||
|
||
/** | ||
* @author luyanbo | ||
*/ | ||
@RestController | ||
@RequestMapping(value = "/api/service/") | ||
public class ServiceController { | ||
|
||
@Autowired | ||
private ApplicationRepository applicationRepository; | ||
|
||
@Autowired | ||
private MetadataRepository metadataRepository; | ||
|
||
@GetMapping("/queryService") | ||
public PagedResult<List<ServiceItem>> queryService( | ||
String appName, | ||
String protocol, | ||
Pageable pageable | ||
) throws InvalidProtocolBufferException { | ||
Optional<MetadataEntity> metadataOptional = metadataRepository.findByAppName(appName); | ||
if (!metadataOptional.isPresent()) { | ||
return PagedResult.ofSuccess(new ArrayList<>()); | ||
} | ||
MetadataEntity appEntity = metadataOptional.get(); | ||
String metadataStr = appEntity.getMetadata(); | ||
ReportMetadataRequest.Builder reqBuilder = ReportMetadataRequest.newBuilder(); | ||
JsonFormat.parser().merge(metadataStr, reqBuilder); | ||
|
||
List<ServiceItem> serviceItems = new ArrayList<>(); | ||
for (ServiceMetadata serviceMetadata : reqBuilder.getServiceMetadataList()) { | ||
if (!serviceMetadata.getProtocolsList().contains(protocol)) { | ||
continue; | ||
} | ||
for (ServiceDescriptor serviceDescriptor : serviceMetadata.getServiceContract().getServicesList()) { | ||
ServiceItem serviceItem = new ServiceItem(); | ||
serviceItem.setAppName(reqBuilder.getAppName()); | ||
serviceItem.setServiceName(serviceDescriptor.getName()); | ||
serviceItems.add(serviceItem); | ||
} | ||
} | ||
return PagedResult.ofSuccess(serviceItems); | ||
} | ||
|
||
@GetMapping("/queryServiceMethod") | ||
public Result<List<MethodItem>> queryServiceMethod( | ||
String appName, | ||
String serviceName, | ||
String protocol, | ||
Pageable pageable | ||
) throws InvalidProtocolBufferException { | ||
Optional<MetadataEntity> metadataOptional = metadataRepository.findByAppName(appName); | ||
if (!metadataOptional.isPresent()) { | ||
return Result.ofSuccess(null); | ||
} | ||
MetadataEntity appEntity = metadataOptional.get(); | ||
String metadataStr = appEntity.getMetadata(); | ||
ReportMetadataRequest.Builder reqBuilder = ReportMetadataRequest.newBuilder(); | ||
JsonFormat.parser().merge(metadataStr, reqBuilder); | ||
|
||
List<MethodItem> methodItems = new ArrayList<>(); | ||
Set<String> methodNames = new HashSet<>(); | ||
for (ServiceMetadata serviceMetadata : reqBuilder.getServiceMetadataList()) { | ||
if (!serviceMetadata.getProtocolsList().contains(protocol)) { | ||
continue; | ||
} | ||
for (ServiceDescriptor serviceDescriptor : serviceMetadata.getServiceContract().getServicesList()) { | ||
if (serviceName.equals(serviceDescriptor.getName())) { | ||
for (MethodDescriptor methodDescriptor : serviceDescriptor.getMethodsList()) { | ||
if (methodNames.contains(methodDescriptor.getName())) { | ||
continue; | ||
} | ||
methodNames.add(methodDescriptor.getName()); | ||
MethodItem methodItem = new MethodItem(); | ||
methodItem.setMethodName(methodDescriptor.getName()); | ||
methodItems.add(methodItem); | ||
} | ||
} | ||
} | ||
} | ||
return Result.ofSuccess(methodItems); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -17,4 +17,6 @@ public class ApplicationEntity { | |
private Long id; | ||
|
||
private String name; | ||
|
||
private String sha256; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,6 @@ | |
@NoArgsConstructor | ||
public class ApplicationItem { | ||
String appName; | ||
|
||
String sha256; | ||
} |
10 changes: 10 additions & 0 deletions
10
opensergo-dashboard-server/src/main/java/io/opensergo/dashboard/vo/service/MethodItem.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,10 @@ | ||
package io.opensergo.dashboard.vo.service; | ||
|
||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
public class MethodItem { | ||
String methodName; | ||
} |
12 changes: 12 additions & 0 deletions
12
opensergo-dashboard-server/src/main/java/io/opensergo/dashboard/vo/service/ServiceItem.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,12 @@ | ||
package io.opensergo.dashboard.vo.service; | ||
|
||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
public class ServiceItem { | ||
String appName; | ||
|
||
String serviceName; | ||
} |
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
Oops, something went wrong.