Commit 51d9b90f authored by ReemyHasan's avatar ReemyHasan

Some cleaning

parent 7617ee44
......@@ -34,16 +34,6 @@ public class TrapData {
@JsonProperty("variableBindings")
public List<VarBind> variableBindings = new ArrayList<VarBind>();
// public TrapData(String enterprise, String agentAddress, int genericTrap, int specificTrap, long timestamp, List<VariableBinding> trapVariableBindings) {
// this.enterprise = enterprise;
// this.genericTrap = genericTrap;
// this.specificTrap = specificTrap;
// this.timestamp = timestamp;
// this.agentAddress = agentAddress;
// for (VariableBinding vb : trapVariableBindings) {
// this.variableBindings.add(new VarBind(vb));
// }
// }
public TrapData(PDUv1 pdu){
this.enterprise = pdu.getEnterprise().toString();
......@@ -58,56 +48,6 @@ public class TrapData {
}
}
// public TrapData() {
// }
// public String getEnterprise() {
// return enterprise;
// }
//
// public void setEnterprise(String enterprise) {
// this.enterprise = enterprise;
// }
//
// public int getGenericTrap() {
// return genericTrap;
// }
//
// public void setGenericTrap(int genericTrap) {
// this.genericTrap = genericTrap;
// }
//
// public int getSpecificTrap() {
// return specificTrap;
// }
//
// public void setSpecificTrap(int specificTrap) {
// this.specificTrap = specificTrap;
// }
//
// public long getTimestamp() {
// return timestamp;
// }
//
// public void setTimestamp(long timestamp) {
// this.timestamp = timestamp;
// }
//
// public List<VarBind> getVariableBindings() {
// return variableBindings;
// }
//
// public void setVariableBindings(List<VarBind> variableBindings) {
// this.variableBindings = variableBindings;
// }
//
// public String getAgentAddress() {
// return agentAddress;
// }
//
// public void setAgentAddress(String agentAddress) {
// this.agentAddress = agentAddress;
// }
public void print(){
System.out.println("enterprise = " + this.getEnterprise());
System.out.println("enterprise = " + this.getAgentAddress());
......
......@@ -17,33 +17,11 @@ public class VarBind {
@JsonProperty("value")
public String value;
// public VarBind(String oid, String value) {
// this.oid = oid;
// this.value = value;
// }
public VarBind(VariableBinding vb){
this.oid = vb.getOid().toString();
this.value = vb.getVariable().toString();
}
// public VarBind() {
// }
// public String getOid() {
// return oid;
// }
//
// public void setOid(String oid) {
// this.oid = oid;
// }
//
// public String getValue() {
// return value;
// }
//
// public void setValue(String value) {
// this.value = value;
// }
public void print(){
System.out.println("oid = "+ this.getOid() + "," + "value = "+ this.getValue());
}
......
......@@ -27,7 +27,7 @@ public class TrapStreamApplication {
private ElasticService elasticService;
@KafkaListener(topics = "EnrichedTrap")
public void handleKafkaMessage(String pduJson) {
String json = pduJson; // Replace with your JSON string
String json = pduJson;
num++;
try {
ObjectMapper objectMapper = new ObjectMapper();
......@@ -39,22 +39,19 @@ public class TrapStreamApplication {
System.out.println(e);
e.printStackTrace();
}
//System.out.println(num);
System.out.println(num);
}
@PostConstruct
public void magic(){
Timer timer = new Timer();
TimerTask task = new TimerTask() {
public void run() {
// Call your function here
myFunction();
}
};
// Schedule the task to run every 10 seconds
timer.schedule(task, 0, 3000);
}
public void myFunction(){
System.out.println("Hey");
elasticService.sendBulk();
}
}
......@@ -41,11 +41,9 @@ public class elasticConfig {
private RestClient restClient = RestClient.builder(
new HttpHost("172.29.3.220", 9200)).build();
// Create the transport with a Jackson mapper
private ElasticsearchTransport transport = new RestClientTransport(
restClient, new JacksonJsonpMapper());
// And create the API client
private ElasticsearchClient elasticClient = new ElasticsearchClient(transport);
public void addPolicy(String path,String name){
FileReader r = null;
......@@ -87,8 +85,6 @@ public class elasticConfig {
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
// IndexTemplate indexTemplate = new IndexTemplate.Builder().withJson(r).build();
// IndexTemplateMapping indexTemplateMapping = new IndexTemplateMapping.Builder().withJson(r).build();
PutIndexTemplateRequest putIndexTemplateRequest = new PutIndexTemplateRequest
.Builder()
.withJson(r)
......@@ -140,18 +136,6 @@ public class elasticConfig {
System.out.println(e);
throw new RuntimeException(e);
}
/*
Reader input = new StringReader(json);
IndexRequest<JsonData> request = IndexRequest.of(i -> i
.index("bashar-data-stream-2")
.withJson(input)
);
IndexResponse response = null;
try {
response = elasticClient.index(request);
} catch (IOException e) {
throw new RuntimeException(e);
}
System.out.println("Indexed with version " + response.version());*/
}
}
......@@ -59,9 +59,7 @@ public class ElasticService {
System.out.println("Sent "+bulk.size());
bulk.clear();
BulkResponse result = null;
System.out.println("Hey I am here");
try {
System.out.println("Hey I am here");
result = elConf.getElasticClient().bulk(br.build());
System.out.println(result);
} catch (IOException e) {
......
......@@ -53,9 +53,8 @@ public class RethinkController {
for (Map<String, Object> rawEntry : rawResults) {
String severityLevel = rawEntry.get("severity").toString();
long timestamp = (long) rawEntry.get("timestamp"); // Assuming timestamp is a long value representing Unix timestamp in milliseconds
long timestamp = (long) rawEntry.get("timestamp");
// Convert Unix timestamp to a Date and extract hour
String hour = convertTimestampToHour(timestamp);
processedData.putIfAbsent(hour, new HashMap<>());
......@@ -69,7 +68,7 @@ public class RethinkController {
private String convertTimestampToHour(long timestamp) {
Date date = new Date(timestamp);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); // Customize the format as needed
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
return sdf.format(date);
}
......
......@@ -75,7 +75,6 @@ public class SettingController {
@PostMapping("/translate")
public ResponseEntity<String> translateText(@RequestBody String request) {
// String translatedText = settingService.translateText(request.getSourceText(), request.getTargetLanguage());
return ResponseEntity.ok(request);
}
}
......@@ -37,23 +37,7 @@ public class EnrichedTrap {
this.timestamp = pdu.getTimestamp();
this.agentAddress = pdu.getAgentAddress().toString();
this.variableBindings = pdu.getVariableBindings();
/*if (this.variableBindings.size() > 5){
this.severity = SeverityLevel.WARNING;
}
else if (this.variableBindings.size() >= 3){
this.severity = SeverityLevel.ERROR;
}
else this.severity = SeverityLevel.INFO;*/
}
/*public EnrichedTrap(String enterprise, String agentAddress, int genericTrap, int specificTrap, long timestamp, String severity, List<VarBind> variableBindings) {
this.enterprise = enterprise;
this.agentAddress = agentAddress;
this.genericTrap = genericTrap;
this.specificTrap = specificTrap;
this.timestamp = timestamp;
this.severity = (severity);
this.variableBindings = variableBindings;
}*/
}
package com.example.WebApplication.entities;
public class SeverityLevel {
/*INFO("INFO"),
WARNING("WARNING"),
ERROR("ERROR");
private final String stringValue;
SeverityLevel(String stringValue) {
this.stringValue = stringValue;
}
public String getStringValue() {
return stringValue;
}
public static SeverityLevel fromStringValue(String stringValue) {
for (SeverityLevel enumValue : SeverityLevel.values()) {
if (enumValue.stringValue.equals(stringValue)) {
return enumValue;
}
}
throw new IllegalArgumentException("Invalid string value for SeverityLevel: " + stringValue);
}
public static SeverityLevel fromString(String string) {
for (SeverityLevel enumValue : SeverityLevel.values()) {
if (enumValue.stringValue.equalsIgnoreCase(string)) {
return enumValue;
}
}
throw new IllegalArgumentException("Invalid string value for SeverityLevel: " + string);
}*/
}
......@@ -51,7 +51,6 @@ public class RethinkDBService{
JsonNode jsonNode = objectMapper.readTree(jsonString);
Map<String,EnrichedTrap> document = objectMapper.convertValue(jsonNode, Map.class);
r.db(connectionFactory.getDbName()).table(connectionFactory.getDbTableName()).insert(document).run(connectionFactory.getConnection());
System.out.println("I am here now reem");
} catch (Exception e) {
System.out.println("error " + e);
}
......@@ -82,7 +81,7 @@ public class RethinkDBService{
eventPublisher.publishEvent(new RethinkAppChange(this, changedData.getOld_val(), changedData.getNew_val()));
}
} catch (Exception e) {
System.out.println("Bkh");
System.out.println("error "+e);
}});
}
public void deleteById(String id){
......
......@@ -17,7 +17,14 @@ spring.cloud.gateway.routes[2].uri=lb://USER-SERVICE
spring.cloud.gateway.routes[2].predicates[0]=Path=/users/**
spring.cloud.gateway.routes[2].filters[0]=AuthenticationFilter
spring.cloud.gateway.routes[3].id=user-service
spring.cloud.gateway.routes[3].uri=lb://USER-SERVICE
spring.cloud.gateway.routes[3].predicates[0]=Path=/users/**
spring.cloud.gateway.routes[3].filters[0]=AuthenticationFilter
\ No newline at end of file
spring.cloud.gateway.routes[3].id=feedback-service
spring.cloud.gateway.routes[3].uri=lb://FEEDBACK-SERVICE
spring.cloud.gateway.routes[3].predicates[0]=Path=/feedback/**
spring.cloud.gateway.routes[3].filters[0]=AuthenticationFilter
spring.cloud.gateway.routes[4].id=ml-model-service
spring.cloud.gateway.routes[4].uri=lb://ML-MODEL-SERVICE
spring.cloud.gateway.routes[4].predicates[0]=Path=/model/**
spring.cloud.gateway.routes[4].filters[0]=AuthenticationFilter
//package com.example.config;
//
//import org.springframework.context.annotation.Configuration;
//import org.springframework.web.servlet.config.annotation.CorsRegistry;
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
//
//@Configuration
//public class AppConfig implements WebMvcConfigurer {
//
// @Override
// public void addCorsMappings(CorsRegistry registry) {
// registry.addMapping("/**")
// .allowedOrigins("*")
// .allowedMethods("GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS")
// .allowedHeaders("*")
// .allowCredentials(true)
// .maxAge(3600);
// }
//}
//package com.example.config;
//
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.HttpStatus;
//import org.springframework.http.server.reactive.ServerHttpResponse;
//import org.springframework.stereotype.Component;
//import org.springframework.web.cors.reactive.CorsUtils;
//import org.springframework.web.server.ServerWebExchange;
//import org.springframework.web.server.WebFilter;
//import org.springframework.web.server.WebFilterChain;
//import reactor.core.publisher.Mono;
//
//@Component
//public class CorsFilter implements WebFilter {
//
// @Override
// public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
// if (CorsUtils.isPreFlightRequest(exchange.getRequest())) {
// ServerHttpResponse response = exchange.getResponse();
// HttpHeaders headers = response.getHeaders();
// headers.add("Access-Control-Allow-Origin", "*");
// headers.add("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE");
// headers.add("Access-Control-Allow-Headers", "*");
// headers.add("Access-Control-Allow-Credentials", "true");
// headers.add("Access-Control-Max-Age", "3600");
// response.setStatusCode(HttpStatus.OK);
// return Mono.empty();
// } else {
// return chain.filter(exchange);
// }
// }
//}
//
//
//
//
//
......@@ -23,10 +23,8 @@ public class AuthController {
@PostMapping("/token")
public String getToken(@RequestBody AuthRequest authRequest) {
System.out.println("Hi" + authRequest);
try {
Authentication authenticate = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(authRequest.getUsername(), authRequest.getPassword()));
System.out.println("HEY");
if (authenticate.isAuthenticated()) {
return service.generateToken(authRequest.getUsername());
}
......@@ -34,15 +32,6 @@ public class AuthController {
e.printStackTrace();
return "Invalid Access";
}
// Authentication authenticate = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(authRequest.getUsername(), authRequest.getPassword()));
// System.out.println("HEY");
// if (authenticate.isAuthenticated()) {
// return service.generateToken(authRequest.getUsername());
// } else {
// System.out.println("invalid access");
// throw new RuntimeException("invalid access");
// }
return null;
}
......
......@@ -20,7 +20,6 @@ public class AuthService {
private JwtService jwtService;
public Optional<UserCredential> saveUser(UserCredential credential) {
// System.out.println("dskmdelkwmelkamdk "+credential);
credential.setPassword(passwordEncoder.encode(credential.getPassword()));
try {
repository.save(credential);
......
......@@ -25,7 +25,6 @@ public class UserService {
}
public Optional<UserCredential> saveUser(UserCredential credential) {
// System.out.println("dskmdelkwmelkamdk "+credential);
credential.setPassword(passwordEncoder.encode(credential.getPassword()));
try {
repository.save(credential);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment