Skip to content

Commit

Permalink
Merge pull request #7 from muralibasani/3.5_improvements
Browse files Browse the repository at this point in the history
3.5 release changes
  • Loading branch information
muralibasani authored Jan 22, 2020
2 parents c41c142 + 83878c5 commit 26f7dd3
Show file tree
Hide file tree
Showing 8 changed files with 883 additions and 172 deletions.
32 changes: 26 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.kafkamgt.clusterapi</groupId>
<artifactId>kafkawizeclusterapi</artifactId>
<version>3.3</version>
<version>3.5</version>
<packaging>jar</packaging>

<name>kafkaclusterapi</name>
Expand All @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<version>2.1.11.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand Down Expand Up @@ -44,22 +44,28 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<!--<exclusions>-->
<!--<exclusion>-->
<!--<artifactId>*</artifactId>-->
<!--<groupId>org.mockito</groupId>-->
<!--</exclusion>-->
<!--</exclusions>-->
</dependency>
<!--Swagger-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.18</version>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
Expand All @@ -77,6 +83,20 @@
<version>2.2.2.RELEASE</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,80 +1,100 @@
package com.kafkamgt.clusterapi.controller;

import com.kafkamgt.clusterapi.services.ManageKafkaComponents;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;

@RestController
@RequestMapping("/topics")
@Slf4j
public class ClusterApiController {

private static Logger LOG = LoggerFactory.getLogger(ClusterApiController.class);

@Autowired
ManageKafkaComponents kafkaTopics;
ManageKafkaComponents manageKafkaComponents;

@RequestMapping(value = "/getTopics/{env}", method = RequestMethod.GET,produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<Set<String>> getTopics(@PathVariable String env){
Set<String> topics = kafkaTopics.loadTopics(env);
@RequestMapping(value = "/getApiStatus", method = RequestMethod.GET,produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> getApiStatus(){
return new ResponseEntity<>("ONLINE", HttpStatus.OK);
}

@RequestMapping(value = "/getStatus/{env}", method = RequestMethod.GET,produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<String> getStatus(@PathVariable String env){
String envStatus = manageKafkaComponents.getStatus(env);

return new ResponseEntity<>(envStatus, HttpStatus.OK);
}

@RequestMapping(value = "/getTopics/{env}", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<Set<String>> getTopics(@PathVariable String env){
Set<String> topics = manageKafkaComponents.loadTopics(env);
return new ResponseEntity<>(topics, HttpStatus.OK);
}

@RequestMapping(value = "/getAcls/{env}", method = RequestMethod.GET,produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<Set<HashMap<String,String>>> getAcls(@PathVariable String env){
Set<HashMap<String,String>> acls = kafkaTopics.loadAcls(env);
Set<HashMap<String,String>> acls = manageKafkaComponents.loadAcls(env);

return new ResponseEntity<>(acls, HttpStatus.OK);
}

@PostMapping(value = "/createTopics")
public ResponseEntity<String> createTopics(@RequestBody MultiValueMap<String, String> topicRequest){
kafkaTopics.createTopic(
topicRequest.get("topicName").get(0),
topicRequest.get("partitions").get(0),
topicRequest.get("rf").get(0),
topicRequest.get("env").get(0)
);
try {
manageKafkaComponents.createTopic(
topicRequest.get("topicName").get(0),
topicRequest.get("partitions").get(0),
topicRequest.get("rf").get(0),
topicRequest.get("env").get(0)
);
} catch (Exception e) {
e.printStackTrace();
return new ResponseEntity<String>("failure "+e, HttpStatus.OK);
}

return new ResponseEntity<String>("success", HttpStatus.OK);
}

@PostMapping(value = "/createAcls")
public ResponseEntity<String> createAcls(@RequestBody MultiValueMap<String, String> topicRequest){

// if(!utils.validateLicense()){
// LOG.info("Invalid License !!");
// return new ResponseEntity<String>("", HttpStatus.FORBIDDEN);
// }
LOG.info("----"+topicRequest.get("topicName"));
String aclType = topicRequest.get("aclType").get(0);
if(aclType.equals("Producer"))
kafkaTopics.createProducerAcl(topicRequest.get("topicName").get(0),topicRequest.get("env").get(0),
topicRequest.get("acl_ip").get(0),topicRequest.get("acl_ssl").get(0));
else
kafkaTopics.createConsumerAcl(topicRequest.get("topicName").get(0),topicRequest.get("env").get(0),
topicRequest.get("acl_ip").get(0),topicRequest.get("acl_ssl").get(0), topicRequest.get("consumerGroup").get(0));

return new ResponseEntity<String>("success", HttpStatus.OK);
try {
String aclType = topicRequest.get("aclType").get(0);

if (aclType.equals("Producer"))
manageKafkaComponents.createProducerAcl(topicRequest.get("topicName").get(0),
topicRequest.get("env").get(0),
topicRequest.get("acl_ip").get(0), topicRequest.get("acl_ssl").get(0));
else
manageKafkaComponents.createConsumerAcl(topicRequest.get("topicName").get(0),
topicRequest.get("env").get(0),
topicRequest.get("acl_ip").get(0), topicRequest.get("acl_ssl").get(0), topicRequest.get("consumerGroup").get(0));

return new ResponseEntity<String>("success", HttpStatus.OK);
}catch(Exception e){
return new ResponseEntity<String>("failure "+e.getMessage(), HttpStatus.OK);
}
}


@PostMapping(value = "/postSchema")
public ResponseEntity<String> postSchema(@RequestBody MultiValueMap<String, String> fullSchemaDetails){
String topicName= fullSchemaDetails.get("topicName").get(0);
String schemaFull = fullSchemaDetails.get("fullSchema").get(0);
String env = fullSchemaDetails.get("env").get(0);

String result = kafkaTopics.postSchema(topicName,schemaFull,env);

return new ResponseEntity<String>("Status:"+result, HttpStatus.OK);
try {
String topicName = fullSchemaDetails.get("topicName").get(0);
String schemaFull = fullSchemaDetails.get("fullSchema").get(0);
String env = fullSchemaDetails.get("env").get(0);

String result = manageKafkaComponents.postSchema(topicName, schemaFull, env);
return new ResponseEntity<>("Status:"+result, HttpStatus.OK);
}catch(Exception e){
return new ResponseEntity<>("failure "+e.getMessage(), HttpStatus.OK);
}
}


Expand Down
Loading

0 comments on commit 26f7dd3

Please sign in to comment.