-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added endpoint for admins to check topics of all namespaces (#222)
* Added endpoint for admins to check topics of all namespaces * Fixed test
- Loading branch information
Loïc GREFFIER
authored
Nov 9, 2022
1 parent
3baffa2
commit 5f33076
Showing
13 changed files
with
214 additions
and
80 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
30 changes: 30 additions & 0 deletions
30
...in/java/com/michelin/ns4kafka/controllers/quota/ResourceQuotaNonNamespacedController.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,30 @@ | ||
package com.michelin.ns4kafka.controllers.quota; | ||
|
||
import com.michelin.ns4kafka.controllers.generic.NonNamespacedResourceController; | ||
import com.michelin.ns4kafka.models.quota.ResourceQuotaResponse; | ||
import com.michelin.ns4kafka.security.ResourceBasedSecurityRule; | ||
import com.michelin.ns4kafka.services.ResourceQuotaService; | ||
import io.micronaut.http.annotation.Controller; | ||
import io.micronaut.http.annotation.Get; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
|
||
import javax.annotation.security.RolesAllowed; | ||
import javax.inject.Inject; | ||
import java.util.List; | ||
|
||
@Tag(name = "Resource Quotas") | ||
@Controller(value = "/api/resource-quotas") | ||
@RolesAllowed(ResourceBasedSecurityRule.IS_ADMIN) | ||
public class ResourceQuotaNonNamespacedController extends NonNamespacedResourceController { | ||
@Inject | ||
ResourceQuotaService resourceQuotaService; | ||
|
||
/** | ||
* Get all the quotas of all namespaces | ||
* @return A list of quotas | ||
*/ | ||
@Get | ||
public List<ResourceQuotaResponse> listAll() { | ||
return resourceQuotaService.getUsedResourcesByQuotaForAllNamespaces(); | ||
} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
api/src/main/java/com/michelin/ns4kafka/controllers/topic/TopicNonNamespacedController.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,30 @@ | ||
package com.michelin.ns4kafka.controllers.topic; | ||
|
||
import com.michelin.ns4kafka.controllers.generic.NonNamespacedResourceController; | ||
import com.michelin.ns4kafka.models.Topic; | ||
import com.michelin.ns4kafka.security.ResourceBasedSecurityRule; | ||
import com.michelin.ns4kafka.services.TopicService; | ||
import io.micronaut.http.annotation.Controller; | ||
import io.micronaut.http.annotation.Get; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
|
||
import javax.annotation.security.RolesAllowed; | ||
import javax.inject.Inject; | ||
import java.util.List; | ||
|
||
@Tag(name = "Topics") | ||
@Controller(value = "/api/topics") | ||
@RolesAllowed(ResourceBasedSecurityRule.IS_ADMIN) | ||
public class TopicNonNamespacedController extends NonNamespacedResourceController { | ||
@Inject | ||
TopicService topicService; | ||
|
||
/** | ||
* Get all the topics of all namespaces | ||
* @return A list of topics | ||
*/ | ||
@Get | ||
public List<Topic> listAll() { | ||
return topicService.findAll(); | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
...test/java/com/michelin/ns4kafka/controllers/ResourceQuotaNonNamespacedControllerTest.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,44 @@ | ||
package com.michelin.ns4kafka.controllers; | ||
|
||
import com.michelin.ns4kafka.controllers.quota.ResourceQuotaNonNamespacedController; | ||
import com.michelin.ns4kafka.models.quota.ResourceQuotaResponse; | ||
import com.michelin.ns4kafka.services.ResourceQuotaService; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.util.List; | ||
|
||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class ResourceQuotaNonNamespacedControllerTest { | ||
@InjectMocks | ||
ResourceQuotaNonNamespacedController resourceQuotaController; | ||
|
||
@Mock | ||
ResourceQuotaService resourceQuotaService; | ||
|
||
/** | ||
* Validate quota listing | ||
*/ | ||
@Test | ||
void listAll() { | ||
ResourceQuotaResponse response = ResourceQuotaResponse.builder() | ||
.spec(ResourceQuotaResponse.ResourceQuotaResponseSpec.builder() | ||
.countTopic("2/5") | ||
.countPartition("2/10") | ||
.countConnector("5/5") | ||
.build()) | ||
.build(); | ||
|
||
when(resourceQuotaService.getUsedResourcesByQuotaForAllNamespaces()).thenReturn(List.of(response)); | ||
|
||
List<ResourceQuotaResponse> actual = resourceQuotaController.listAll(); | ||
Assertions.assertEquals(1, actual.size()); | ||
Assertions.assertEquals(response, actual.get(0)); | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
api/src/test/java/com/michelin/ns4kafka/controllers/TopicNonNamespacedControllerTest.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,47 @@ | ||
package com.michelin.ns4kafka.controllers; | ||
|
||
import com.michelin.ns4kafka.controllers.topic.TopicNonNamespacedController; | ||
import com.michelin.ns4kafka.models.ObjectMeta; | ||
import com.michelin.ns4kafka.models.Topic; | ||
import com.michelin.ns4kafka.services.NamespaceService; | ||
import com.michelin.ns4kafka.services.TopicService; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.util.List; | ||
|
||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class TopicNonNamespacedControllerTest { | ||
@Mock | ||
NamespaceService namespaceService; | ||
|
||
@Mock | ||
TopicService topicService; | ||
|
||
@InjectMocks | ||
TopicNonNamespacedController topicController; | ||
|
||
/** | ||
* Validate topics listing | ||
*/ | ||
@Test | ||
void listAll() { | ||
when(topicService.findAll()) | ||
.thenReturn(List.of( | ||
Topic.builder().metadata(ObjectMeta.builder().name("topic1").build()).build(), | ||
Topic.builder().metadata(ObjectMeta.builder().name("topic2").build()).build() | ||
)); | ||
|
||
List<Topic> actual = topicController.listAll(); | ||
|
||
Assertions.assertEquals(2, actual.size()); | ||
Assertions.assertEquals("topic1", actual.get(0).getMetadata().getName()); | ||
Assertions.assertEquals("topic2", actual.get(1).getMetadata().getName()); | ||
} | ||
} |
Oops, something went wrong.