Skip to content
Snippets Groups Projects
Commit 7e42541d authored by tranoris's avatar tranoris Committed by trantzas
Browse files

Iniitial commit

(cherry picked from commit bfa53c74)
parent 9443f93c
No related branches found
No related tags found
1 merge request!1Resolve "Populate main branch with initial commit (Release 0)"
/target/
.project
.classpath
/.settings
pom.xml 0 → 100644
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.etsi.osl</groupId>
<artifactId>org.etsi.osl.main</artifactId>
<version>1.2.0-SNAPSHOT</version>
<relativePath>../org.etsi.osl.main</relativePath>
</parent>
<artifactId>org.etsi.osl.centrallog.client</artifactId>
<name>org.etsi.osl.centrallog.client</name>
<dependencyManagement>
<dependencies>
<!-- Camel BOM -->
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-dependencies</artifactId>
<version>${camel.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- activeMQ -->
<!-- Camel -->
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-http-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-activemq</artifactId>
<exclusions>
<exclusion>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-broker</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-service-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-stream</artifactId>
</dependency>
</dependencies>
</project>
\ No newline at end of file
/*-
* ========================LICENSE_START=================================
* CentralLoggerClient
* %%
* Copyright (C) 2019 - 2020 openslice.io
* %%
* Licensed 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
*
* http://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.
* =========================LICENSE_END==================================
*/
package org.etsi.osl.centrallog.client;
/**
* @author ctranoris
*
*/
public enum CLevel {
INFO,
WARN,
ERROR
}
/*-
* ========================LICENSE_START=================================
* CentralLoggerClient
* %%
* Copyright (C) 2019 - 2020 openslice.io
* %%
* Licensed 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
*
* http://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.
* =========================LICENSE_END==================================
*/
package org.etsi.osl.centrallog.client;
import java.time.Instant;
/**
* @author ctranoris
*
*/
public class CentralLogMessage {
private CLevel clevel;
private String message;
private String time;
private String component;
/**
*
*/
public CentralLogMessage() {
this.clevel=CLevel.WARN;
this.message="This is the default CentralLogger message";
this.time = Instant.now().toString();
}
/**
* @param cLevel
* @param message
*/
public CentralLogMessage(CLevel cLevel, String message) {
super();
this.clevel = cLevel;
this.message = message;
this.time = Instant.now().toString();
}
/**
* @return the cLevel
*/
public CLevel getclevel() {
return clevel;
}
/**
* @param cLevel the cLevel to set
*/
public void setclevel(CLevel cLevel) {
this.clevel = cLevel;
}
/**
* @return the message
*/
public String getMessage() {
return message;
}
/**
* @param message the message to set
*/
public void setMessage(String message) {
this.message = message;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getComponent() {
return component;
}
public void setComponent(String component) {
this.component = component;
}
}
/*-
* ========================LICENSE_START=================================
* CentralLoggerClient
* %%
* Copyright (C) 2019 - 2020 openslice.io
* %%
* Licensed 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
*
* http://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.
* =========================LICENSE_END==================================
*/
package org.etsi.osl.centrallog.client;
public class CentralLogPackage {
String endpoint;
CentralLogMessage centrallogmsg;
/**
*
*/
public CentralLogPackage() {
this.endpoint = "";
this.centrallogmsg = new CentralLogMessage();
}
public String getEndpoint() {
return endpoint;
}
public void setEndpoint(String endpoint) {
this.endpoint = endpoint;
}
public CentralLogMessage getCentralLogMessage()
{
return this.centrallogmsg;
}
public void setCentralLogMessage(CentralLogMessage clm)
{
this.centrallogmsg=clm;
}
}
package org.etsi.osl.centrallog.client;
/*-
* ========================LICENSE_START=================================
* org.etsi.osl.portal.api
* %%
* Copyright (C) 2019 openslice.io
* %%
* Licensed 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
*
* http://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.
* =========================LICENSE_END==================================
*/
import java.util.concurrent.Future;
import org.apache.camel.Exchange;
import org.apache.camel.FluentProducerTemplate;
import org.apache.camel.ProducerTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import com.fasterxml.jackson.databind.ObjectMapper;
/**
* @author ctranoris
*
*
*/
@Configuration
@Component
public class CentralLogger {
/** the Camel Context configure via Spring. See bean.xml*/
// private static CamelContext actx;
@Autowired
private ProducerTemplate template;
// private static String centralloggerurl = null;
//
// public static String getCentralLoggerUrl()
// {
// return centralloggerurl;
// }
//
// public CentralLogger(String centralloggerurl_tmp) {
// super();
// centralloggerurl = centralloggerurl_tmp;
// }
//
// public static void setCentralLoggerUrl(String centralLoggerUrl)
// {
// centralloggerurl=centralLoggerUrl;
// }
// public void setActx(CamelContext actx) {
// CentralLogger.actx = actx;
// }
/**
* @param cl
* @param amessage
* @param componentName
*/
// public void log(CLevel cl, String amessage) {
// Map<String, Object> map = new HashMap<String, Object>();
// map.put("endpoint", this.centralloggerurl );
// map.put("clevel", cl.toString() );
// map.put("message", amessage );
// log(map);
// }
// public static void log(Map<String, Object> map)
// {
// String json;
// try {
// json = new ObjectMapper().writeValueAsString(map);
// //System.out.println(json);
// FluentProducerTemplate template = actx.createFluentProducerTemplate().to("seda:centralLog?multipleConsumers=true");
// Future<Exchange> result = template.withBody( json ).asyncSend();
// waitAndStopForTemplate( result, template);
//
// } catch (JsonProcessingException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
public void log(CLevel cl, String amessage, String component) {
// CentralLogPackage clp = new CentralLogPackage();
// clp.setEndpoint(centralloggerurl);
CentralLogMessage clm = new CentralLogMessage();
clm.setclevel(cl);
clm.setMessage(amessage);
clm.setComponent(component);
// clp.setCentralLogMessage(clm);
try {
log(clm);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void log(CentralLogMessage clm) throws Exception
{
// if ( actx==null) {
// throw new Exception("actx is null");
// }
if ( template==null) {
throw new Exception("template is null");
}
String json;
json = new ObjectMapper().writeValueAsString(clm);
// FluentProducerTemplate template = actx.createFluentProducerTemplate()
// .to("activemq:queue:centrallogger.log");
//Future<Exchange> result = template.withBody( json ).asyncSend();
//waitAndStopForTemplate( result, template);
template.sendBody("activemq:queue:centrallogger.log", json);
}
/**
*
* utility function to stop ProducerTemplate
* @param result
* @param template
*/
private void waitAndStopForTemplate(Future<Exchange> result, FluentProducerTemplate template) {
while (true) {
if (result.isDone()) {
//logger.info( "waitAndStopForTemplate: " + template.toString() + " [STOPPED]");
try {
template.stop();
//template.clearAll();
template.cleanUp();
break;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
try {
//logger.info( "waitAndStopForTemplate: " + template.toString() + " [WAITING...]");
Thread.sleep( 5000 );
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment