Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[controller] Refactor StoresRoutes::getAllStores API #1246

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.linkedin.venice.controller.server;

import java.util.Optional;


public class ListAllStoresStatusesRequest {
private String cluster;
private String storeName;
private String includeSystemStores;
private Optional<String> storeConfigNameFilter;
private Optional<String> storeConfigValueFilter;

public ListAllStoresStatusesRequest(
String cluster,
String storeName,
String includeSystemStores,
Optional<String> storeConfigNameFilter,
Optional<String> storeConfigValueFilter) {
this.cluster = cluster;
this.storeName = storeName;
this.includeSystemStores = includeSystemStores;
this.storeConfigNameFilter = storeConfigNameFilter;
this.storeConfigValueFilter = storeConfigValueFilter;
}

public ListAllStoresStatusesRequest() {
}

public String getCluster() {
return cluster;
}

public String getStoreName() {
return storeName;
}

public void setCluster(String cluster) {
this.cluster = cluster;
}

public void setStoreName(String storeName) {
this.storeName = storeName;
}

public String getIncludeSystemStores() {
return includeSystemStores;
}

public void setIncludeSystemStores(String includeSystemStores) {
this.includeSystemStores = includeSystemStores;
}

public Optional<String> getStoreConfigNameFilter() {
return storeConfigNameFilter;
}

public void setStoreConfigNameFilter(Optional<String> storeConfigNameFilter) {
this.storeConfigNameFilter = storeConfigNameFilter;
}

public Optional<String> getStoreConfigValueFilter() {
return storeConfigValueFilter;
}

public void setStoreConfigValueFilter(Optional<String> storeConfigValueFilter) {
this.storeConfigValueFilter = storeConfigValueFilter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,24 @@ public Route getAllStoresStatuses(Admin admin) {
@Override
public void internalHandle(Request request, MultiStoreStatusResponse veniceResponse) {
AdminSparkServer.validateParams(request, CLUSTER_HEALTH_STORES.getParams(), admin);
String clusterName = request.queryParams(CLUSTER);
veniceResponse.setCluster(clusterName);
Map<String, String> storeStatusMap = admin.getAllStoreStatuses(clusterName);
veniceResponse.setStoreStatusMap(storeStatusMap);
ListAllStoresStatusesRequest listAllStoresStatusesRequest = new ListAllStoresStatusesRequest();
listAllStoresStatusesRequest.setCluster(request.queryParams(CLUSTER));

MultiStoreStatusResponse multiStoreStatusResponse = listAllStoresStatuses(listAllStoresStatusesRequest, admin);
veniceResponse.setCluster(multiStoreStatusResponse.getCluster());
veniceResponse.setStoreStatusMap(multiStoreStatusResponse.getStoreStatusMap());
}
};
}

private MultiStoreStatusResponse listAllStoresStatuses(ListAllStoresStatusesRequest request, Admin admin) {
MultiStoreStatusResponse veniceResponse = new MultiStoreStatusResponse();
veniceResponse.setCluster(request.getCluster());
Map<String, String> storeStatusMap = admin.getAllStoreStatuses(request.getCluster());
veniceResponse.setStoreStatusMap(storeStatusMap);
return veniceResponse;
}

public Route getInUseSchemaIds(Admin admin) {
return new VeniceRouteHandler<SchemaUsageResponse>(SchemaUsageResponse.class) {
@Override
Expand All @@ -276,7 +286,6 @@ public void internalHandle(Request request, SchemaUsageResponse response) {
String storeName = request.queryParams(NAME);
Set<Integer> schemaIds = admin.getInUseValueSchemaIds(clusterName, storeName);
response.setInUseValueSchemaIds(schemaIds);

}
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.linkedin.venice.controller.server;

import static org.testng.Assert.*;

import java.util.Optional;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;


public class ListAllStoresStatusesRequestTest {
private ListAllStoresStatusesRequest mockListAllStoresStatusesRequest;

private final String TEST_CLUSTER = "testCluster";
private final String TEST_STORE_NAME = "testStoreName";
private final String TEST_INCLUDE_SYSTEM_STORES = "testIncludeSystemStores";
private final String TEST_STORE_CONFIG_NAME_FILTER = "testStoreConfigNameFilter";
private final String TEST_STORE_CONFIG_VALUE_FILTER = "testStoreConfigValueFilter";

@BeforeMethod
public void setUp() {
// Create a mock ListStoresRequestTest with mock data for each of it's private fields:
mockListAllStoresStatusesRequest = new ListAllStoresStatusesRequest(
"cluster",
"storeName",
"includeSystemStores",
Optional.of("storeConfigNameFilter"),
Optional.of("storeConfigValueFilter"));
}

@Test
public void testGetCluster() {
assertEquals(mockListAllStoresStatusesRequest.getCluster(), "cluster");
}

@Test
public void testGetStoreName() {
assertEquals(mockListAllStoresStatusesRequest.getStoreName(), "storeName");
}

@Test
public void testSetCluster() {
mockListAllStoresStatusesRequest.setCluster(TEST_CLUSTER);
assertEquals(mockListAllStoresStatusesRequest.getCluster(), TEST_CLUSTER);
}

@Test
public void testSetStoreName() {
mockListAllStoresStatusesRequest.setStoreName(TEST_STORE_NAME);
assertEquals(mockListAllStoresStatusesRequest.getStoreName(), TEST_STORE_NAME);
}

@Test
public void testGetIncludeSystemStores() {
assertEquals(mockListAllStoresStatusesRequest.getIncludeSystemStores(), "includeSystemStores");
}

@Test
public void testSetIncludeSystemStores() {
mockListAllStoresStatusesRequest.setIncludeSystemStores(TEST_INCLUDE_SYSTEM_STORES);
assertEquals(mockListAllStoresStatusesRequest.getIncludeSystemStores(), TEST_INCLUDE_SYSTEM_STORES);
}

@Test
public void testGetStoreConfigNameFilter() {
assertEquals(mockListAllStoresStatusesRequest.getStoreConfigNameFilter(), Optional.of("storeConfigNameFilter"));
}

@Test
public void testSetStoreConfigNameFilter() {
mockListAllStoresStatusesRequest.setStoreConfigNameFilter(Optional.of(TEST_STORE_CONFIG_NAME_FILTER));
assertEquals(
mockListAllStoresStatusesRequest.getStoreConfigNameFilter(),
Optional.of(TEST_STORE_CONFIG_NAME_FILTER));
}

@Test
public void testGetStoreConfigValueFilter() {
assertEquals(mockListAllStoresStatusesRequest.getStoreConfigValueFilter(), Optional.of("storeConfigValueFilter"));
}

@Test
public void testSetStoreConfigValueFilter() {
mockListAllStoresStatusesRequest.setStoreConfigValueFilter(Optional.of(TEST_STORE_CONFIG_VALUE_FILTER));
assertEquals(
mockListAllStoresStatusesRequest.getStoreConfigValueFilter(),
Optional.of(TEST_STORE_CONFIG_VALUE_FILTER));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,31 @@ public void testGetFutureVersion() throws Exception {
Assert.assertEquals(multiStoreStatusResponse.getStoreStatusMap(), storeStatusMap);
}

@Test
public void testGetAllStoresStatuses() throws Exception {
Admin mockAdmin = mock(VeniceParentHelixAdmin.class);
doReturn(true).when(mockAdmin).isLeaderControllerFor(TEST_CLUSTER);

Store mockStore = mock(Store.class);
doReturn(mockStore).when(mockAdmin).getStore(TEST_CLUSTER, TEST_STORE_NAME);

Map<String, String> storeStatusMap = Collections.singletonMap("dc-0", "1");
doReturn(storeStatusMap).when(mockAdmin).getAllStoreStatuses(TEST_CLUSTER);

Request request = mock(Request.class);
doReturn(TEST_CLUSTER).when(request).queryParams(eq(ControllerApiConstants.CLUSTER));
doReturn(TEST_STORE_NAME).when(request).queryParams(eq(ControllerApiConstants.NAME));

Route getAllStoresStatusesRoute =
new StoresRoutes(false, Optional.empty(), pubSubTopicRepository).getAllStoresStatuses(mockAdmin);
MultiStoreStatusResponse multiStoreStatusResponse = ObjectMapperFactory.getInstance()
.readValue(
getAllStoresStatusesRoute.handle(request, mock(Response.class)).toString(),
MultiStoreStatusResponse.class);
Assert.assertEquals(multiStoreStatusResponse.getCluster(), TEST_CLUSTER);
Assert.assertEquals(multiStoreStatusResponse.getStoreStatusMap(), storeStatusMap);
}

@Test
public void testRollForwardToFutureVersion() throws Exception {
Admin mockAdmin = mock(VeniceParentHelixAdmin.class);
Expand Down
Loading