diff options
author | 2021-03-19 11:25:07 +0000 | |
---|---|---|
committer | 2021-03-19 17:00:24 +0000 | |
commit | b1fc8c337d3b9750eff6e62b626c0bc3a1467a88 (patch) | |
tree | eb998524e59b271bbdab635fabe56ff1bb979619 /catalog-be/src/main/java/org/openecomp/sdc/be/catalog | |
parent | 260a951d3431429bab9732e16225e42641ae4787 (diff) |
Reformat catalog-be
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech>
Issue-ID: SDC-3449
Change-Id: I45ae9fef826bcd5e3aa65c81d232d349faf02f91
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/catalog')
9 files changed, 213 insertions, 242 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/IComponentMessage.java b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/IComponentMessage.java index 42a869137b..588bddbbd5 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/IComponentMessage.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/IComponentMessage.java @@ -17,29 +17,25 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.be.catalog.api; +import java.io.Serializable; import org.openecomp.sdc.be.catalog.enums.ChangeTypeEnum; import org.openecomp.sdc.be.model.CatalogUpdateTimestamp; -import java.io.Serializable; - - - /** - * Represent Component (service, resource etc...) change message added to the - * message queue by sdc backend.<br> - * - * @author ms172g + * Represent Component (service, resource etc...) change message added to the message queue by sdc backend.<br> * + * @author ms172g */ public interface IComponentMessage extends Serializable, ITypeMessage { - /** - * Change Type - * @return - */ - ChangeTypeEnum getChangeType(); - CatalogUpdateTimestamp getCatalogUpdateTimestamp(); + /** + * Change Type + * + * @return + */ + ChangeTypeEnum getChangeType(); + + CatalogUpdateTimestamp getCatalogUpdateTimestamp(); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/IMessageQueueHandlerProducer.java b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/IMessageQueueHandlerProducer.java index 21c3ac8f2e..c898825a78 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/IMessageQueueHandlerProducer.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/IMessageQueueHandlerProducer.java @@ -17,12 +17,11 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.be.catalog.api; public interface IMessageQueueHandlerProducer { - + IStatus pushMessage(ITypeMessage message); - IStatus init(); + IStatus init(); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/IStatus.java b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/IStatus.java index dd21c2985d..7ffb6d01cc 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/IStatus.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/IStatus.java @@ -17,16 +17,14 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.be.catalog.api; import org.openecomp.sdc.be.catalog.enums.ResultStatusEnum; @FunctionalInterface public interface IStatus { - + static IStatus getSuccessStatus() { - return () -> ResultStatusEnum.SUCCESS; } @@ -39,5 +37,4 @@ public interface IStatus { } ResultStatusEnum getResultStatus(); - -}
\ No newline at end of file +} diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/ITypeMessage.java b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/ITypeMessage.java index a58e5f87c1..cec7313116 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/ITypeMessage.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/api/ITypeMessage.java @@ -17,9 +17,9 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.be.catalog.api; public interface ITypeMessage { + String getMessageType(); } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/enums/ChangeTypeEnum.java b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/enums/ChangeTypeEnum.java index 5107468af4..776c00bde4 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/enums/ChangeTypeEnum.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/enums/ChangeTypeEnum.java @@ -17,14 +17,13 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.be.catalog.enums; /** - * Represents The change type SDC Backend requests on the Component.<br> - * @author ms172g + * Represents The change type SDC Backend requests on the Component.<br> * + * @author ms172g */ -public enum ChangeTypeEnum { - LIFECYCLE, DELETE, ARCHIVE, RESTORE -}
\ No newline at end of file +public enum ChangeTypeEnum { + LIFECYCLE, DELETE, ARCHIVE, RESTORE +} diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/enums/ResultStatusEnum.java b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/enums/ResultStatusEnum.java index 53a242380c..925bd47b8d 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/enums/ResultStatusEnum.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/enums/ResultStatusEnum.java @@ -17,14 +17,13 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.be.catalog.enums; /** * Simple Status Enum - * @author ms172g * + * @author ms172g */ public enum ResultStatusEnum { - SUCCESS, FAIL , SERVICE_DISABLED -}
\ No newline at end of file + SUCCESS, FAIL, SERVICE_DISABLED +} diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/impl/ComponentMessage.java b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/impl/ComponentMessage.java index 82b646714e..69a04e1df5 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/impl/ComponentMessage.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/impl/ComponentMessage.java @@ -17,10 +17,10 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.be.catalog.impl; import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; import org.openecomp.sdc.be.catalog.api.IComponentMessage; import org.openecomp.sdc.be.catalog.enums.ChangeTypeEnum; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; @@ -32,120 +32,116 @@ import org.openecomp.sdc.be.model.catalog.CatalogComponent; import org.openecomp.sdc.be.model.category.CategoryDefinition; import org.openecomp.sdc.be.model.category.SubCategoryDefinition; -import java.util.List; - public class ComponentMessage extends CatalogComponent implements IComponentMessage { - /** - * - */ - private static final long serialVersionUID = 3233307722573636520L; - @JsonProperty("changeTypeEnum") - ChangeTypeEnum changeTypeEnum; - @JsonProperty("catalogUpdateTimestamp") - private CatalogUpdateTimestamp catalogUpdateTimestamp; - private Boolean isArchived; - - public ComponentMessage(Component component, ChangeTypeEnum changeTypeEnum, - CatalogUpdateTimestamp catalogUpdateTimestamp) { - super(); - - this.changeTypeEnum = changeTypeEnum; - this.catalogUpdateTimestamp = catalogUpdateTimestamp; - - setUniqueId(component.getUniqueId());// uniqueId - setUuid(component.getUUID()); // uuid - setInvariantUUID(component.getInvariantUUID()); // invariantUUID - - // View Fields - setName(component.getName()); // name - setSystemName(component.getSystemName()); // systemName - - setVersion(component.getVersion());// version - setLifecycleState(component.getLifecycleState() - .name()); // lifecycleState - setIcon(component.getIcon()); // icon - - ComponentTypeEnum componentType = component.getComponentType(); - setComponentType(componentType);// componentType - - buildCategories(component.getCategories()); // categoryNormalizedName, - // subCategoryNormalizedName - if (componentType == ComponentTypeEnum.SERVICE) { - Service service = (Service) component; - setDistributionStatus(service.getDistributionStatus() - .name()); // distributionStatus - } else { - Resource r = (Resource) component; - this.setResourceType(r.getResourceType() - .name()); // resourceType - } - setIsArchived(component.isArchived()); // isArchived - setIsHighestVersion(component.isHighestVersion()); // isHighestVersion - setDescription(component.getDescription()); // description - if (component.getTags() != null) { - setTags(component.getTags()); // tags - } - setLastUpdateDate(component.getLastUpdateDate());// lastUpdateDate - setLastUpdaterUserId(component.getLastUpdaterUserId()); - } - - private void buildCategories(List<CategoryDefinition> categories) { - if (categories != null) { - setCategories(categories); - CategoryDefinition categoryDefinition = categories.get(0); - - if (categoryDefinition != null) { - setCategoryNormalizedName(categoryDefinition.getName()); - List<SubCategoryDefinition> subcategories = categoryDefinition.getSubcategories(); - if (null != subcategories) { - SubCategoryDefinition subCategoryDefinition = subcategories.get(0); - - if (subCategoryDefinition != null) { - setSubCategoryNormalizedName(subCategoryDefinition.getName()); - } - } - } - } - } - - @Override - public ChangeTypeEnum getChangeType() { - return changeTypeEnum; - } - - @Override - public CatalogUpdateTimestamp getCatalogUpdateTimestamp() { - return catalogUpdateTimestamp; - } - - @Override - public String toString() { - return "ComponentMessage [ getChangeType()=" + getChangeType() + ", getCatalogUpdateTimestamp()=" - + getCatalogUpdateTimestamp() + ", getIsArchived()=" + getIsArchived() + ", getUuid()=" + getUuid() - + ", getInvariantUUID()=" + getInvariantUUID() + ", getSystemName()=" + getSystemName() - + ", getDescription()=" + getDescription() + ", getIsHighestVersion()=" + getIsHighestVersion() - + ", getCategoryNormalizedName()=" + getCategoryNormalizedName() + ", getSubCategoryNormalizedName()=" - + getSubCategoryNormalizedName() + ", getResourceType()=" + getResourceType() + ", getName()=" - + getName() + ", getLastUpdateDate()=" + getLastUpdateDate() + ", getVersion()=" + getVersion() - + ", getComponentType()=" + getComponentType() + ", getIcon()=" + getIcon() + ", getUniqueId()=" - + getUniqueId() + ", getLifecycleState()=" + getLifecycleState() + ", getDistributionStatus()=" - + getDistributionStatus() + ", getTags()=" + getTags() + ", getCategories()=" + getCategories() - + ", getClass()=" + getClass() + ", hashCode()=" + hashCode() + ", toString()=" + super.toString() - + "]"; - } - - public Boolean getIsArchived() { - return isArchived; - } - - public void setIsArchived(Boolean isArchived) { - this.isArchived = isArchived; - } + /** + * + */ + private static final long serialVersionUID = 3233307722573636520L; + @JsonProperty("changeTypeEnum") + ChangeTypeEnum changeTypeEnum; + @JsonProperty("catalogUpdateTimestamp") + private CatalogUpdateTimestamp catalogUpdateTimestamp; + private Boolean isArchived; + + public ComponentMessage(Component component, ChangeTypeEnum changeTypeEnum, CatalogUpdateTimestamp catalogUpdateTimestamp) { + super(); + this.changeTypeEnum = changeTypeEnum; + this.catalogUpdateTimestamp = catalogUpdateTimestamp; + setUniqueId(component.getUniqueId());// uniqueId + + setUuid(component.getUUID()); // uuid + + setInvariantUUID(component.getInvariantUUID()); // invariantUUID + + // View Fields + + setName(component.getName()); // name + + setSystemName(component.getSystemName()); // systemName + + setVersion(component.getVersion());// version + setLifecycleState(component.getLifecycleState() + .name()); // lifecycleState + + setIcon(component.getIcon()); // icon + ComponentTypeEnum componentType = component.getComponentType(); + setComponentType(componentType);// componentType + + buildCategories(component.getCategories()); // categoryNormalizedName, + + // subCategoryNormalizedName + if (componentType == ComponentTypeEnum.SERVICE) { + Service service = (Service) component; + setDistributionStatus(service.getDistributionStatus() + .name()); // distributionStatus + } else { + Resource r = (Resource) component; + this.setResourceType(r.getResourceType() + .name()); // resourceType + } + setIsArchived(component.isArchived()); // isArchived + + setIsHighestVersion(component.isHighestVersion()); // isHighestVersion + + setDescription(component.getDescription()); // description + if (component.getTags() != null) { + setTags(component.getTags()); // tags + } + setLastUpdateDate(component.getLastUpdateDate());// lastUpdateDate + setLastUpdaterUserId(component.getLastUpdaterUserId()); + } + + private void buildCategories(List<CategoryDefinition> categories) { + if (categories != null) { + setCategories(categories); + CategoryDefinition categoryDefinition = categories.get(0); + if (categoryDefinition != null) { + setCategoryNormalizedName(categoryDefinition.getName()); + List<SubCategoryDefinition> subcategories = categoryDefinition.getSubcategories(); + if (null != subcategories) { + SubCategoryDefinition subCategoryDefinition = subcategories.get(0); + if (subCategoryDefinition != null) { + setSubCategoryNormalizedName(subCategoryDefinition.getName()); + } + } + } + } + } + + @Override + public ChangeTypeEnum getChangeType() { + return changeTypeEnum; + } + + @Override + public CatalogUpdateTimestamp getCatalogUpdateTimestamp() { + return catalogUpdateTimestamp; + } + + @Override + public String toString() { + return "ComponentMessage [ getChangeType()=" + getChangeType() + ", getCatalogUpdateTimestamp()=" + getCatalogUpdateTimestamp() + + ", getIsArchived()=" + getIsArchived() + ", getUuid()=" + getUuid() + ", getInvariantUUID()=" + getInvariantUUID() + + ", getSystemName()=" + getSystemName() + ", getDescription()=" + getDescription() + ", getIsHighestVersion()=" + getIsHighestVersion() + + ", getCategoryNormalizedName()=" + getCategoryNormalizedName() + ", getSubCategoryNormalizedName()=" + getSubCategoryNormalizedName() + + ", getResourceType()=" + getResourceType() + ", getName()=" + getName() + ", getLastUpdateDate()=" + getLastUpdateDate() + + ", getVersion()=" + getVersion() + ", getComponentType()=" + getComponentType() + ", getIcon()=" + getIcon() + ", getUniqueId()=" + + getUniqueId() + ", getLifecycleState()=" + getLifecycleState() + ", getDistributionStatus()=" + getDistributionStatus() + ", getTags()=" + + getTags() + ", getCategories()=" + getCategories() + ", getClass()=" + getClass() + ", hashCode()=" + hashCode() + ", toString()=" + + super.toString() + "]"; + } + + public Boolean getIsArchived() { + return isArchived; + } + + public void setIsArchived(Boolean isArchived) { + this.isArchived = isArchived; + } @Override public String getMessageType() { return getClass().getSimpleName(); } - } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/impl/DmaapProducer.java b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/impl/DmaapProducer.java index a442481258..855ef64d9c 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/impl/DmaapProducer.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/impl/DmaapProducer.java @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.be.catalog.impl; import com.att.nsa.mr.client.MRBatchingPublisher; @@ -45,8 +44,7 @@ public class DmaapProducer implements IMessageQueueHandlerProducer { private final ConfigurationManager configurationManager = ConfigurationManager.getConfigurationManager(); private MRBatchingPublisher publisher; - public DmaapProducer(final DmaapClientFactory dmaapClientFactory, - final DmaapProducerHealth dmaapHealth) { + public DmaapProducer(final DmaapClientFactory dmaapClientFactory, final DmaapProducerHealth dmaapHealth) { this.dmaapClientFactory = dmaapClientFactory; this.dmaapHealth = dmaapHealth; } @@ -54,18 +52,15 @@ public class DmaapProducer implements IMessageQueueHandlerProducer { @Override public IStatus pushMessage(ITypeMessage message) { try { - DmaapProducerConfiguration producerConfiguration = configurationManager.getConfiguration() - .getDmaapProducerConfiguration(); + DmaapProducerConfiguration producerConfiguration = configurationManager.getConfiguration().getDmaapProducerConfiguration(); if (!producerConfiguration.getActive()) { - LOG.info( - "[Microservice DMAAP] producer is disabled [re-enable in configuration->isActive],message not sent."); + LOG.info("[Microservice DMAAP] producer is disabled [re-enable in configuration->isActive],message not sent."); dmaapHealth.report(false); return IStatus.getServiceDisabled(); } if (publisher == null) { IStatus initStatus = init(); if (initStatus.getResultStatus() != ResultStatusEnum.SUCCESS) { - return initStatus; } } @@ -73,23 +68,17 @@ public class DmaapProducer implements IMessageQueueHandlerProducer { String jsonInString = mapper.writeValueAsString(message); if (publisher != null) { LOG.info("before send message . response {}", jsonInString); - - LOG.invoke("Dmaap Producer", "DmaapProducer-pushMessage", DmaapProducer.class.getName(), - message.toString()); - + LOG.invoke("Dmaap Producer", "DmaapProducer-pushMessage", DmaapProducer.class.getName(), message.toString()); int pendingMsg = publisher.send(jsonInString); LOG.info("sent message . response {}", pendingMsg); - LOG.invokeReturn(producerConfiguration.getConsumerId(), "Dmaap Producer", - StatusCode.COMPLETE.getStatusCode(), "DmaapProducer-pushMessage", message.toString(), pendingMsg); - + LOG.invokeReturn(producerConfiguration.getConsumerId(), "Dmaap Producer", StatusCode.COMPLETE.getStatusCode(), + "DmaapProducer-pushMessage", message.toString(), pendingMsg); } - dmaapHealth.report(true); } catch (Exception e) { LOG.error(EcompLoggerErrorCode.BUSINESS_PROCESS_ERROR, "Failed to send message . Exception {}", e.getMessage()); return IStatus.getFailStatus(); } - return IStatus.getSuccessStatus(); } @@ -97,8 +86,7 @@ public class DmaapProducer implements IMessageQueueHandlerProducer { @Override public IStatus init() { LOG.debug("MessageQueueHandlerProducer:: Start initializing"); - DmaapProducerConfiguration configuration = configurationManager.getConfiguration() - .getDmaapProducerConfiguration(); + DmaapProducerConfiguration configuration = configurationManager.getConfiguration().getDmaapProducerConfiguration(); if (configuration.getActive()) { try { publisher = dmaapClientFactory.createProducer(configuration); @@ -107,7 +95,6 @@ public class DmaapProducer implements IMessageQueueHandlerProducer { dmaapHealth.report(false); return IStatus.getFailStatus(); } - } catch (Exception e) { LOG.error("Failed to connect to topic . Exeption {}", e.getMessage()); dmaapHealth.report(false); @@ -130,9 +117,6 @@ public class DmaapProducer implements IMessageQueueHandlerProducer { } } catch (Exception e) { LOG.error("Failed to close messageQ . Exeption {}", e.getMessage()); - } - } - } diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/impl/DmaapProducerHealth.java b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/impl/DmaapProducerHealth.java index b62df86b4b..4000be39b3 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/impl/DmaapProducerHealth.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/catalog/impl/DmaapProducerHealth.java @@ -17,9 +17,15 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.be.catalog.impl; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; import org.openecomp.sdc.be.config.BeEcompErrorManager; import org.openecomp.sdc.be.config.ConfigurationManager; import org.openecomp.sdc.be.config.DmaapProducerConfiguration; @@ -28,75 +34,37 @@ import org.openecomp.sdc.common.api.HealthCheckInfo; import org.openecomp.sdc.common.log.wrappers.Logger; import org.springframework.stereotype.Component; -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; - @Component("dmaapProducerHealth") public class DmaapProducerHealth { - private static final String DMAAP_HEALTH_LOG_CONTEXT = "dmaapProducer.healthcheck"; private static final String DMAAP_HEALTH_CHECK_STR = "dmaapProducerHealthCheck"; private static final Logger log = Logger.getLogger(DmaapProducerHealth.class.getName()); private static final Logger logHealth = Logger.getLogger(DMAAP_HEALTH_LOG_CONTEXT); + private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); private HealthCheckInfo healthCheckInfo = DmaapProducerHealth.HealthCheckInfoResult.UNAVAILABLE.getHealthCheckInfo(); private long healthCheckReadTimeout = 20; private long reconnectInterval = 5; - private HealthCheckScheduledTask healthCheckScheduledTask = null ; - private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); + private HealthCheckScheduledTask healthCheckScheduledTask = null; private ScheduledFuture<?> scheduledFuture = null; - private DmaapProducerConfiguration configuration = null ; - + private DmaapProducerConfiguration configuration = null; private volatile AtomicBoolean lastHealthState = new AtomicBoolean(false); private volatile AtomicBoolean reportedHealthState = null; - public enum HealthCheckInfoResult { - OK(new HealthCheckInfo(Constants.HC_COMPONENT_DMAAP_PRODUCER, HealthCheckInfo.HealthCheckStatus.UP, null, DmaapStatusDescription.OK.getDescription())), - UNAVAILABLE(new HealthCheckInfo(Constants.HC_COMPONENT_DMAAP_PRODUCER, HealthCheckInfo.HealthCheckStatus.DOWN, null, DmaapStatusDescription.UNAVAILABLE.getDescription())), - DOWN(new HealthCheckInfo(Constants.HC_COMPONENT_DMAAP_PRODUCER, HealthCheckInfo.HealthCheckStatus.DOWN, null, DmaapStatusDescription.DOWN.getDescription())); - - private HealthCheckInfo healthCheckInfo; - HealthCheckInfoResult(HealthCheckInfo healthCheckInfo) { - this.healthCheckInfo = healthCheckInfo; - } - public HealthCheckInfo getHealthCheckInfo() { - return healthCheckInfo; - } - } - - public enum DmaapStatusDescription { - OK("OK"), UNAVAILABLE("DmaapProducer is not available"),DOWN("DOWN"), NOT_CONFIGURED("DmaapProducer configuration is missing/wrong "); - - private String desc; - DmaapStatusDescription(String desc) { - this.desc = desc; - } - public String getDescription() { - return desc; - } - - } - @PostConstruct public DmaapProducerHealth init() { log.trace("Enter init method of DmaapProducer health"); - synchronized (DmaapProducerHealth.class){ + synchronized (DmaapProducerHealth.class) { this.configuration = ConfigurationManager.getConfigurationManager().getConfiguration().getDmaapProducerConfiguration(); - Integer pollingInterval = configuration.getPollingInterval(); - if (pollingInterval != null && pollingInterval!=0) { + if (pollingInterval != null && pollingInterval != 0) { reconnectInterval = pollingInterval; } Integer healthCheckReadTimeoutConfig = configuration.getTimeoutMs(); if (healthCheckReadTimeoutConfig != null) { this.healthCheckReadTimeout = healthCheckReadTimeoutConfig; } - this.healthCheckScheduledTask = new HealthCheckScheduledTask( configuration ); //what is the representation? csv? delimiter? json or other + this.healthCheckScheduledTask = new HealthCheckScheduledTask(configuration); //what is the representation? csv? delimiter? json or other startHealthCheckTask(true); } log.trace("Exit init method of DistributionEngineClusterHealth"); @@ -120,75 +88,108 @@ public class DmaapProducerHealth { * @param startTask */ private void startHealthCheckTask(boolean startTask) { - synchronized (DmaapProducerHealth.class){ + synchronized (DmaapProducerHealth.class) { if (startTask && this.scheduledFuture == null) { - this.scheduledFuture = this.scheduler.scheduleAtFixedRate(this.healthCheckScheduledTask , 0, reconnectInterval, TimeUnit.SECONDS); + this.scheduledFuture = this.scheduler.scheduleAtFixedRate(this.healthCheckScheduledTask, 0, reconnectInterval, TimeUnit.SECONDS); } } } - void report(Boolean isUp){ - if (reportedHealthState == null) + void report(Boolean isUp) { + if (reportedHealthState == null) { reportedHealthState = new AtomicBoolean(isUp); + } reportedHealthState.set(isUp); } - public HealthCheckInfo getHealthCheckInfo() { return healthCheckInfo; } + public enum HealthCheckInfoResult { + // @formatter:off + OK(new HealthCheckInfo(Constants.HC_COMPONENT_DMAAP_PRODUCER, HealthCheckInfo.HealthCheckStatus.UP, null, DmaapStatusDescription.OK.getDescription())), + UNAVAILABLE(new HealthCheckInfo(Constants.HC_COMPONENT_DMAAP_PRODUCER, HealthCheckInfo.HealthCheckStatus.DOWN, null, DmaapStatusDescription.UNAVAILABLE.getDescription())), + DOWN(new HealthCheckInfo(Constants.HC_COMPONENT_DMAAP_PRODUCER, HealthCheckInfo.HealthCheckStatus.DOWN, null, DmaapStatusDescription.DOWN.getDescription())); + // @formatter:on + + private HealthCheckInfo healthCheckInfo; + + HealthCheckInfoResult(HealthCheckInfo healthCheckInfo) { + this.healthCheckInfo = healthCheckInfo; + } + + public HealthCheckInfo getHealthCheckInfo() { + return healthCheckInfo; + } + } + + public enum DmaapStatusDescription { + // @formatter:off + OK("OK"), + UNAVAILABLE("DmaapProducer is not available"), + DOWN("DOWN"), + NOT_CONFIGURED("DmaapProducer configuration is missing/wrong "); + // @formatter:on + + private String desc; + + DmaapStatusDescription(String desc) { + this.desc = desc; + } + + public String getDescription() { + return desc; + } + + } + /** * Health Check Task Scheduler - infinite check. */ public class HealthCheckScheduledTask implements Runnable { - private final DmaapProducerConfiguration config; + private static final int TIMEOUT = 8192; + private final DmaapProducerConfiguration config; - HealthCheckScheduledTask(final DmaapProducerConfiguration config){ + HealthCheckScheduledTask(final DmaapProducerConfiguration config) { this.config = config; } + @Override public void run() { logHealth.trace("Executing Dmaap Health Check Task - Start"); boolean prevIsReachable; boolean reachable; //first try simple ping - try{ - if ( reportedHealthState != null ){ + try { + if (reportedHealthState != null) { reachable = reportedHealthState.get(); + } else { + reachable = false; } - else{ - reachable = false; - } - prevIsReachable = lastHealthState.getAndSet( reachable ); + prevIsReachable = lastHealthState.getAndSet(reachable); healthCheckInfo = reachable ? HealthCheckInfoResult.OK.healthCheckInfo : HealthCheckInfoResult.DOWN.healthCheckInfo; - } - catch( Exception e ){ - log.debug("{} - cannot check connectivity -> {}",DMAAP_HEALTH_CHECK_STR, e ); + } catch (Exception e) { + log.debug("{} - cannot check connectivity -> {}", DMAAP_HEALTH_CHECK_STR, e); prevIsReachable = lastHealthState.getAndSet(false); healthCheckInfo = HealthCheckInfoResult.UNAVAILABLE.healthCheckInfo; } - if (prevIsReachable != lastHealthState.get()) - logAlarm( lastHealthState.get() ); + if (prevIsReachable != lastHealthState.get()) { + logAlarm(lastHealthState.get()); + } } - - - private void logAlarm(boolean lastHealthState) { - try{ - if ( lastHealthState ) { - BeEcompErrorManager.getInstance().logDmaapHealthCheckRecovery( DMAAP_HEALTH_CHECK_STR ); + try { + if (lastHealthState) { + BeEcompErrorManager.getInstance().logDmaapHealthCheckRecovery(DMAAP_HEALTH_CHECK_STR); } else { - BeEcompErrorManager.getInstance().logDmaapHealthCheckError( DMAAP_HEALTH_CHECK_STR ); + BeEcompErrorManager.getInstance().logDmaapHealthCheckError(DMAAP_HEALTH_CHECK_STR); } - }catch( Exception e ){ - log.debug("cannot logAlarm -> {}" ,e ); + } catch (Exception e) { + log.debug("cannot logAlarm -> {}", e); } } - } - - } |