Loading src/main/java/org/etsi/osl/centrallog/client/CLevel.java 0 → 100644 +34 −0 Viewed Changes for src/main/java/org/etsi/osl/centrallog/client/CLevel.java: 34 added lines, 0 removed lines. Original line number Diff line number Diff line /*- * ========================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 } src/main/java/org/etsi/osl/centrallog/client/CentralLogMessage.java 0 → 100644 +104 −0 Viewed Changes for src/main/java/org/etsi/osl/centrallog/client/CentralLogMessage.java: 104 added lines, 0 removed lines. Original line number Diff line number Diff line /*- * ========================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; } } src/main/java/org/etsi/osl/centrallog/client/CentralLogPackage.java 0 → 100644 +51 −0 Viewed Changes for src/main/java/org/etsi/osl/centrallog/client/CentralLogPackage.java: 51 added lines, 0 removed lines. Original line number Diff line number Diff line /*- * ========================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; } } src/main/java/org/etsi/osl/centrallog/client/CentralLogger.java 0 → 100644 +166 −0 Viewed Changes for src/main/java/org/etsi/osl/centrallog/client/CentralLogger.java: 166 added lines, 0 removed lines. Original line number Diff line number Diff line 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("jms:topic: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(); } } } } .gitignore 0 → 100644 +4 −0 Viewed Changes for .gitignore: 4 added lines, 0 removed lines. Original line number Diff line number Diff line /target/ .project .classpath /.settings Loading
src/main/java/org/etsi/osl/centrallog/client/CLevel.java 0 → 100644 +34 −0 Viewed Changes for src/main/java/org/etsi/osl/centrallog/client/CLevel.java: 34 added lines, 0 removed lines. Original line number Diff line number Diff line /*- * ========================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 }
src/main/java/org/etsi/osl/centrallog/client/CentralLogMessage.java 0 → 100644 +104 −0 Viewed Changes for src/main/java/org/etsi/osl/centrallog/client/CentralLogMessage.java: 104 added lines, 0 removed lines. Original line number Diff line number Diff line /*- * ========================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; } }
src/main/java/org/etsi/osl/centrallog/client/CentralLogPackage.java 0 → 100644 +51 −0 Viewed Changes for src/main/java/org/etsi/osl/centrallog/client/CentralLogPackage.java: 51 added lines, 0 removed lines. Original line number Diff line number Diff line /*- * ========================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; } }
src/main/java/org/etsi/osl/centrallog/client/CentralLogger.java 0 → 100644 +166 −0 Viewed Changes for src/main/java/org/etsi/osl/centrallog/client/CentralLogger.java: 166 added lines, 0 removed lines. Original line number Diff line number Diff line 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("jms:topic: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(); } } } }
.gitignore 0 → 100644 +4 −0 Viewed Changes for .gitignore: 4 added lines, 0 removed lines. Original line number Diff line number Diff line /target/ .project .classpath /.settings