Skip to content

Commit

Permalink
BIGTOP-4372: Adjust APIs related to cluster management for UI needs (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinw66 authored Feb 19, 2025
1 parent ade59c2 commit 3fc2812
Show file tree
Hide file tree
Showing 19 changed files with 361 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ protected Boolean isTaskRequest(Object obj) {

// Every task will have taskId, but TaskLogRequest have it also, so we need to exclude it
Class<?> clazz = obj.getClass();
if (clazz.isInstance(TaskLogRequest.class)) {
if (TaskLogRequest.class.isAssignableFrom(clazz)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.bigtop.manager.agent.grpc.interceptor;

import org.apache.bigtop.manager.common.utils.ProjectPathUtils;
import org.apache.bigtop.manager.grpc.generated.TaskLogRequest;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -91,16 +92,17 @@ public void testTruncateLogFileFileDoesNotExist() throws IOException {
}

@Test
public void testIsTaskRequestTaskRequest() {
TaskLogRequest taskLogRequest = new TaskLogRequest();
public void testIsTaskLogRequestTaskRequest() {
TaskLogRequest taskLogRequest =
TaskLogRequest.newBuilder().setTaskId(1L).build();

Boolean result = taskInterceptor.isTaskRequest(taskLogRequest);

assertTrue(result);
assertFalse(result);
}

@Test
public void testIsTaskRequestTaskWithGetTaskIdMethod() {
public void testIsTaskRequestTaskRequest() {
Task task = new Task();

Boolean result = taskInterceptor.isTaskRequest(task);
Expand Down Expand Up @@ -129,10 +131,4 @@ public Long getTaskId() {
return 1L;
}
}

private static class TaskLogRequest {
public Long getTaskId() {
return 1L;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.bigtop.manager.server.command.validator;

import org.apache.bigtop.manager.common.enums.Command;
import org.apache.bigtop.manager.dao.po.ServicePO;
import org.apache.bigtop.manager.dao.repository.ServiceDao;
import org.apache.bigtop.manager.server.command.CommandIdentifier;
import org.apache.bigtop.manager.server.enums.ApiExceptionEnum;
import org.apache.bigtop.manager.server.enums.CommandLevel;
import org.apache.bigtop.manager.server.exception.ApiException;

import org.apache.commons.collections4.CollectionUtils;

import org.springframework.stereotype.Component;

import jakarta.annotation.Resource;
import java.util.List;

@Component
public class ClusterRestartValidator implements CommandValidator {

@Resource
private ServiceDao serviceDao;

@Override
public List<CommandIdentifier> getCommandIdentifiers() {
return List.of(new CommandIdentifier(CommandLevel.CLUSTER, Command.RESTART));
}

@Override
public void validate(ValidatorContext context) {
Long clusterId = context.getCommandDTO().getClusterId();
List<ServicePO> servicePOList = serviceDao.findByClusterId(clusterId);

if (CollectionUtils.isEmpty(servicePOList)) {
throw new ApiException(ApiExceptionEnum.CLUSTER_HAS_NO_SERVICES);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.bigtop.manager.server.command.validator;

import org.apache.bigtop.manager.common.enums.Command;
import org.apache.bigtop.manager.dao.po.ServicePO;
import org.apache.bigtop.manager.dao.repository.ServiceDao;
import org.apache.bigtop.manager.server.command.CommandIdentifier;
import org.apache.bigtop.manager.server.enums.ApiExceptionEnum;
import org.apache.bigtop.manager.server.enums.CommandLevel;
import org.apache.bigtop.manager.server.exception.ApiException;

import org.apache.commons.collections4.CollectionUtils;

import org.springframework.stereotype.Component;

import jakarta.annotation.Resource;
import java.util.List;

@Component
public class ClusterStartValidator implements CommandValidator {

@Resource
private ServiceDao serviceDao;

@Override
public List<CommandIdentifier> getCommandIdentifiers() {
return List.of(new CommandIdentifier(CommandLevel.CLUSTER, Command.START));
}

@Override
public void validate(ValidatorContext context) {
Long clusterId = context.getCommandDTO().getClusterId();
List<ServicePO> servicePOList = serviceDao.findByClusterId(clusterId);

if (CollectionUtils.isEmpty(servicePOList)) {
throw new ApiException(ApiExceptionEnum.CLUSTER_HAS_NO_SERVICES);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.bigtop.manager.server.command.validator;

import org.apache.bigtop.manager.common.enums.Command;
import org.apache.bigtop.manager.dao.po.ServicePO;
import org.apache.bigtop.manager.dao.repository.ServiceDao;
import org.apache.bigtop.manager.server.command.CommandIdentifier;
import org.apache.bigtop.manager.server.enums.ApiExceptionEnum;
import org.apache.bigtop.manager.server.enums.CommandLevel;
import org.apache.bigtop.manager.server.exception.ApiException;

import org.apache.commons.collections4.CollectionUtils;

import org.springframework.stereotype.Component;

import jakarta.annotation.Resource;
import java.util.List;

@Component
public class ClusterStopValidator implements CommandValidator {

@Resource
private ServiceDao serviceDao;

@Override
public List<CommandIdentifier> getCommandIdentifiers() {
return List.of(new CommandIdentifier(CommandLevel.CLUSTER, Command.STOP));
}

@Override
public void validate(ValidatorContext context) {
Long clusterId = context.getCommandDTO().getClusterId();
List<ServicePO> servicePOList = serviceDao.findByClusterId(clusterId);

if (CollectionUtils.isEmpty(servicePOList)) {
throw new ApiException(ApiExceptionEnum.CLUSTER_HAS_NO_SERVICES);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.bigtop.manager.server.model.vo.PageVO;
import org.apache.bigtop.manager.server.model.vo.ServiceConfigSnapshotVO;
import org.apache.bigtop.manager.server.model.vo.ServiceConfigVO;
import org.apache.bigtop.manager.server.model.vo.ServiceUserVO;
import org.apache.bigtop.manager.server.model.vo.ServiceVO;
import org.apache.bigtop.manager.server.service.ServiceService;
import org.apache.bigtop.manager.server.utils.ResponseEntity;
Expand Down Expand Up @@ -72,6 +73,22 @@ public ResponseEntity<PageVO<ServiceVO>> list(ServiceQuery query) {
return ResponseEntity.success(serviceService.list(query));
}

@Parameters({
@Parameter(in = ParameterIn.QUERY, name = "pageNum", schema = @Schema(type = "integer", defaultValue = "1")),
@Parameter(in = ParameterIn.QUERY, name = "pageSize", schema = @Schema(type = "integer", defaultValue = "10")),
@Parameter(in = ParameterIn.QUERY, name = "orderBy", schema = @Schema(type = "string", defaultValue = "id")),
@Parameter(
in = ParameterIn.QUERY,
name = "sort",
description = "asc/desc",
schema = @Schema(type = "string", defaultValue = "asc"))
})
@Operation(summary = "service user list", description = "List service users")
@GetMapping("/users")
public ResponseEntity<PageVO<ServiceUserVO>> serviceUsers(@PathVariable Long clusterId) {
return ResponseEntity.success(serviceService.serviceUsers(clusterId));
}

@Operation(summary = "get", description = "Get a service")
@GetMapping("/{id}")
public ResponseEntity<ServiceVO> get(@PathVariable Long clusterId, @PathVariable Long id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@
*/
package org.apache.bigtop.manager.server.controller;

import org.apache.bigtop.manager.server.model.vo.ClusterVO;
import org.apache.bigtop.manager.server.model.vo.ServiceClusterVO;
import org.apache.bigtop.manager.server.model.vo.StackVO;
import org.apache.bigtop.manager.server.service.StackService;
import org.apache.bigtop.manager.server.utils.ResponseEntity;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -49,8 +48,8 @@ public ResponseEntity<List<StackVO>> list() {
}

@Operation(summary = "service clusters", description = "Get service clusters")
@GetMapping("/services/{serviceName}/clusters")
public ResponseEntity<List<ClusterVO>> serviceClusters(@PathVariable String serviceName) {
return ResponseEntity.success(stackService.serviceClusters(serviceName));
@GetMapping("/services/clusters")
public ResponseEntity<List<ServiceClusterVO>> serviceClusters() {
return ResponseEntity.success(stackService.serviceClusters());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public enum ApiExceptionEnum {
CLUSTER_EXISTS(11001, LocaleKeys.CLUSTER_EXISTS),
CLUSTER_HAS_HOSTS(11002, LocaleKeys.CLUSTER_HAS_HOSTS),
CLUSTER_HAS_SERVICES(11003, LocaleKeys.CLUSTER_HAS_SERVICES),
CLUSTER_HAS_NO_SERVICES(11004, LocaleKeys.CLUSTER_HAS_NO_SERVICES),

// Host Exceptions -- 12000 ~ 12999
HOST_NOT_FOUND(12000, LocaleKeys.HOST_NOT_FOUND),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public enum LocaleKeys {
CLUSTER_EXISTS("cluster.exists"),
CLUSTER_HAS_HOSTS("cluster.has.hosts"),
CLUSTER_HAS_SERVICES("cluster.has.services"),
CLUSTER_HAS_NO_SERVICES("cluster.has.no.services"),

HOST_NOT_FOUND("host.not.found"),
HOST_ASSIGNED("host.assigned"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ public class JobVO {

private String updateTime;

private Integer progress;

private List<StageVO> stages;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.bigtop.manager.server.model.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ServiceClusterVO {

private String serviceName;

private List<ClusterVO> clusters;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.bigtop.manager.server.model.vo;

import lombok.Data;

@Data
public class ServiceUserVO {

private String displayName;

private String user;

private String userGroup;

private String desc;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.bigtop.manager.server.model.vo.PageVO;
import org.apache.bigtop.manager.server.model.vo.ServiceConfigSnapshotVO;
import org.apache.bigtop.manager.server.model.vo.ServiceConfigVO;
import org.apache.bigtop.manager.server.model.vo.ServiceUserVO;
import org.apache.bigtop.manager.server.model.vo.ServiceVO;

import java.util.List;
Expand All @@ -37,6 +38,13 @@ public interface ServiceService {
*/
PageVO<ServiceVO> list(ServiceQuery query);

/**
* Get service users.
*
* @return service users
*/
PageVO<ServiceUserVO> serviceUsers(Long clusterId);

/**
* Get a service.
*
Expand Down
Loading

0 comments on commit 3fc2812

Please sign in to comment.