From 1a19de00a0854540d0ae77c1c909e07ad059d5f4 Mon Sep 17 00:00:00 2001 From: "tjamakeev@optimal-dynamics.com" Date: Sat, 29 Dec 2018 14:25:39 +0600 Subject: [PATCH] #2379 - event pushing - metadata request by type --- .../impl/adapter/BazaaarAdapterImpl.java | 36 ++++++++++- .../api/EnvironmentMetadataManager.java | 7 +-- .../impl/EnvironmentMetadataManagerImpl.java | 30 +++------ .../resources/OSGI-INF/blueprint/context.xml | 4 ++ .../metadata/rest/RestService.java | 9 +-- .../metadata/rest/RestServiceImpl.java | 12 ++-- .../bazaar/share/common/BazaaarAdapter.java | 8 +++ .../bazaar/share/event/meta/OriginMeta.java | 5 +- .../share/event/payload/CustomPayload.java | 2 +- .../bazaar/share/event/payload/Payload.java | 6 +- .../io/subutai/bazaar/share/events/Event.java | 6 -- .../bazaar/share/events/ProgressEvent.java | 61 ------------------- .../bazaar/share/event/EventMessageTest.java | 2 +- 13 files changed, 74 insertions(+), 114 deletions(-) delete mode 100644 management/server/subutai-bazaar-share/src/main/java/io/subutai/bazaar/share/events/Event.java delete mode 100644 management/server/subutai-bazaar-share/src/main/java/io/subutai/bazaar/share/events/ProgressEvent.java diff --git a/management/server/core/bazaar-manager/bazaar-manager-impl/src/main/java/io/subutai/core/bazaarmanager/impl/adapter/BazaaarAdapterImpl.java b/management/server/core/bazaar-manager/bazaar-manager-impl/src/main/java/io/subutai/core/bazaarmanager/impl/adapter/BazaaarAdapterImpl.java index 87a8c2c48c5..b29eaebbe26 100644 --- a/management/server/core/bazaar-manager/bazaar-manager-impl/src/main/java/io/subutai/core/bazaarmanager/impl/adapter/BazaaarAdapterImpl.java +++ b/management/server/core/bazaar-manager/bazaar-manager-impl/src/main/java/io/subutai/core/bazaarmanager/impl/adapter/BazaaarAdapterImpl.java @@ -8,6 +8,8 @@ import org.apache.commons.lang3.StringUtils; +import io.subutai.bazaar.share.common.BazaaarAdapter; +import io.subutai.bazaar.share.event.payload.Payload; import io.subutai.common.dao.DaoManager; import io.subutai.common.environment.Environment; import io.subutai.common.host.ContainerHostInfo; @@ -17,17 +19,16 @@ import io.subutai.common.peer.HostNotFoundException; import io.subutai.common.peer.LocalPeer; import io.subutai.common.util.ServiceLocator; -import io.subutai.core.environment.api.EnvironmentEventListener; -import io.subutai.core.hostregistry.api.HostListener; import io.subutai.core.bazaarmanager.api.BazaarManager; import io.subutai.core.bazaarmanager.api.RestClient; import io.subutai.core.bazaarmanager.api.RestResult; import io.subutai.core.bazaarmanager.api.dao.ConfigDataService; import io.subutai.core.bazaarmanager.impl.dao.ConfigDataServiceImpl; +import io.subutai.core.environment.api.EnvironmentEventListener; +import io.subutai.core.hostregistry.api.HostListener; import io.subutai.core.identity.api.IdentityManager; import io.subutai.core.identity.api.model.User; import io.subutai.core.peer.api.PeerManager; -import io.subutai.bazaar.share.common.BazaaarAdapter; import static java.lang.String.format; @@ -258,6 +259,35 @@ public void notifyContainerDiskUsageExcess( String peerId, String envId, String } + @Override + public void pushEvent( final Payload message ) + { + RestResult result = + getRestClient().post( String.format( "/rest/v1/peers/%s/event", peerId ), message, message.getClass() ); + + if ( !result.isSuccess() ) + { + log.error( "Error pushing event to Bazaar: HTTP {} - {}", result.getStatus(), result.getReasonPhrase() ); + } + } + + + @Override + public Payload getMetaData( final String environmentId, final String type ) + { + RestResult result = getRestClient() + .get( String.format( "/rest/v1/peers/%s/meta/%s/%s", peerId, environmentId, type ), Payload.class ); + + if ( !result.isSuccess() ) + { + log.error( "Error retrieving meta data from Bazaar: HTTP {} - {}", result.getStatus(), + result.getReasonPhrase() ); + } + + return ( Payload ) result.getEntity(); + } + + private void onContainerStateChange( String envId, String contId, String state ) { if ( !isRegistered() ) diff --git a/management/server/core/environment-metadata-manager/environment-metadata-manager-api/src/main/java/io/subutai/core/environment/metadata/api/EnvironmentMetadataManager.java b/management/server/core/environment-metadata-manager/environment-metadata-manager-api/src/main/java/io/subutai/core/environment/metadata/api/EnvironmentMetadataManager.java index 57f4c55df98..0ccbddfbbdc 100644 --- a/management/server/core/environment-metadata-manager/environment-metadata-manager-api/src/main/java/io/subutai/core/environment/metadata/api/EnvironmentMetadataManager.java +++ b/management/server/core/environment-metadata-manager/environment-metadata-manager-api/src/main/java/io/subutai/core/environment/metadata/api/EnvironmentMetadataManager.java @@ -1,8 +1,7 @@ package io.subutai.core.environment.metadata.api; -import io.subutai.bazaar.share.dto.environment.EnvironmentInfoDto; -import io.subutai.bazaar.share.events.Event; +import io.subutai.bazaar.share.event.payload.Payload; import io.subutai.core.identity.api.exception.TokenCreateException; @@ -18,7 +17,7 @@ public interface EnvironmentMetadataManager void issueToken( String containerIp ) throws TokenCreateException; - EnvironmentInfoDto getEnvironmentInfoDto( String environmentId ); + Payload getEnvironmentInfoDto( String environmentId, String type ); - void pushEvent( Event event ); + void pushEvent( Payload eventMessage ); } diff --git a/management/server/core/environment-metadata-manager/environment-metadata-manager-impl/src/main/java/io/subutai/core/environment/metadata/impl/EnvironmentMetadataManagerImpl.java b/management/server/core/environment-metadata-manager/environment-metadata-manager-impl/src/main/java/io/subutai/core/environment/metadata/impl/EnvironmentMetadataManagerImpl.java index 65d06e0e535..322d617ea7e 100644 --- a/management/server/core/environment-metadata-manager/environment-metadata-manager-impl/src/main/java/io/subutai/core/environment/metadata/impl/EnvironmentMetadataManagerImpl.java +++ b/management/server/core/environment-metadata-manager/environment-metadata-manager-impl/src/main/java/io/subutai/core/environment/metadata/impl/EnvironmentMetadataManagerImpl.java @@ -4,12 +4,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import io.subutai.bazaar.share.dto.environment.EnvironmentInfoDto; -import io.subutai.bazaar.share.events.Event; +import io.subutai.bazaar.share.common.BazaaarAdapter; +import io.subutai.bazaar.share.event.payload.Payload; import io.subutai.common.command.CommandException; import io.subutai.common.command.RequestBuilder; -import io.subutai.common.environment.Environment; -import io.subutai.common.environment.EnvironmentNotFoundException; import io.subutai.common.host.SubutaiOrigin; import io.subutai.common.peer.ContainerHost; import io.subutai.common.peer.HostNotFoundException; @@ -29,14 +27,16 @@ public class EnvironmentMetadataManagerImpl implements EnvironmentMetadataManage private final IdentityManager identityManager; private PeerManager peerManager; private EnvironmentManager environmentManager; + private BazaaarAdapter bazaarAdapter; public EnvironmentMetadataManagerImpl( PeerManager peerManager, EnvironmentManager environmentManager, - IdentityManager identityManager ) + IdentityManager identityManager, BazaaarAdapter bazaaarAdapter ) { this.peerManager = peerManager; this.environmentManager = environmentManager; this.identityManager = identityManager; + this.bazaarAdapter = bazaaarAdapter; } @@ -74,27 +74,17 @@ public void issueToken( String containerIp ) throws TokenCreateException @Override - public EnvironmentInfoDto getEnvironmentInfoDto( final String environmentId ) + public Payload getEnvironmentInfoDto( final String environmentId, final String type ) { - final EnvironmentInfoDto result = new EnvironmentInfoDto(); - try - { - Environment environment = environmentManager.loadEnvironment( environmentId ); - result.setName( environment.getName() ); - result.setSubnetCidr( environment.getSubnetCidr() ); - } - catch ( EnvironmentNotFoundException e ) - { - // ignore - } - return result; + return bazaarAdapter.getMetaData( environmentId, type ); } @Override - public void pushEvent( final Event event ) + public void pushEvent( final Payload eventMessage ) { - LOG.debug( "Event received: {}", event ); + LOG.debug( "Event received: {}", eventMessage ); + bazaarAdapter.pushEvent( eventMessage ); } diff --git a/management/server/core/environment-metadata-manager/environment-metadata-manager-impl/src/main/resources/OSGI-INF/blueprint/context.xml b/management/server/core/environment-metadata-manager/environment-metadata-manager-impl/src/main/resources/OSGI-INF/blueprint/context.xml index 6ae1ff8d403..86f51e9106b 100644 --- a/management/server/core/environment-metadata-manager/environment-metadata-manager-impl/src/main/resources/OSGI-INF/blueprint/context.xml +++ b/management/server/core/environment-metadata-manager/environment-metadata-manager-impl/src/main/resources/OSGI-INF/blueprint/context.xml @@ -16,11 +16,15 @@ + + +