diff --git a/features.xml b/features.xml index 026144e38..323064d31 100644 --- a/features.xml +++ b/features.xml @@ -1,7 +1,7 @@ - - - mvn:io.subutai/generic-plugin-api/4.0.0-RC2 - mvn:io.subutai/generic-plugin-impl/4.0.0-RC2 - mvn:io.subutai/generic-plugin-ui/4.0.0-RC2 + + + mvn:io.subutai/generic-plugin-api/4.0.0-RC3 + mvn:io.subutai/generic-plugin-impl/4.0.0-RC3 + mvn:io.subutai/generic-plugin-ui/4.0.0-RC3 diff --git a/generic-plugin-api/pom.xml b/generic-plugin-api/pom.xml index 6bb1a68f8..1d7a44680 100644 --- a/generic-plugin-api/pom.xml +++ b/generic-plugin-api/pom.xml @@ -5,7 +5,7 @@ generic-plugin io.subutai - 4.0.0-RC2 + 4.0.0-RC3 4.0.0 diff --git a/generic-plugin-api/src/main/java/io/subutai/plugin/generic/api/GenericPlugin.java b/generic-plugin-api/src/main/java/io/subutai/plugin/generic/api/GenericPlugin.java index 7489136de..87204e36f 100644 --- a/generic-plugin-api/src/main/java/io/subutai/plugin/generic/api/GenericPlugin.java +++ b/generic-plugin-api/src/main/java/io/subutai/plugin/generic/api/GenericPlugin.java @@ -5,25 +5,24 @@ import io.subutai.common.peer.ContainerHost; import io.subutai.plugin.generic.api.model.Operation; +import io.subutai.plugin.generic.api.model.Profile; public interface GenericPlugin { - public void saveProfile( String profileName ); + void saveProfile (String profileName); - public List getProfiles(); + List getProfiles(); - public void saveOperation( Long profileId, String operationName, String commandName, String cwd, String timeout, - Boolean daemon ); + void saveOperation (Long profileId, String operationName, String commandName, String cwd, String timeout, Boolean daemon); - public List getProfileOperations( Long profileId ); + List getProfileOperations (Long profileId); - public boolean IsOperationRegistered( String operationName ); + boolean IsOperationRegistered (String operationName); - public void updateOperation( final Operation operation, final String commandValue, final String cwdValue, - final String timeoutValue, final Boolean daemonValue ); + void updateOperation (final Operation operation, final String commandValue, final String cwdValue, final String timeoutValue, final Boolean daemonValue); - public void deleteOperation( Long operationId ); + void deleteOperation (Long operationId); - public String executeCommandOnContainer( ContainerHost host, Operation operation ); + String executeCommandOnContainer (ContainerHost host, Operation operation); } diff --git a/generic-plugin-api/src/main/java/io/subutai/plugin/generic/api/dao/ConfigDataService.java b/generic-plugin-api/src/main/java/io/subutai/plugin/generic/api/dao/ConfigDataService.java index 96b825e34..a26141e03 100644 --- a/generic-plugin-api/src/main/java/io/subutai/plugin/generic/api/dao/ConfigDataService.java +++ b/generic-plugin-api/src/main/java/io/subutai/plugin/generic/api/dao/ConfigDataService.java @@ -9,21 +9,19 @@ public interface ConfigDataService { - public void saveProfile( String profileName ); + void saveProfile (String profileName); - public List getAllProfiles(); + List getAllProfiles(); - public void saveOperation( Long profileId, String operationName, String commandName, String cwd, String timeout, - Boolean daemon ); + void saveOperation (Long profileId, String operationName, String commandName, String cwd, String timeout, Boolean daemon); - public List getOperations( Long profileId ); + List getOperations (Long profileId); - public boolean isOperationRegistered( String operationName ); + boolean isOperationRegistered (String operationName); - public Operation getOperationByName( String operationName ); + Operation getOperationByName (String operationName); - public void updateOperation( Operation operation, String commandValue, String cwdValue, String timeoutValue, - Boolean daemonValue ); + void updateOperation (Operation operation, String commandValue, String cwdValue, String timeoutValue, Boolean daemonValue); - public void deleteOperation( Long operationId ); + void deleteOperation (Long operationId); } diff --git a/generic-plugin-api/src/main/java/io/subutai/plugin/generic/api/model/Operation.java b/generic-plugin-api/src/main/java/io/subutai/plugin/generic/api/model/Operation.java index 669e63190..f48c84fb1 100644 --- a/generic-plugin-api/src/main/java/io/subutai/plugin/generic/api/model/Operation.java +++ b/generic-plugin-api/src/main/java/io/subutai/plugin/generic/api/model/Operation.java @@ -3,43 +3,43 @@ public interface Operation { - public String getOperationName(); + String getOperationName(); - public void setOperationName( final String operationName ); + void setOperationName (final String operationName); - public String getCommandName(); + String getCommandName(); - public void setCommandName( final String commandName ); + void setCommandName (final String commandName); - public String getCwd(); + String getCwd(); - public void setCwd( final String cwd ); + void setCwd (final String cwd); - public String getTimeout(); + String getTimeout(); - public void setTimeout( final String timeout ); + void setTimeout (final String timeout); - public Boolean getDaemon(); + Boolean getDaemon(); - public void setDaemon( final Boolean daemon ); + void setDaemon (final Boolean daemon); - public Long getProfileId(); + Long getProfileId(); - public void setProfileId( final Long profileId ); + void setProfileId (final Long profileId); - public Long getOperationId(); + Long getOperationId(); - public void setOperationId( final Long operationId ); + void setOperationId (final Long operationId); } diff --git a/generic-plugin-api/src/main/java/io/subutai/plugin/generic/api/model/Profile.java b/generic-plugin-api/src/main/java/io/subutai/plugin/generic/api/model/Profile.java index a0f6ad932..ba6afd5da 100644 --- a/generic-plugin-api/src/main/java/io/subutai/plugin/generic/api/model/Profile.java +++ b/generic-plugin-api/src/main/java/io/subutai/plugin/generic/api/model/Profile.java @@ -3,11 +3,11 @@ public interface Profile { - public Long getId(); + Long getId(); - public void setId( final Long id ); + void setId (final Long id); - public String getName(); + String getName(); - public void setName( final String name ); + void setName (final String name); } diff --git a/generic-plugin-impl/pom.xml b/generic-plugin-impl/pom.xml index 667a67cc0..ee4ee84e6 100644 --- a/generic-plugin-impl/pom.xml +++ b/generic-plugin-impl/pom.xml @@ -5,7 +5,7 @@ generic-plugin io.subutai - 4.0.0-RC2 + 4.0.0-RC3 4.0.0 @@ -24,7 +24,7 @@ ${project.groupId} generic-plugin-api - 4.0.0-RC2 + 4.0.0-RC3 org.slf4j diff --git a/generic-plugin-impl/src/main/java/io/subutai/plugin/generic/impl/ExecutorManager.java b/generic-plugin-impl/src/main/java/io/subutai/plugin/generic/impl/ExecutorManager.java index f0d9d4378..f3776fd60 100644 --- a/generic-plugin-impl/src/main/java/io/subutai/plugin/generic/impl/ExecutorManager.java +++ b/generic-plugin-impl/src/main/java/io/subutai/plugin/generic/impl/ExecutorManager.java @@ -21,88 +21,79 @@ public class ExecutorManager { - private static final Logger LOG = LoggerFactory.getLogger( ExecutorManager.class.getName() ); - private ExecutorService executor = SubutaiExecutors.newCachedThreadPool(); - private String output; - private ContainerHost containerHost; - private Operation operation; + private static final Logger LOG = LoggerFactory.getLogger (ExecutorManager.class.getName()); + // private ExecutorService executor = SubutaiExecutors.newCachedThreadPool(); + private String output; + private ContainerHost containerHost; + private Operation operation; - public ExecutorManager( final ContainerHost host, final Operation operation ) - { - this.containerHost = host; - this.operation = operation; - } + public ExecutorManager (final ContainerHost host, final Operation operation) + { + this.containerHost = host; + this.operation = operation; + } - public String execute() - { - final RequestBuilder requestBuilder = new RequestBuilder( operation.getCommandName() ); - requestBuilder.withCwd( operation.getCwd() ); - // TODO: timeout cannot be float??? - requestBuilder.withTimeout( Integer.parseInt( operation.getTimeout() ) ); - if ( operation.getDaemon() ) - { - requestBuilder.daemon(); - } -/* executor.execute (new Runnable() - { + public String execute() + { + final RequestBuilder requestBuilder = new RequestBuilder (operation.getCommandName()); + requestBuilder.withCwd (operation.getCwd()); + // TODO: timeout cannot be float??? + requestBuilder.withTimeout (Integer.parseInt (operation.getTimeout())); + if (operation.getDaemon()) + { + requestBuilder.daemon(); + } + /* executor.execute (new Runnable() + { @Override public void run() {*/ - try - { - containerHost.execute( requestBuilder, new CommandCallback() - { - @Override - public void onResponse( Response response, CommandResult commandResult ) - { - StringBuilder out = new StringBuilder(); - if ( !Strings.isNullOrEmpty( response.getStdOut() ) ) - { - out.append( response.getStdOut() ).append( "\n" ); - } - if ( !Strings.isNullOrEmpty( response.getStdErr() ) ) - { - out.append( response.getStdErr() ).append( "\n" ); - } - if ( commandResult.hasCompleted() || commandResult.hasTimedOut() ) - { - if ( response.getType() == ResponseType.EXECUTE_RESPONSE && response.getExitCode() != 0 ) - { - out.append( "Exit code: " ).append( response.getExitCode() ).append( "\n\n" ); - } - else if ( response.getType() != ResponseType.EXECUTE_RESPONSE ) - { - out.append( response.getType() ).append( "\n\n" ); - } - } + try + { + containerHost.execute (requestBuilder, new CommandCallback() + { + @Override + public void onResponse (Response response, CommandResult commandResult) + { + StringBuilder out = new StringBuilder(); + if (!Strings.isNullOrEmpty (response.getStdOut())) + { + out.append (response.getStdOut()).append ("\n"); + } + if (!Strings.isNullOrEmpty (response.getStdErr())) + { + out.append (response.getStdErr()).append ("\n"); + } + if (commandResult.hasCompleted() || commandResult.hasTimedOut()) + { + if (response.getType() == ResponseType.EXECUTE_RESPONSE && response.getExitCode() != 0) + { + out.append ("Exit code: ").append (response.getExitCode()).append ("\n\n"); + } + else if (response.getType() != ResponseType.EXECUTE_RESPONSE) + { + out.append (response.getType()).append ("\n\n"); + } + } - if ( out.length() > 0 ) - { - LOG.info( "out is:\n" + out ); - output = - String.format( "%s [%d]:%n%s", containerHost.getHostname(), response.getPid(), out ); - } - } - } ); - } - catch ( CommandException e ) - { - //LOG.error( "Error in ExecuteCommandTask", e ); - output = e.getMessage() + "\n"; - } - finally - { - //form.taskCount.decrementAndGet(); - //if ( form.taskCount.get() == 0 ) - //{ - // form.indicator.setVisible( false ); - //} - } + if (out.length() > 0) + { + LOG.info ("out is:\n" + out); + output = String.format ("%s [%d]:%n%s", containerHost.getHostname(), response.getPid(), out); + } + } + }); + } + catch (CommandException e) + { + LOG.error ("Error in ExecuteCommandTask", e); + output = e.getMessage() + "\n"; + } /* } });*/ - LOG.info( "Output is:\n" + output ); - return output; - } + LOG.info ("Output is:\n" + output); + return output; + } } diff --git a/generic-plugin-impl/src/main/java/io/subutai/plugin/generic/impl/GenericPluginImpl.java b/generic-plugin-impl/src/main/java/io/subutai/plugin/generic/impl/GenericPluginImpl.java index f075bd0a0..d9df62e77 100644 --- a/generic-plugin-impl/src/main/java/io/subutai/plugin/generic/impl/GenericPluginImpl.java +++ b/generic-plugin-impl/src/main/java/io/subutai/plugin/generic/impl/GenericPluginImpl.java @@ -8,90 +8,87 @@ import io.subutai.plugin.generic.api.GenericPlugin; import io.subutai.plugin.generic.api.dao.ConfigDataService; import io.subutai.plugin.generic.api.model.Operation; +import io.subutai.plugin.generic.api.model.Profile; import io.subutai.plugin.generic.impl.dao.ConfigDataServiceImpl; public class GenericPluginImpl implements GenericPlugin { - private DaoManager daoManager; - private ConfigDataService configDataService; - private ConfigManager configManager; + private DaoManager daoManager; + private ConfigDataService configDataService; - public GenericPluginImpl( final DaoManager daoManager ) - { - this.daoManager = daoManager; - } + public GenericPluginImpl (final DaoManager daoManager) + { + this.daoManager = daoManager; + } - public void init() - { - configDataService = new ConfigDataServiceImpl( daoManager ); - configManager = new ConfigManager(); - } + public void init() + { + configDataService = new ConfigDataServiceImpl (daoManager); + } - @Override - public void saveProfile( final String profileName ) - { - configDataService.saveProfile( profileName ); - } + @Override + public void saveProfile (final String profileName) + { + configDataService.saveProfile (profileName); + } - @Override - public List getProfiles() - { - return configDataService.getAllProfiles(); - } + @Override + public List getProfiles() + { + return configDataService.getAllProfiles(); + } - @Override - public void saveOperation( final Long profileId, final String operationName, final String commandName, - final String cwd, final String timeout, final Boolean daemon ) - { - configDataService.saveOperation( profileId, operationName, commandName, cwd, timeout, daemon ); - } + @Override + public void saveOperation (final Long profileId, final String operationName, final String commandName, final String cwd, final String timeout, final Boolean daemon) + { + configDataService.saveOperation (profileId, operationName, commandName, cwd, timeout, daemon); + } - @Override - public List getProfileOperations( final Long profileId ) - { - return configDataService.getOperations( profileId ); - } + @Override + public List getProfileOperations (final Long profileId) + { + return configDataService.getOperations (profileId); + } - @Override - public boolean IsOperationRegistered( final String operationName ) - { - return configDataService.isOperationRegistered( operationName ); - } + @Override + public boolean IsOperationRegistered (final String operationName) + { + return configDataService.isOperationRegistered (operationName); + } - @Override - public void updateOperation( final Operation operation, final String commandValue, final String cwdValue, - final String timeoutValue, final Boolean daemonValue ) - { - configDataService.updateOperation( operation, commandValue, cwdValue, timeoutValue, daemonValue ); - } + @Override + public void updateOperation (final Operation operation, final String commandValue, final String cwdValue, final String timeoutValue, final Boolean daemonValue) + { + configDataService.updateOperation (operation, commandValue, cwdValue, timeoutValue, daemonValue); + } - @Override - public void deleteOperation( final Long operationId ) - { - configDataService.deleteOperation( operationId ); - } + @Override + public void deleteOperation (final Long operationId) + { + configDataService.deleteOperation (operationId); + } - @Override - public String executeCommandOnContainer( final ContainerHost host, final Operation operation ) - { - ExecutorManager manager = new ExecutorManager( host, operation ); - return manager.execute(); - } + @Override + public String executeCommandOnContainer (final ContainerHost host, final Operation operation) + { + ExecutorManager manager = new ExecutorManager (host, operation); + return manager.execute(); + } - public ConfigDataService getConfigDataService() - { - return configDataService; - } + public ConfigDataService getConfigDataService() + { + return configDataService; + } } diff --git a/generic-plugin-impl/src/main/java/io/subutai/plugin/generic/impl/dao/ConfigDataServiceImpl.java b/generic-plugin-impl/src/main/java/io/subutai/plugin/generic/impl/dao/ConfigDataServiceImpl.java index c30fd7c46..ef0afb633 100644 --- a/generic-plugin-impl/src/main/java/io/subutai/plugin/generic/impl/dao/ConfigDataServiceImpl.java +++ b/generic-plugin-impl/src/main/java/io/subutai/plugin/generic/impl/dao/ConfigDataServiceImpl.java @@ -1,6 +1,5 @@ package io.subutai.plugin.generic.impl.dao; - import java.util.List; import javax.persistence.EntityManager; @@ -21,207 +20,207 @@ public class ConfigDataServiceImpl implements ConfigDataService { - private static final Logger LOG = LoggerFactory.getLogger( ConfigDataServiceImpl.class ); - private DaoManager daoManager; - - - public ConfigDataServiceImpl( final DaoManager daoManager ) - { - this.daoManager = daoManager; - } - - - @Override - public void saveProfile( final String profileName ) - { - Profile profile = new ProfileEntity(); - profile.setName( profileName ); - - EntityManager em = daoManager.getEntityManagerFactory().createEntityManager(); - - try - { - daoManager.startTransaction( em ); - em.merge( profile ); - daoManager.commitTransaction( em ); - } - catch ( Exception ex ) - { - daoManager.rollBackTransaction( em ); - LOG.error( "ConfigDataService saveProfile:" + ex.toString() ); - } - finally - { - daoManager.closeEntityManager( em ); - } - } - - - @Override - public List getAllProfiles() - { - List result = Lists.newArrayList(); - - EntityManager em = daoManager.getEntityManagerFromFactory(); - try - { - result = ( List ) em.createQuery( "select h from ProfileEntity h" ).getResultList(); - } - catch ( Exception e ) - { - LOG.error( e.toString(), e ); - } - finally - { - daoManager.closeEntityManager( em ); - } - return result; - } - - - @Override - public void saveOperation( final Long profileId, final String operationName, final String commandName, - final String cwd, final String timeout, final Boolean daemon ) - { - Operation operation = new OperationEntity(); - operation.setProfileId( profileId ); - operation.setOperationName( operationName ); - operation.setCommandName( commandName ); - operation.setCwd( cwd ); - operation.setTimeout( timeout ); - operation.setDaemon( daemon ); - - EntityManager em = daoManager.getEntityManagerFactory().createEntityManager(); - - try - { - daoManager.startTransaction( em ); - em.merge( operation ); - daoManager.commitTransaction( em ); - } - catch ( Exception ex ) - { - daoManager.rollBackTransaction( em ); - LOG.error( "ConfigDataService saveOperation:" + ex.toString() ); - } - finally - { - daoManager.closeEntityManager( em ); - } - } - - - @Override - public List getOperations( final Long profileId ) - { - List result = Lists.newArrayList(); - - EntityManager em = daoManager.getEntityManagerFromFactory(); - Query query = null; - try - { -// result = ( List ) em.createQuery( "select h from OperationEntity h where h.profileId = :profileId" ).getResultList(); - query = em.createQuery( "select h from OperationEntity h where h.profileId = :profileId" ); - query.setParameter( "profileId", profileId ); - result = ( List ) query.getResultList(); - } - catch ( Exception e ) - { - LOG.error( e.toString(), e ); - } - finally - { - daoManager.closeEntityManager( em ); - } - return result; - } - - - @Override - public boolean isOperationRegistered( final String operationName ) - { - if ( getOperationByName( operationName ) == null ) - { - return false; - } - else - { - return true; - } - } - - - @Override - public Operation getOperationByName( final String operationName ) - { - EntityManager em = daoManager.getEntityManagerFromFactory(); - Query query = null; - try - { - query = em.createQuery( "select e from OperationEntity e where e.operationName = :operationName" ); - query.setParameter( "operationName", operationName ); - return ( Operation ) query.getSingleResult(); - } - catch ( Exception e ) - { - daoManager.closeEntityManager( em ); - return null; - } - } - - - @Override - public void updateOperation( final Operation operation, final String commandValue, final String cwdValue, - final String timeoutValue, final Boolean daemonValue ) - { - EntityManager em = daoManager.getEntityManagerFromFactory(); - - try - { - daoManager.startTransaction( em ); - OperationEntity entity = em.find( OperationEntity.class, operation.getOperationId() ); - entity.setCommandName( commandValue ); - entity.setCwd( commandValue ); - entity.setTimeout( timeoutValue ); - entity.setDaemon( daemonValue ); - em.merge( entity ); - em.flush(); - daoManager.commitTransaction( em ); - } - catch ( Exception ex ) - { - daoManager.rollBackTransaction( em ); - LOG.error( "ConfigDataService updateOperation:" + ex.toString() ); - } - finally - { - daoManager.closeEntityManager( em ); - } - } - - - @Override - public void deleteOperation( final Long operationId ) - { - EntityManager em = daoManager.getEntityManagerFromFactory(); - - try - { - daoManager.startTransaction( em ); - OperationEntity entity = em.find( OperationEntity.class, operationId ); - em.remove( entity ); - em.flush(); - daoManager.commitTransaction( em ); - } - catch ( Exception ex ) - { - daoManager.rollBackTransaction( em ); - LOG.error( "ConfigDataService deleteOperation:" + ex.toString() ); - } - finally - { - daoManager.closeEntityManager( em ); - } - - } + private static final Logger LOG = LoggerFactory.getLogger (ConfigDataServiceImpl.class); + private DaoManager daoManager; + + + public ConfigDataServiceImpl (final DaoManager daoManager) + { + this.daoManager = daoManager; + } + + + @Override + public void saveProfile (final String profileName) + { + Profile profile = new ProfileEntity(); + profile.setName(profileName); + + EntityManager em = daoManager.getEntityManagerFactory().createEntityManager(); + + try + { + daoManager.startTransaction (em); + em.merge (profile); + daoManager.commitTransaction (em); + } + catch (Exception e) + { + daoManager.rollBackTransaction (em); + LOG.error ("ConfigDataService saveProfile:" + e.toString()); + } + finally + { + daoManager.closeEntityManager (em); + } + } + + + + + @Override + public List getAllProfiles() + { + List result = Lists.newArrayList(); + + EntityManager em = daoManager.getEntityManagerFromFactory(); + try + { + result = (List) em.createQuery ("select h from ProfileEntity h").getResultList(); + } + catch (Exception e) + { + LOG.error (e.toString(), e); + } + finally + { + daoManager.closeEntityManager (em); + } + return result; + } + + + @Override + public void saveOperation (final Long profileId, final String operationName, final String commandName, final String cwd, final String timeout, final Boolean daemon) + { + Operation operation = new OperationEntity(); + operation.setProfileId (profileId); + operation.setOperationName (operationName); + operation.setCommandName (commandName); + operation.setCwd (cwd); + operation.setTimeout (timeout); + operation.setDaemon (daemon); + + EntityManager em = daoManager.getEntityManagerFactory().createEntityManager(); + + try + { + daoManager.startTransaction (em); + em.merge (operation); + daoManager.commitTransaction (em); + } + catch (Exception ex) + { + daoManager.rollBackTransaction (em); + LOG.error ("ConfigDataService saveOperation:" + ex.toString()); + } + finally + { + daoManager.closeEntityManager (em); + } + } + + + @Override + public List getOperations (final Long profileId) + { + List result = Lists.newArrayList(); + + EntityManager em = daoManager.getEntityManagerFromFactory(); + Query query; + try + { + // result = (List ) em.createQuery ("select h from OperationEntity h where h.profileId = :profileId").getResultList(); + query = em.createQuery ("select h from OperationEntity h where h.profileId = :profileId"); + query.setParameter ("profileId", profileId); + result = (List) query.getResultList(); + } + catch (Exception e) + { + LOG.error (e.toString(), e); + } + finally + { + daoManager.closeEntityManager (em); + } + return result; + } + + + @Override + public boolean isOperationRegistered (final String operationName) + { + if (getOperationByName (operationName) == null) + { + return false; + } + else + { + return true; + } + } + + + @Override + public Operation getOperationByName (final String operationName) + { + EntityManager em = daoManager.getEntityManagerFromFactory(); + Query query; + try + { + query = em.createQuery ("select e from OperationEntity e where e.operationName = :operationName"); + query.setParameter ("operationName", operationName); + return (Operation) query.getSingleResult(); + } + catch (Exception e) + { + daoManager.closeEntityManager (em); + return null; + } + } + + + @Override + public void updateOperation (final Operation operation, final String commandValue, final String cwdValue, final String timeoutValue, final Boolean daemonValue) + { + EntityManager em = daoManager.getEntityManagerFromFactory(); + + try + { + daoManager.startTransaction (em); + OperationEntity entity = em.find (OperationEntity.class, operation.getOperationId()); + entity.setCommandName (commandValue); + entity.setCwd (commandValue); + entity.setTimeout (timeoutValue); + entity.setDaemon (daemonValue); + em.merge (entity); + em.flush(); + daoManager.commitTransaction (em); + } + catch (Exception ex) + { + daoManager.rollBackTransaction (em); + LOG.error ("ConfigDataService updateOperation:" + ex.toString()); + } + finally + { + daoManager.closeEntityManager (em); + } + } + + + @Override + public void deleteOperation( final Long operationId ) + { + EntityManager em = daoManager.getEntityManagerFromFactory(); + + try + { + daoManager.startTransaction (em); + OperationEntity entity = em.find (OperationEntity.class, operationId); + em.remove (entity); + em.flush(); + daoManager.commitTransaction (em); + } + catch (Exception ex) + { + daoManager.rollBackTransaction (em); + LOG.error ("ConfigDataService deleteOperation:" + ex.toString()); + } + finally + { + daoManager.closeEntityManager (em); + } + + } } diff --git a/generic-plugin-impl/src/main/java/io/subutai/plugin/generic/impl/model/OperationEntity.java b/generic-plugin-impl/src/main/java/io/subutai/plugin/generic/impl/model/OperationEntity.java index c0602b47e..b127dfeaf 100644 --- a/generic-plugin-impl/src/main/java/io/subutai/plugin/generic/impl/model/OperationEntity.java +++ b/generic-plugin-impl/src/main/java/io/subutai/plugin/generic/impl/model/OperationEntity.java @@ -13,113 +13,113 @@ @Entity -@Table( name = "plugin_operation" ) -@Access( AccessType.FIELD ) +@Table (name = "plugin_operation") +@Access (AccessType.FIELD) public class OperationEntity implements Operation { - @Id - @Column( name = "operation_id" ) - @GeneratedValue - private Long operationId; + @Id + @Column (name = "operation_id") + @GeneratedValue + private Long operationId; - @Column( name = "profile_id" ) - private Long profileId; + @Column (name = "profile_id") + private Long profileId; - @Column( name = "operation_name" ) - private String operationName; + @Column (name = "operation_name") + private String operationName; - @Column( name = "command_name" ) - private String commandName; + @Column (name = "command_name") + private String commandName; - @Column( name = "cwd" ) - private String cwd; + @Column (name = "cwd") + private String cwd; - @Column( name = "timeout" ) - private String timeout; + @Column (name = "timeout") + private String timeout; - @Column( name = "daemon" ) - private Boolean daemon; + @Column (name = "daemon") + private Boolean daemon; - public String getOperationName() - { - return operationName; - } + public String getOperationName() + { + return operationName; + } - public void setOperationName( final String operationName ) - { - this.operationName = operationName; - } + public void setOperationName (final String operationName) + { + this.operationName = operationName; + } - public String getCommandName() - { - return commandName; - } + public String getCommandName() + { + return commandName; + } - public void setCommandName( final String commandName ) - { - this.commandName = commandName; - } + public void setCommandName (final String commandName) + { + this.commandName = commandName; + } - public String getCwd() - { - return cwd; - } + public String getCwd() + { + return cwd; + } - public void setCwd( final String cwd ) - { - this.cwd = cwd; - } + public void setCwd (final String cwd) + { + this.cwd = cwd; + } - public String getTimeout() - { - return timeout; - } + public String getTimeout() + { + return timeout; + } - public void setTimeout( final String timeout ) - { - this.timeout = timeout; - } + public void setTimeout (final String timeout) + { + this.timeout = timeout; + } - public Boolean getDaemon() - { - return daemon; - } + public Boolean getDaemon() + { + return daemon; + } - public void setDaemon( final Boolean daemon ) - { - this.daemon = daemon; - } + public void setDaemon (final Boolean daemon) + { + this.daemon = daemon; + } - public Long getProfileId() - { - return profileId; - } + public Long getProfileId() + { + return profileId; + } - public void setProfileId( final Long profileId ) - { - this.profileId = profileId; - } + public void setProfileId (final Long profileId) + { + this.profileId = profileId; + } - public Long getOperationId() - { - return operationId; - } + public Long getOperationId() + { + return operationId; + } - public void setOperationId( final Long operationId ) - { - this.operationId = operationId; - } + public void setOperationId (final Long operationId) + { + this.operationId = operationId; + } } diff --git a/generic-plugin-impl/src/main/java/io/subutai/plugin/generic/impl/model/ProfileEntity.java b/generic-plugin-impl/src/main/java/io/subutai/plugin/generic/impl/model/ProfileEntity.java index b27a3ee97..f4c5b8475 100644 --- a/generic-plugin-impl/src/main/java/io/subutai/plugin/generic/impl/model/ProfileEntity.java +++ b/generic-plugin-impl/src/main/java/io/subutai/plugin/generic/impl/model/ProfileEntity.java @@ -14,39 +14,39 @@ @Entity -@Table( name = "plugin_profile" ) -@Access( AccessType.FIELD ) +@Table (name = "plugin_profile") +@Access (AccessType.FIELD) public class ProfileEntity implements Profile { - @Id - @Column( name = "id" ) - @GeneratedValue( strategy = GenerationType.IDENTITY ) - private Long id; + @Id + @Column (name = "id") + @GeneratedValue (strategy = GenerationType.IDENTITY) + private Long id; - @Column( name = "name", unique = true ) - private String name; + @Column (name = "name", unique = true) + private String name; - public Long getId() - { - return id; - } + public Long getId() + { + return id; + } - public void setId( final Long id ) - { - this.id = id; - } + public void setId (final Long id) + { + this.id = id; + } - public String getName() - { - return name; - } + public String getName() + { + return name; + } - public void setName( final String name ) - { - this.name = name; - } + public void setName (final String name) + { + this.name = name; + } } diff --git a/generic-plugin-kar/pom.xml b/generic-plugin-kar/pom.xml index b16799376..a30dce0c0 100644 --- a/generic-plugin-kar/pom.xml +++ b/generic-plugin-kar/pom.xml @@ -5,7 +5,7 @@ generic-plugin io.subutai - 4.0.0-RC2 + 4.0.0-RC3 4.0.0 diff --git a/generic-plugin-ui/pom.xml b/generic-plugin-ui/pom.xml index 4a8919243..08b117d2e 100644 --- a/generic-plugin-ui/pom.xml +++ b/generic-plugin-ui/pom.xml @@ -5,7 +5,7 @@ generic-plugin io.subutai - 4.0.0-RC2 + 4.0.0-RC3 4.0.0 @@ -29,42 +29,42 @@ vaadin-custom - - - - - + + com.vaadin + vaadin-server + 7.5.8 + ${project.groupId} generic-plugin-api - 4.0.0-RC2 + 4.0.0-RC3 + + + com.vaadin + vaadin-theme-compiler + 7.1.15 + + + com.vaadin + vaadin-sass-compiler + 0.9.12 + + + com.vaadin + vaadin-push + 7.5.8 + + + com.vaadin + vaadin-themes + 7.5.8 + + + com.vaadin + vaadin-client-compiler + 7.5.8 + provided - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/GenericPluginComponent.java b/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/GenericPluginComponent.java index cee9bb35d..06e8ac4d4 100644 --- a/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/GenericPluginComponent.java +++ b/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/GenericPluginComponent.java @@ -11,15 +11,15 @@ public class GenericPluginComponent extends CustomComponent { - private final Wizard wizard; - public GenericPluginComponent(TemplateRegistry registry, EnvironmentManager manager, GenericPlugin genericPlugin) - { - this.wizard = new Wizard (registry, manager, genericPlugin); - setSizeFull(); - VerticalLayout content = new VerticalLayout(); - content.setSpacing( true ); - content.setSizeFull(); - content.addComponent (this.wizard.getContent()); - setCompositionRoot( content ); - } + private final Wizard wizard; + public GenericPluginComponent (TemplateRegistry registry, EnvironmentManager manager, GenericPlugin genericPlugin) + { + this.wizard = new Wizard (registry, manager, genericPlugin); + setSizeFull(); + VerticalLayout content = new VerticalLayout(); + content.setSpacing (true); + content.setSizeFull(); + content.addComponent (this.wizard.getContent()); + setCompositionRoot (content); + } } diff --git a/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/GenericPluginPortalModule.java b/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/GenericPluginPortalModule.java index 24983d070..6c0d3122e 100644 --- a/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/GenericPluginPortalModule.java +++ b/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/GenericPluginPortalModule.java @@ -14,51 +14,51 @@ public class GenericPluginPortalModule implements PortalModule { - public static final String MODULE_IMAGE = "test.png"; - private static final String NAME = "Generic Plugin"; - private GenericPlugin genericPlugin; + public static final String MODULE_IMAGE = "test.png"; + private static final String NAME = "Generic Plugin"; + private GenericPlugin genericPlugin; private TemplateRegistry registry; private EnvironmentManager manager; - public GenericPluginPortalModule( GenericPlugin genericPlugin, TemplateRegistry registry, EnvironmentManager manager ) - { - this.registry = registry; - this.manager = manager; - this.genericPlugin = genericPlugin; - } + public GenericPluginPortalModule (GenericPlugin genericPlugin, TemplateRegistry registry, EnvironmentManager manager) + { + this.registry = registry; + this.manager = manager; + this.genericPlugin = genericPlugin; + } - @Override - public String getId() - { - return NAME; - } + @Override + public String getId() + { + return NAME; + } - @Override - public String getName() - { - return NAME; - } + @Override + public String getName() + { + return NAME; + } - @Override - public File getImage() - { - return FileUtil.getFile( GenericPluginPortalModule.MODULE_IMAGE, this ); - } + @Override + public File getImage() + { + return FileUtil.getFile (GenericPluginPortalModule.MODULE_IMAGE, this); + } - @Override - public Component createComponent() - { - return new GenericPluginComponent (registry, manager, genericPlugin); - } + @Override + public Component createComponent() + { + return new GenericPluginComponent (registry, manager, genericPlugin); + } - @Override - public Boolean isCorePlugin() - { - return false; - } + @Override + public Boolean isCorePlugin() + { + return false; + } } diff --git a/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/wizard/ConfigureOperationStep.java b/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/wizard/ConfigureOperationStep.java index 0e7462aa1..a05ed8b6b 100644 --- a/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/wizard/ConfigureOperationStep.java +++ b/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/wizard/ConfigureOperationStep.java @@ -1,26 +1,21 @@ package io.subutai.plugin.generic.ui.wizard; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.file.Files; +import java.nio.file.Paths; import java.util.List; +import com.vaadin.ui.*; +import org.apache.commons.io.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.vaadin.data.Property; import com.vaadin.server.Page; -import com.vaadin.ui.Alignment; -import com.vaadin.ui.Button; -import com.vaadin.ui.CheckBox; -import com.vaadin.ui.ComboBox; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Label; -import com.vaadin.ui.Notification; -import com.vaadin.ui.Panel; -import com.vaadin.ui.Table; -import com.vaadin.ui.TextField; -import com.vaadin.ui.UI; -import com.vaadin.ui.VerticalLayout; -import com.vaadin.ui.Window; import io.subutai.plugin.generic.api.GenericPlugin; import io.subutai.plugin.generic.api.model.Operation; @@ -29,504 +24,583 @@ public class ConfigureOperationStep extends Panel { - private static final Logger LOG = LoggerFactory.getLogger( ConfigureOperationStep.class.getName() ); - protected static final String BUTTON_STYLE_NAME = "default"; - private static final String VIEW_BUTTON_CAPTION = "View"; - private static final String EDIT_BUTTON_CAPTION = "Edit"; - private static final String DELETE_BUTTON_CAPTION = "Delete"; - private TextField cwd = new TextField( "cwd" ); - private TextField timeOut = new TextField( "Timeout" ); - private CheckBox daemon = new CheckBox( "Daemon" ); - private Wizard wizard; - - private GenericPlugin genericPlugin; - private VerticalLayout content; - private Label title; - private ComboBox profileSelect; - private HorizontalLayout fieldGrid; - private Profile profile; - - private final Table operationTable; - - - public ConfigureOperationStep( final Wizard wizard, final GenericPlugin genericPlugin ) - { - this.wizard = wizard; - this.genericPlugin = genericPlugin; - - operationTable = createTableTemplate( "Operations" ); - - content = new VerticalLayout(); - title = new Label( "Configure operations" ); - - profileSelect = new ComboBox( "Profile" ); - profileSelect.setNullSelectionAllowed( false ); - profileSelect.setTextInputAllowed( false ); - profileSelect.addValueChangeListener( new Property.ValueChangeListener() - { - @Override - public void valueChange( Property.ValueChangeEvent event ) - { - profile = ( Profile ) event.getProperty().getValue(); - refreshUI(); - } - } ); - refreshProfileInfo(); - - fieldGrid = new HorizontalLayout(); - fieldGrid.setSpacing( true ); - fieldGrid.setWidth( "100%" ); - - final TextField newName = new TextField( "New operation name (maximum 10 characters)" ); - newName.setInputPrompt( "Enter new operation name" ); - newName.setRequired( true ); - - final TextField newCommand = new TextField( "New command" ); - newCommand.setRequired( true ); - newCommand.setInputPrompt( "Enter new command" ); - - // - /*final ComboBox templates = new ComboBox ("Template"); - templates.setNullSelectionAllowed (false); + private static final Logger LOG = LoggerFactory.getLogger (ConfigureOperationStep.class.getName()); + protected static final String BUTTON_STYLE_NAME = "default"; + private TextField cwd = new TextField( "cwd" ); + private TextField timeOut = new TextField( "Timeout" ); + private CheckBox daemon = new CheckBox( "Daemon" ); + + private GenericPlugin genericPlugin; + private VerticalLayout content; + private Label title; + private ComboBox profileSelect; + private HorizontalLayout fieldGrid; + private Profile profile; + + private final Table operationTable; + private TextField newCommand; + private Window uploadWindow; + + + class MyUploader implements Upload.Receiver, Upload.SucceededListener, Upload.FailedListener + { + private File file; + private String path; + + + @Override + public OutputStream receiveUpload (String filename, String MIMEType) + { + FileOutputStream fos; + new File ("/tmp/uploads").mkdirs(); + this.file = new File ("/tmp/uploads/" + filename); + this.path = new String ("/tmp/uploads/" + filename); + try + { + fos = new FileOutputStream (this.file); + } + catch (final java.io.FileNotFoundException e) + { + // Error while opening the file + // TODO: notify that file is not opened + return null; + } + + return fos; + } + + + @Override + public void uploadSucceeded (Upload.SucceededEvent event) + { + try + { + byte[] encoded = Files.readAllBytes (Paths.get (this.path)); + newCommand.setValue (new String (encoded)); + FileUtils.deleteDirectory (new File ("/tmp")); + uploadWindow.close(); + } + catch (IOException e) + { + // TODO: file is not saved + } + + } + + + @Override + public void uploadFailed (Upload.FailedEvent event) + { + // TODO: Log the failure on screen. + } + } + + + public ConfigureOperationStep (final Wizard wizard, final GenericPlugin genericPlugin) + { + this.genericPlugin = genericPlugin; + + operationTable = createTableTemplate ("Operations"); + + content = new VerticalLayout(); + title = new Label ("Configure operations"); + + profileSelect = new ComboBox ("Profile"); + profileSelect.setNullSelectionAllowed (false); + profileSelect.setTextInputAllowed (false); + profileSelect.addValueChangeListener (new Property.ValueChangeListener() + { + @Override + public void valueChange (Property.ValueChangeEvent event) + { + profile = (Profile) event.getProperty().getValue(); + refreshUI(); + } + }); + refreshProfileInfo(); + + fieldGrid = new HorizontalLayout(); + fieldGrid.setSpacing (true); + fieldGrid.setWidth ("100%"); + + final TextField newName = new TextField ("New operation name"); + newName.setInputPrompt ("Enter new operation name"); + newName.setRequired (true); + + newCommand = new TextField ("New command"); + newCommand.setRequired (true); + newCommand.setInputPrompt ("Enter new command"); + + // + /*final ComboBox templates = new ComboBox ("Template"); + templates.setNullSelectionAllowed (false); templates.setTextInputAllowed (false); for (Template t : wizard.getRegistry().getAllTemplates()) { templates.addItem (t.getTemplateName()); } templates.setValue (wizard.getRegistry().getAllTemplates().get (0).getTemplateName());*/ - // - - - cwd.setValue( "/" ); - cwd.setData( "/" ); - timeOut.setValue( "30" ); - timeOut.setData( "30" ); - daemon.setValue( false ); - daemon.setData( false ); - - Button options = new Button( "Options" ); - options.addStyleName( BUTTON_STYLE_NAME ); - - Button addOperation = new Button( "Add operation" ); - addOperation.addStyleName( BUTTON_STYLE_NAME ); - - fieldGrid.addComponent( newName ); - fieldGrid.addComponent( newCommand ); - //fieldGrid.addComponent (templates); - fieldGrid.addComponent( options ); - fieldGrid.addComponent( addOperation ); - fieldGrid.setComponentAlignment( newName, Alignment.BOTTOM_LEFT ); - fieldGrid.setComponentAlignment( newCommand, Alignment.BOTTOM_LEFT ); - //fieldGrid.setComponentAlignment (templates, Alignment.BOTTOM_LEFT); - fieldGrid.setComponentAlignment( options, Alignment.BOTTOM_LEFT ); - fieldGrid.setComponentAlignment( addOperation, Alignment.BOTTOM_LEFT ); - - content.addComponent( title ); - content.addComponent( profileSelect ); - content.addComponent( fieldGrid ); - content.addComponent( operationTable ); - - Button back = new Button( "Back" ); - back.addStyleName( BUTTON_STYLE_NAME ); - back.addClickListener( new Button.ClickListener() - { - @Override - public void buttonClick( final Button.ClickEvent clickEvent ) - { - wizard.changeWindow( 0 ); - wizard.putForm(); - } - } ); - content.addComponent( back ); - - - options.addClickListener( new Button.ClickListener() - { - @Override - public void buttonClick( Button.ClickEvent event ) - { - final Window subWindow = new Window( "Edit operation" ); - subWindow.setClosable( false ); - subWindow.addStyleName( "default" ); - subWindow.center(); - VerticalLayout subContent = new VerticalLayout(); - subContent.setSpacing( true ); - subContent.setMargin( true ); - HorizontalLayout fields = new HorizontalLayout(); - fields.setSpacing( true ); - fields.addComponent( cwd ); - fields.addComponent( timeOut ); - fields.setComponentAlignment( cwd, Alignment.BOTTOM_LEFT ); - fields.setComponentAlignment( timeOut, Alignment.BOTTOM_LEFT ); - - HorizontalLayout buttonGrid = new HorizontalLayout(); - buttonGrid.setSpacing( true ); - - Button back = new Button( "Back" ); - back.setSizeFull(); - back.addClickListener( new Button.ClickListener() - { - @Override - public void buttonClick( Button.ClickEvent event ) - { - cwd.setValue( ( String ) cwd.getData() ); - timeOut.setValue( ( String ) timeOut.getData() ); - daemon.setValue( ( boolean ) daemon.getData() ); - subWindow.close(); - } - } ); - - Button save = new Button( "Save" ); - save.setSizeFull(); - save.addClickListener( new Button.ClickListener() - { - @Override - public void buttonClick( Button.ClickEvent event ) - { - cwd.setData( cwd.getValue() ); - timeOut.setData( timeOut.getValue() ); - daemon.setData( daemon.getValue() ); - subWindow.close(); - } - } ); - - buttonGrid.addComponent( back ); - buttonGrid.addComponent( save ); - buttonGrid.setComponentAlignment( back, Alignment.BOTTOM_CENTER ); - buttonGrid.setComponentAlignment( save, Alignment.BOTTOM_CENTER ); - - subContent.addComponent( fields ); - subContent.addComponent( daemon ); - subContent.addComponent( buttonGrid ); - subContent.setComponentAlignment( daemon, Alignment.BOTTOM_LEFT ); - subContent.setComponentAlignment( buttonGrid, Alignment.BOTTOM_CENTER ); - subWindow.setContent( subContent ); - UI.getCurrent().addWindow( subWindow ); - } - } ); - - - addOperation.addClickListener( new Button.ClickListener() - { - public void buttonClick( final Button.ClickEvent clickEvent ) - { - if ( newName.getValue().isEmpty() ) - { - show( "Please enter operation name" ); - } - else if ( newCommand.getValue().isEmpty() ) - { - show( "Please enter command" ); - } - else if ( profileSelect.getValue() == null ) - { - show( "Please choose profile" ); - } - else - { - Profile current = ( Profile ) profileSelect.getValue(); - if ( genericPlugin.IsOperationRegistered( newName.getValue() ) ) - { - show( "Operation with such name already exist!" ); - } - else - { - genericPlugin.saveOperation( current.getId(), newName.getValue(), newCommand.getValue(), - cwd.getValue(), timeOut.getValue(), daemon.getValue() ); - show( "Operation saved successfully!" ); - refreshUI(); - } - } - } - } ); - this.setContent( content ); - } - - - private Table createTableTemplate( final String caption ) - { - final Table table = new Table( caption ); - table.addContainerProperty( "Operation name", String.class, null ); - table.addContainerProperty( "Command", String.class, null ); - //operationTable.addContainerProperty ("Template", String.class, null); - table.addContainerProperty( "Actions", HorizontalLayout.class, null ); - table.setSizeFull(); - table.setPageLength( 10 ); - table.setSelectable( false ); - table.setImmediate( true ); - - return table; - } - - - private void refreshUI() - { - if ( profile != null ) - { - List operations = genericPlugin.getProfileOperations( profile.getId() ); - populateTable( operationTable, operations ); - } - } - - - private void populateTable( final Table sampleTable, final List operations ) - { - sampleTable.removeAllItems(); - - for ( Operation operation : operations ) - { - final Button viewBtn = new Button( VIEW_BUTTON_CAPTION ); - final Button editBtn = new Button( EDIT_BUTTON_CAPTION ); - final Button deleteBtn = new Button( DELETE_BUTTON_CAPTION ); - - addStyleNameToButtons( viewBtn, editBtn, deleteBtn ); - - final HorizontalLayout availableOperations = new HorizontalLayout(); - availableOperations.addStyleName( "default" ); - availableOperations.setSpacing( true ); - - addGivenComponents( availableOperations, viewBtn, editBtn, deleteBtn ); - sampleTable.addItem( new Object[] { - operation.getOperationName(), operation.getCommandName(), availableOperations - }, null ); - - addClickListenerToViewButton( viewBtn, operation ); - addClickListenerToEditButton( editBtn, operation ); - addClickListenerToDeleteButton( deleteBtn, operation ); - } - } - - - private void addClickListenerToDeleteButton( final Button deleteBtn, final Operation operation ) - { - getButton( DELETE_BUTTON_CAPTION, deleteBtn ).addClickListener( new Button.ClickListener() - { - @Override - public void buttonClick( Button.ClickEvent event ) - { - genericPlugin.deleteOperation( operation.getOperationId() ); - show( "Operation deleted successfully!" ); - refreshUI(); - } - } ); - } - - - private void addClickListenerToViewButton( Button viewBtn, final Operation operation ) - { - getButton( VIEW_BUTTON_CAPTION, viewBtn ).addClickListener( new Button.ClickListener() - { - @Override - public void buttonClick( Button.ClickEvent event ) - { - final Window subWindow = new Window( "Edit operation" ); - subWindow.setClosable( false ); - subWindow.addStyleName( "default" ); - subWindow.center(); - - VerticalLayout subContent = new VerticalLayout(); - subContent.setSpacing( true ); - subContent.setMargin( true ); - - - Label operationLbl = new Label( "Operation name: " + operation.getOperationName() ); - Label command = new Label( "Command: " + operation.getCommandName() ); - Label cwd = new Label( "Cwd: " + operation.getCwd() ); - Label timeout = new Label( "Timeout: " + operation.getTimeout() ); - Label daemon = new Label( "Daemon: " ); - if ( operation.getDaemon() ) - { - daemon.setValue( daemon.getValue() + "yes" ); - } - else - { - daemon.setValue( daemon.getValue() + "no" ); - } - - Button close = new Button( "Close" ); - close.addStyleName( BUTTON_STYLE_NAME ); - close.addClickListener( new Button.ClickListener() - { - @Override - public void buttonClick( Button.ClickEvent event ) - { - subWindow.close(); - } - } ); - - subContent.addComponent( operationLbl ); - subContent.addComponent( command ); - subContent.addComponent( cwd ); - subContent.addComponent( timeout ); - subContent.addComponent( daemon ); - subContent.addComponent( close ); - subContent.setComponentAlignment( close, Alignment.BOTTOM_CENTER ); - - subWindow.setContent( subContent ); - UI.getCurrent().addWindow( subWindow ); - } - } ); - } - - - private void addClickListenerToEditButton( Button viewBtn, final Operation operation ) - { - getButton( EDIT_BUTTON_CAPTION, viewBtn ).addClickListener( new Button.ClickListener() - { - @Override - public void buttonClick( Button.ClickEvent event ) - { - final Window subWindow = new Window( "Edit operation" ); - subWindow.setClosable( false ); - subWindow.addStyleName( "default" ); - subWindow.center(); - - VerticalLayout subContent = new VerticalLayout(); - subContent.setSpacing( true ); - subContent.setMargin( true ); - - HorizontalLayout editInfo = new HorizontalLayout(); - editInfo.setSpacing( true ); - editInfo.setWidth( "100%" ); - - final TextField editCommand = new TextField( "Edit command" ); - editCommand.setValue( operation.getCommandName() ); - - /*final ComboBox editTemplate = new ComboBox ("Edit template"); - for (Template t : wizard.getRegistry().getAllTemplates()) + // + + + cwd.setValue ("/"); + cwd.setData ("/"); + timeOut.setValue ("30"); + timeOut.setData ("30"); + daemon.setValue (false); + daemon.setData (false); + + Button options = new Button ("Options"); + options.addStyleName (BUTTON_STYLE_NAME); + + Button addOperation = new Button ("Add operation"); + addOperation.addStyleName (BUTTON_STYLE_NAME); + + + Button uploadScript = new Button ("Upload script"); + uploadScript.addStyleName ("default"); + uploadScript.addClickListener (new Button.ClickListener() + { + @Override + public void buttonClick (Button.ClickEvent event) + { + uploadWindow = new Window ("Upload Script"); + uploadWindow.center(); + uploadWindow.setClosable (false); + uploadWindow.addStyleName ("default"); + VerticalLayout content = new VerticalLayout(); + content.setSpacing (true); + content.setMargin (true); + MyUploader uploader = new MyUploader(); + Upload upload = new Upload ("", uploader); + upload.setButtonCaption ("Start Upload"); + upload.addSucceededListener (uploader); + upload.addFailedListener (uploader); + Button cancel = new Button ("Cancel"); + cancel.addClickListener (new Button.ClickListener() + { + @Override + public void buttonClick (Button.ClickEvent event) + { + uploadWindow.close(); + } + }); + content.addComponent (upload); + content.addComponent (cancel); + content.setComponentAlignment (upload, Alignment.BOTTOM_CENTER); + content.setComponentAlignment (cancel, Alignment.BOTTOM_CENTER); + uploadWindow.setContent (content); + UI.getCurrent().addWindow (uploadWindow); + } + }); + + + + fieldGrid.addComponent (newName); + fieldGrid.addComponent (newCommand); + // fieldGrid.addComponent (templates); + fieldGrid.addComponent (options); + fieldGrid.addComponent (addOperation); + fieldGrid.addComponent (uploadScript); + fieldGrid.setComponentAlignment (newName, Alignment.BOTTOM_LEFT); + fieldGrid.setComponentAlignment (newCommand, Alignment.BOTTOM_LEFT); + //fieldGrid.setComponentAlignment (templates, Alignment.BOTTOM_LEFT); + fieldGrid.setComponentAlignment (options, Alignment.BOTTOM_LEFT); + fieldGrid.setComponentAlignment (addOperation, Alignment.BOTTOM_LEFT); + fieldGrid.setComponentAlignment (uploadScript, Alignment.BOTTOM_LEFT); + + content.addComponent (title); + content.addComponent (profileSelect); + content.addComponent (fieldGrid); + content.addComponent (operationTable); + + Button back = new Button ("Back"); + back.addStyleName (BUTTON_STYLE_NAME); + back.addClickListener (new Button.ClickListener() + { + @Override + public void buttonClick (final Button.ClickEvent clickEvent) + { + wizard.changeWindow (0); + wizard.putForm(); + } + }); + content.addComponent (back); + + + options.addClickListener (new Button.ClickListener() + { + @Override + public void buttonClick (Button.ClickEvent event) + { + final Window subWindow = new Window ("Edit operation"); + subWindow.setClosable (false); + subWindow.addStyleName ("default"); + subWindow.center(); + VerticalLayout subContent = new VerticalLayout(); + subContent.setSpacing (true); + subContent.setMargin (true); + HorizontalLayout fields = new HorizontalLayout(); + fields.setSpacing (true); + fields.addComponent (cwd); + fields.addComponent (timeOut); + fields.setComponentAlignment (cwd, Alignment.BOTTOM_LEFT); + fields.setComponentAlignment (timeOut, Alignment.BOTTOM_LEFT); + + HorizontalLayout buttonGrid = new HorizontalLayout(); + buttonGrid.setSpacing (true); + + Button back = new Button ("Back"); + back.setSizeFull(); + back.addClickListener (new Button.ClickListener() + { + @Override + public void buttonClick (Button.ClickEvent event) + { + cwd.setValue ((String) cwd.getData()); + timeOut.setValue ((String) timeOut.getData()); + daemon.setValue ((boolean) daemon.getData()); + subWindow.close(); + } + }); + + Button save = new Button ("Save"); + save.setSizeFull(); + save.addClickListener (new Button.ClickListener() + { + @Override + public void buttonClick (Button.ClickEvent event) + { + cwd.setData (cwd.getValue()); + timeOut.setData (timeOut.getValue()); + daemon.setData (daemon.getValue()); + subWindow.close(); + } + }); + + buttonGrid.addComponent (back); + buttonGrid.addComponent (save); + buttonGrid.setComponentAlignment (back, Alignment.BOTTOM_CENTER); + buttonGrid.setComponentAlignment (save, Alignment.BOTTOM_CENTER); + + subContent.addComponent (fields); + subContent.addComponent (daemon); + subContent.addComponent (buttonGrid); + subContent.setComponentAlignment (daemon, Alignment.BOTTOM_LEFT); + subContent.setComponentAlignment (buttonGrid, Alignment.BOTTOM_CENTER); + subWindow.setContent (subContent); + UI.getCurrent().addWindow (subWindow); + } + }); + + + addOperation.addClickListener (new Button.ClickListener() + { + public void buttonClick (final Button.ClickEvent clickEvent) + { + if (newName.getValue().isEmpty()) + { + show ("Please enter operation name"); + } + else if (newCommand.getValue().isEmpty()) + { + show ("Please enter command"); + } + else + { + Profile current = (Profile) profileSelect.getValue(); + if (genericPlugin.IsOperationRegistered (newName.getValue())) + { + show ("Operation with such name already exists"); + } + else + { + genericPlugin.saveOperation (current.getId(), newName.getValue(), newCommand.getValue(), cwd.getValue(), timeOut.getValue(), daemon.getValue()); + show ("Operation saved successfully!"); + refreshUI(); + } + } + } + }); + this.setContent (content); + } + + + private Table createTableTemplate (final String caption) + { + final Table table = new Table (caption); + table.addContainerProperty ("Operation name", String.class, null); + table.addContainerProperty ("Command", String.class, null); + // table.addContainerProperty ("Template", String.class, null); + table.addContainerProperty ("Actions", HorizontalLayout.class, null); + table.setSizeFull(); + table.setPageLength (10); + table.setSelectable (false); + table.setImmediate (true); + + return table; + } + + + private void refreshUI() + { + if (profile != null) + { + List operations = genericPlugin.getProfileOperations (profile.getId()); + populateTable (operationTable, operations); + } + } + + + private void populateTable (final Table sampleTable, final List operations) + { + sampleTable.removeAllItems(); + + for (Operation operation : operations) + { + final Button viewBtn = new Button ("View"); + final Button editBtn = new Button ("Edit"); + final Button deleteBtn = new Button ("Delete"); + + addStyleNameToButtons (viewBtn, editBtn, deleteBtn); + + final HorizontalLayout availableOperations = new HorizontalLayout(); + availableOperations.addStyleName ("default"); + availableOperations.setSpacing (true); + + addGivenComponents (availableOperations, viewBtn, editBtn, deleteBtn); + sampleTable.addItem (new Object[] { operation.getOperationName(), operation.getCommandName(), availableOperations }, null ); + + addClickListenerToViewButton (viewBtn, operation); + addClickListenerToEditButton (editBtn, operation); + addClickListenerToDeleteButton (deleteBtn, operation); + } + } + + + private void addClickListenerToDeleteButton (final Button deleteBtn, final Operation operation) + { + deleteBtn.addClickListener (new Button.ClickListener() + { + @Override + public void buttonClick (Button.ClickEvent event) + { + genericPlugin.deleteOperation (operation.getOperationId()); + show ("Operation deleted successfully!"); + refreshUI(); + } + }); + } + + + private void addClickListenerToViewButton( Button viewBtn, final Operation operation ) + { + viewBtn.addClickListener (new Button.ClickListener() + { + @Override + public void buttonClick (Button.ClickEvent event) + { + final Window subWindow = new Window ("Edit operation"); + subWindow.setClosable (false); + subWindow.addStyleName ("default"); + subWindow.center(); + + VerticalLayout subContent = new VerticalLayout(); + subContent.setSpacing (true); + subContent.setMargin (true); + + + Label operationLbl = new Label ("Operation name: " + operation.getOperationName()); + Label command = new Label ("Command: " + operation.getCommandName()); + Label cwd = new Label ("Cwd: " + operation.getCwd()); + Label timeout = new Label ("Timeout: " + operation.getTimeout()); + Label daemon = new Label ("Daemon: "); + if (operation.getDaemon()) + { + daemon.setValue (daemon.getValue() + "yes"); + } + else + { + daemon.setValue (daemon.getValue() + "no"); + } + + Button close = new Button ("Close"); + close.addStyleName (BUTTON_STYLE_NAME); + close.addClickListener (new Button.ClickListener() + { + @Override + public void buttonClick (Button.ClickEvent event) + { + subWindow.close(); + } + }); + + subContent.addComponent (operationLbl); + subContent.addComponent (command); + subContent.addComponent (cwd); + subContent.addComponent (timeout); + subContent.addComponent (daemon); + subContent.addComponent (close); + subContent.setComponentAlignment (close, Alignment.BOTTOM_CENTER); + + subWindow.setContent (subContent); + UI.getCurrent().addWindow (subWindow); + } + }); + } + + + private void addClickListenerToEditButton (Button editBtn, final Operation operation) + { + editBtn.addClickListener (new Button.ClickListener() + { + @Override + public void buttonClick (Button.ClickEvent event) + { + final Window subWindow = new Window ("Edit operation"); + subWindow.setClosable (false); + subWindow.addStyleName ("default"); + subWindow.center(); + + VerticalLayout subContent = new VerticalLayout(); + subContent.setSpacing (true); + subContent.setMargin (true); + + HorizontalLayout editInfo = new HorizontalLayout(); + editInfo.setSpacing (true); + editInfo.setWidth ("100%"); + + final TextField editCommand = new TextField ("Edit command"); + editCommand.setValue (operation.getCommandName()); + + /*final ComboBox editTemplate = new ComboBox ("Edit template"); + for (Template t : wizard.getRegistry().getAllTemplates()) + { + editTemplate.addItem (t.getTemplateName()); + } + editTemplate.setValue (operationTable.getItem (edit.getData()).getItemProperty ("Template").toString());*/ + + final TextField editCwd = new TextField ("Edit cwd"); + editCwd.setValue (operation.getCwd()); + + final TextField editTimeout = new TextField ("Edit timeout"); + editTimeout.setValue (operation.getTimeout()); + + final CheckBox editDaemon = new CheckBox ("Edit daemon"); + editDaemon.setValue (operation.getDaemon()); + + + HorizontalLayout buttons = new HorizontalLayout(); + buttons.setSpacing (true); + buttons.setWidth ("100%"); + + Button cancel = new Button ("Cancel"); + cancel.addStyleName (BUTTON_STYLE_NAME); + cancel.addClickListener (new Button.ClickListener() + { + @Override + public void buttonClick (Button.ClickEvent clickEvent) + { + subWindow.close(); + } + }); + + + Button finalEdit = new Button ("Edit"); + finalEdit.addStyleName (BUTTON_STYLE_NAME); + finalEdit.addClickListener (new Button.ClickListener() + { + @Override + public void buttonClick (Button.ClickEvent clickEvent) { - editTemplate.addItem (t.getTemplateName()); + if (editCommand.getValue().isEmpty()) + { + Notification notif = new Notification ("Please enter command"); + notif.setDelayMsec (2000); + notif.show (Page.getCurrent()); + } + else + { + genericPlugin.updateOperation (operation, editCommand.getValue(), editCwd.getValue(), editTimeout.getValue(), editDaemon.getValue()); + show ("Operation saved successfully!"); + subWindow.close(); + refreshUI(); + } } - editTemplate.setValue (operationTable.getItem (edit.getData()).getItemProperty ("Template") - .toString());*/ - - final TextField editCwd = new TextField( "Edit cwd" ); - editCwd.setValue( operation.getCwd() ); - - final TextField editTimeout = new TextField( "Edit timeout" ); - editTimeout.setValue( operation.getTimeout() ); - - final CheckBox editDaemon = new CheckBox( "Edit daemon" ); - editDaemon.setValue( operation.getDaemon() ); - - - HorizontalLayout buttons = new HorizontalLayout(); - buttons.setSpacing( true ); - buttons.setWidth( "100%" ); - - Button cancel = new Button( "Cancel" ); - cancel.addStyleName( BUTTON_STYLE_NAME ); - cancel.addClickListener( new Button.ClickListener() - { - @Override - public void buttonClick( Button.ClickEvent clickEvent ) - { - subWindow.close(); - } - } ); - - - Button finalEdit = new Button( "Edit" ); - finalEdit.addStyleName( BUTTON_STYLE_NAME ); - finalEdit.addClickListener( new Button.ClickListener() - { - @Override - public void buttonClick( Button.ClickEvent clickEvent ) - { - if ( editCommand.getValue().isEmpty() ) - { - Notification notif = new Notification( "Please enter command" ); - notif.setDelayMsec( 2000 ); - notif.show( Page.getCurrent() ); - } - else - { - genericPlugin.updateOperation( operation, editCommand.getValue(), editCwd.getValue(), - editTimeout.getValue(), editDaemon.getValue() ); - show( "Operation saved successfully!" ); - subWindow.close(); - refreshUI(); - } - } - } ); - - - editInfo.addComponent( editCommand ); - //editInfo.addComponent (editTemplate); - editInfo.addComponent( editCwd ); - editInfo.addComponent( editTimeout ); - editInfo.setComponentAlignment( editCommand, Alignment.BOTTOM_LEFT ); - //editInfo.setComponentAlignment (editTemplate, Alignment.BOTTOM_LEFT); - editInfo.setComponentAlignment( editCwd, Alignment.BOTTOM_LEFT ); - editInfo.setComponentAlignment( editTimeout, Alignment.BOTTOM_LEFT ); - - buttons.addComponent( cancel ); - buttons.addComponent( finalEdit ); - buttons.setComponentAlignment( cancel, Alignment.BOTTOM_CENTER ); - buttons.setComponentAlignment( finalEdit, Alignment.BOTTOM_CENTER ); - - - subContent.addComponent( editInfo ); - subContent.addComponent( editDaemon ); - subContent.setComponentAlignment( editDaemon, Alignment.BOTTOM_CENTER ); - subContent.addComponent( buttons ); - - - subWindow.setContent( subContent ); - UI.getCurrent().addWindow( subWindow ); - } - } ); - } - - - private void refreshProfileInfo() - { - profileSelect.removeAllItems(); - List profileInfo = genericPlugin.getProfiles(); - if ( profileInfo != null && !profileInfo.isEmpty() ) - { - for ( Profile pi : profileInfo ) - { - profileSelect.addItem( pi ); - profileSelect.setItemCaption( pi, pi.getName() ); - } - } - } - - - private void addStyleNameToButtons( Button... buttons ) - { - for ( Button b : buttons ) - { - b.addStyleName( BUTTON_STYLE_NAME ); - } - } - - - private void addGivenComponents( HorizontalLayout layout, Button... buttons ) - { - for ( Button b : buttons ) - { - layout.addComponent( b ); - } - } - - - private void show( String notification ) - { - Notification.show( notification ); - } - - - private Button getButton( String caption, Button... buttons ) - { - for ( Button b : buttons ) - { - if ( b.getCaption().equals( caption ) ) - { - return b; - } - } - return null; - } + }); + + + editInfo.addComponent (editCommand); + // editInfo.addComponent (editTemplate); + editInfo.addComponent (editCwd); + editInfo.addComponent (editTimeout); + editInfo.setComponentAlignment (editCommand, Alignment.BOTTOM_LEFT); + // editInfo.setComponentAlignment (editTemplate, Alignment.BOTTOM_LEFT); + editInfo.setComponentAlignment (editCwd, Alignment.BOTTOM_LEFT); + editInfo.setComponentAlignment (editTimeout, Alignment.BOTTOM_LEFT); + + buttons.addComponent (cancel); + buttons.addComponent (finalEdit); + buttons.setComponentAlignment (cancel, Alignment.BOTTOM_CENTER); + buttons.setComponentAlignment (finalEdit, Alignment.BOTTOM_CENTER); + + + subContent.addComponent (editInfo); + subContent.addComponent (editDaemon ); + subContent.setComponentAlignment (editDaemon, Alignment.BOTTOM_CENTER); + subContent.addComponent (buttons); + + + subWindow.setContent (subContent); + UI.getCurrent().addWindow (subWindow); + } + }); + } + + + private void refreshProfileInfo() + { + profileSelect.removeAllItems(); + List profileInfo = genericPlugin.getProfiles(); + if (profileInfo != null && !profileInfo.isEmpty()) + { + boolean set = false; + for (Profile pi : profileInfo) + { + profileSelect.addItem (pi); + profileSelect.setItemCaption (pi, pi.getName()); + if (!set) + { + profileSelect.setValue (pi); + set = true; + } + } + } + } + + + private void addStyleNameToButtons (Button... buttons) + { + for (Button b : buttons) + { + b.addStyleName (BUTTON_STYLE_NAME); + } + } + + + private void addGivenComponents (HorizontalLayout layout, Button... buttons) + { + for (Button b : buttons) + { + layout.addComponent (b); + } + } + + + private void show (String notification) + { + Notification notif = new Notification (notification); + notif.setDelayMsec (2000); + notif.show (Page.getCurrent()); + } } diff --git a/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/wizard/ManageContainersStep.java b/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/wizard/ManageContainersStep.java index 3edb97d02..83ab09b25 100644 --- a/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/wizard/ManageContainersStep.java +++ b/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/wizard/ManageContainersStep.java @@ -6,6 +6,7 @@ import java.util.Objects; import java.util.Set; +import com.vaadin.server.Page; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,340 +35,341 @@ @Theme( "valo" ) public class ManageContainersStep extends Panel { - private static final Logger LOG = LoggerFactory.getLogger( Wizard.class.getName() ); - private static final String EXECUTE_BUTTON_CAPTION = "Execute"; - private static final String BUTTON_STYLE_NAME = "default"; - private Environment currentEnvironment; - private Profile currentProfile; - private String currentTemplate; - private Table containerTable; - private Operation currentOperation; - private Wizard wizard; - private TextArea output = new TextArea( "Output" ); - - private GenericPlugin genericPlugin; - private VerticalLayout content; - private HorizontalLayout comboGrid; - private ComboBox envSelect; - private ComboBox profileSelect; - private ComboBox templates; - - - public ManageContainersStep( final Wizard wizard, final GenericPlugin genericPlugin ) - { - this.wizard = wizard; - this.genericPlugin = genericPlugin; - this.setSizeFull(); - - content = new VerticalLayout(); - Label title = new Label( "Manage containers" ); - - comboGrid = new HorizontalLayout(); - comboGrid.setWidth( "100%" ); - comboGrid.setSpacing( true ); - - envSelect = new ComboBox( "Environment" ); - envSelect.setNullSelectionAllowed( false ); - envSelect.setTextInputAllowed( false ); - - profileSelect = new ComboBox( "Profile" ); - profileSelect.setNullSelectionAllowed( false ); - profileSelect.setTextInputAllowed( false ); - - templates = new ComboBox( "Template" ); - templates.setNullSelectionAllowed( false ); - templates.setTextInputAllowed( false ); - - comboGrid.addComponent( envSelect ); - comboGrid.addComponent( templates ); - comboGrid.addComponent( profileSelect ); - - containerTable = createTableTemplate( "Containers" ); - - content.addComponent( title ); - content.addComponent( comboGrid ); - content.addComponent( containerTable ); - - templates.addValueChangeListener( new Property.ValueChangeListener() - { - @Override - public void valueChange( Property.ValueChangeEvent event ) - { - currentTemplate = ( String ) event.getProperty().getValue(); - refreshUI(); - } - } ); - - profileSelect.addValueChangeListener( new Property.ValueChangeListener() - { - @Override - public void valueChange( Property.ValueChangeEvent event ) - { - currentProfile = ( Profile ) event.getProperty().getValue(); - refreshUI(); - } - } ); - - envSelect.addValueChangeListener( new Property.ValueChangeListener() - { - @Override - public void valueChange( Property.ValueChangeEvent event ) - { - currentEnvironment = ( Environment ) event.getProperty().getValue(); - refreshTemplates( currentEnvironment ); - refreshUI(); - } - } ); - - refreshPluginInfo(); - - Button back = new Button( "Back" ); - addStyleNameToButtons( back ); - back.addClickListener( new Button.ClickListener() - { - @Override - public void buttonClick( final Button.ClickEvent clickEvent ) - { - wizard.changeWindow( 0 ); - wizard.putForm(); - } - } ); - content.addComponent( back ); - output.setSizeFull(); - output.setRows( 15 ); - // output.setReadOnly (true); TODO: set output readonly without making its design like a label - content.addComponent( output ); - this.setContent( content ); - } - - - protected void addOutput( String output ) - { - if ( !Strings.isNullOrEmpty( output ) ) - { - this.output.setValue( output ); - this.output.setCursorPosition( this.output.getValue().length() - 1 ); - } - } - - - private void refreshPluginInfo() - { - Profile currentProfile = ( Profile ) profileSelect.getValue(); - profileSelect.removeAllItems(); - List profileInfo = genericPlugin.getProfiles(); - if ( profileInfo != null && !profileInfo.isEmpty() ) - { - for ( Profile pi : profileInfo ) - { - profileSelect.addItem( pi ); - profileSelect.setItemCaption( pi, pi.getName() ); - } - if ( currentProfile != null ) - { - for ( Profile pi : profileInfo ) - { - if ( pi.getName().equals( currentProfile.getName() ) ) - { - profileSelect.setValue( pi ); - } - } - } - else - { - profileSelect.setValue( profileInfo.get( 0 ) ); - } - } - - Environment currentEvn = ( Environment ) envSelect.getValue(); - envSelect.removeAllItems(); - Set environments = wizard.getManager().getEnvironments(); - if ( environments != null && !environments.isEmpty() ) - { - for ( Environment environment : environments ) - { - envSelect.addItem( environment ); - envSelect.setItemCaption( environment, environment.getName() ); - } - if ( currentEvn != null ) - { - for ( Environment env : environments ) - { - if ( env.getName().equals( currentEvn.getName() ) ) - { - envSelect.setValue( env ); - } - } - } - else - { - for ( Environment env : environments ) - { - envSelect.setValue( env ); - envSelect.setItemCaption( env, env.getName() ); - break; - } - } - } - } - - - private void refreshTemplates( Environment environment ) - { - templates.removeAllItems(); - Set tempSet = new HashSet<>(); - if ( environment != null ) - { - for ( ContainerHost c : environment.getContainerHosts() ) - { - tempSet.add( c.getTemplateName() ); - } - - for ( String s : tempSet ) - { - templates.addItem( s ); - } - } - } - - - private Table createTableTemplate( final String caption ) - { - final Table table = new Table( caption ); - table.addContainerProperty( "Container name", String.class, null ); - table.addContainerProperty( "Operation", ComboBox.class, null ); - table.addContainerProperty( "Action", Button.class, null ); - //operationTable.addContainerProperty ("Template", String.class, null); - // table.addContainerProperty( "Action", HorizontalLayout.class, null ); - table.setSizeFull(); - table.setPageLength( 10 ); - table.setSelectable( false ); - table.setImmediate( true ); - - return table; - } - - - private void refreshUI() - { - if ( currentEnvironment != null && currentProfile != null ) - { - Set hosts = currentEnvironment.getContainerHosts(); - - if ( currentTemplate == null ) - { - populateTable( containerTable, hosts, currentProfile ); - } - else - { - Set sortedHosts = Sets.newHashSet(); - for ( final EnvironmentContainerHost host : hosts ) - { - if ( Objects.equals( host.getTemplateName(), currentTemplate ) ) - { - sortedHosts.add( host ); - } - } - - populateTable( containerTable, sortedHosts, currentProfile ); - } - } - } - - - private void populateTable( final Table containerTable, final Set hosts, - final Profile currentProfile ) - { - containerTable.removeAllItems(); - - for ( final ContainerHost host : hosts ) - { - final Button executeBtn = new Button( EXECUTE_BUTTON_CAPTION ); - addStyleNameToButtons( executeBtn ); - - final ComboBox operationSelect = new ComboBox(); - operationSelect.setNullSelectionAllowed( false ); - operationSelect.setTextInputAllowed( false ); - - List operations = genericPlugin.getProfileOperations( currentProfile.getId() ); - - if ( operations != null && !operations.isEmpty() ) - { - for ( Operation operation : operations ) - { - operationSelect.addItem( operation ); - operationSelect.setItemCaption( operation, operation.getOperationName() ); - } - operationSelect.select( operations.get( 0 ) ); - } - - operationSelect.addValueChangeListener( new Property.ValueChangeListener() - { - @Override - public void valueChange( Property.ValueChangeEvent event ) - { - currentOperation = ( Operation ) event.getProperty().getValue(); - operationSelect.setValue( currentOperation ); - } - } ); - - containerTable.addItem( new Object[] { - host.getHostname(), operationSelect, executeBtn - }, null ); - - executeBtn.addClickListener( new Button.ClickListener() - { - @Override - public void buttonClick( final Button.ClickEvent clickEvent ) - { - addOutput( genericPlugin.executeCommandOnContainer( host, (Operation) operationSelect.getValue() ) ); - show( "Operation deleted successfully!" ); - } - } ); -// addClickListenerToExecuteButton( executeBtn, host, ( Operation ) operationSelect.getValue() ); - } - } - - - private void addClickListenerToExecuteButton( final Button executeBtn, final ContainerHost host, - final Operation operation ) - { - getButton( EXECUTE_BUTTON_CAPTION, executeBtn ).addClickListener( new Button.ClickListener() - { - @Override - public void buttonClick( Button.ClickEvent event ) - { - addOutput( genericPlugin.executeCommandOnContainer( host, operation ) ); - show( "Operation deleted successfully!" ); - } - } ); - } - - - private Button getButton( String caption, Button... buttons ) - { - for ( Button b : buttons ) - { - if ( b.getCaption().equals( caption ) ) - { - return b; - } - } - return null; - } - - - private void addStyleNameToButtons( Button... buttons ) - { - for ( Button b : buttons ) - { - b.addStyleName( BUTTON_STYLE_NAME ); - } - } - - - private void show( String notification ) - { - Notification.show( notification ); - } + private static final Logger LOG = LoggerFactory.getLogger( Wizard.class.getName() ); + private static final String EXECUTE_BUTTON_CAPTION = "Execute"; + private static final String BUTTON_STYLE_NAME = "default"; + private Environment currentEnvironment; + private Profile currentProfile; + private String currentTemplate; + private Table containerTable; + private Operation currentOperation; + private Wizard wizard; + private TextArea output = new TextArea( "Output" ); + + private GenericPlugin genericPlugin; + private VerticalLayout content; + private HorizontalLayout comboGrid; + private ComboBox envSelect; + private ComboBox profileSelect; + private ComboBox templates; + + + public ManageContainersStep (final Wizard wizard, final GenericPlugin genericPlugin) + { + this.wizard = wizard; + this.genericPlugin = genericPlugin; + this.setSizeFull(); + + content = new VerticalLayout(); + Label title = new Label ("Manage containers"); + + comboGrid = new HorizontalLayout(); + comboGrid.setWidth ("100%"); + comboGrid.setSpacing (true); + + envSelect = new ComboBox ("Environment"); + envSelect.setNullSelectionAllowed (false); + envSelect.setTextInputAllowed (false); + + profileSelect = new ComboBox ("Profile"); + profileSelect.setNullSelectionAllowed (false); + profileSelect.setTextInputAllowed (false); + + templates = new ComboBox ("Template"); + templates.setNullSelectionAllowed (false); + templates.setTextInputAllowed (false); + + comboGrid.addComponent (envSelect); + comboGrid.addComponent (templates); + comboGrid.addComponent (profileSelect); + + containerTable = createTableTemplate ("Containers"); + containerTable.setHeight ("200px"); + content.addComponent (title); + content.addComponent (comboGrid); + content.addComponent (containerTable); + + templates.addValueChangeListener (new Property.ValueChangeListener() + { + @Override + public void valueChange (Property.ValueChangeEvent event) + { + currentTemplate = (String) event.getProperty().getValue(); + refreshUI(); + } + }); + + profileSelect.addValueChangeListener (new Property.ValueChangeListener() + { + @Override + public void valueChange (Property.ValueChangeEvent event) + { + currentProfile = (Profile) event.getProperty().getValue(); + refreshUI(); + } + }); + + envSelect.addValueChangeListener (new Property.ValueChangeListener() + { + @Override + public void valueChange (Property.ValueChangeEvent event) + { + currentEnvironment = (Environment) event.getProperty().getValue(); + refreshTemplates (currentEnvironment); + refreshUI(); + } + }); + + refreshPluginInfo(); + + Button back = new Button ("Back"); + addStyleNameToButtons (back); + back.addClickListener (new Button.ClickListener() + { + @Override + public void buttonClick (final Button.ClickEvent clickEvent) + { + wizard.changeWindow (0); + wizard.putForm(); + } + }); + content.addComponent (back); + output.setSizeFull(); + output.setRows (15); + // output.setReadOnly (true); TODO: set output readonly without making its design like a label + content.addComponent (output); + this.setContent (content); + } + + + protected void addOutput (String output) + { + if (!Strings.isNullOrEmpty (output)) + { + this.output.setValue (output); + this.output.setCursorPosition (this.output.getValue().length() - 1); + } + } + + + private void refreshPluginInfo() + { + Profile currentProfile = (Profile) profileSelect.getValue(); + profileSelect.removeAllItems(); + List profileInfo = genericPlugin.getProfiles(); + if (profileInfo != null && !profileInfo.isEmpty()) + { + for (Profile pi : profileInfo) + { + profileSelect.addItem (pi); + profileSelect.setItemCaption (pi, pi.getName()); + } + if (currentProfile != null) + { + for (Profile pi : profileInfo) + { + if (pi.getName().equals (currentProfile.getName())) + { + profileSelect.setValue (pi); + } + } + } + else + { + profileSelect.setValue( profileInfo.get( 0 ) ); + } + } + + Environment currentEvn = (Environment) envSelect.getValue(); + envSelect.removeAllItems(); + Set environments = wizard.getManager().getEnvironments(); + if (environments != null && !environments.isEmpty()) + { + for (Environment environment : environments) + { + envSelect.addItem (environment); + envSelect.setItemCaption (environment, environment.getName()); + } + if (currentEvn != null) + { + for (Environment env : environments) + { + if (env.getName().equals (currentEvn.getName())) + { + envSelect.setValue (env); + } + } + } + else + { + for (Environment env : environments) + { + envSelect.setValue (env); + envSelect.setItemCaption (env, env.getName()); + break; + } + } + } + } + + + private void refreshTemplates (Environment environment) + { + templates.removeAllItems(); + Set tempSet = new HashSet<>(); + if (environment != null) + { + for (ContainerHost c : environment.getContainerHosts()) + { + tempSet.add (c.getTemplateName()); + } + boolean set = false; + for (String s : tempSet) + { + templates.addItem (s); + if (!set) + { + templates.setValue (s); + set = true; + } + } + } + } + + + private Table createTableTemplate (final String caption) + { + final Table table = new Table (caption); + table.addContainerProperty ("Container name", String.class, null); + table.addContainerProperty ("Operation", ComboBox.class, null); + table.addContainerProperty ("Action", Button.class, null); + // table.addContainerProperty ("Template", String.class, null); + // table.addContainerProperty ("Action", HorizontalLayout.class, null); + table.setSizeFull(); + table.setPageLength (10); + table.setSelectable (false); + table.setImmediate (true); + + return table; + } + + + private void refreshUI() + { + if (currentEnvironment != null && currentProfile != null) + { + Set hosts = currentEnvironment.getContainerHosts(); + + if (currentTemplate == null) + { + populateTable (containerTable, hosts, currentProfile); + } + else + { + Set sortedHosts = Sets.newHashSet(); + for (final EnvironmentContainerHost host : hosts) + { + if (Objects.equals (host.getTemplateName(), currentTemplate)) + { + sortedHosts.add (host); + } + } + + populateTable (containerTable, sortedHosts, currentProfile); + } + } + } + + + private void populateTable (final Table containerTable, final Set hosts, final Profile currentProfile ) + { + containerTable.removeAllItems(); + + for (final ContainerHost host : hosts) + { + final Button executeBtn = new Button (EXECUTE_BUTTON_CAPTION); + addStyleNameToButtons (executeBtn); + + final ComboBox operationSelect = new ComboBox(); + operationSelect.setNullSelectionAllowed (false); + operationSelect.setTextInputAllowed (false); + + List operations = genericPlugin.getProfileOperations (currentProfile.getId()); + + if (operations != null && !operations.isEmpty()) + { + for (Operation operation : operations) + { + operationSelect.addItem (operation); + operationSelect.setItemCaption (operation, operation.getOperationName()); + } + operationSelect.select (operations.get (0)); + } + + operationSelect.addValueChangeListener (new Property.ValueChangeListener() + { + @Override + public void valueChange (Property.ValueChangeEvent event) + { + currentOperation = (Operation) event.getProperty().getValue(); + operationSelect.setValue (currentOperation); + } + }); + + containerTable.addItem (new Object[] {host.getHostname(), operationSelect, executeBtn}, null); + + executeBtn.addClickListener (new Button.ClickListener() + { + @Override + public void buttonClick (final Button.ClickEvent clickEvent) + { + addOutput (genericPlugin.executeCommandOnContainer (host, (Operation) operationSelect.getValue())); + } + }); + // addClickListenerToExecuteButton( executeBtn, host, ( Operation ) operationSelect.getValue() ); + } + } + + + private void addClickListenerToExecuteButton (final Button executeBtn, final ContainerHost host, final Operation operation) + { + executeBtn.addClickListener (new Button.ClickListener() + { + @Override + public void buttonClick (Button.ClickEvent event) + { + addOutput (genericPlugin.executeCommandOnContainer (host, operation)); + } + }); + } + + + private Button getButton (String caption, Button... buttons) + { + for (Button b : buttons) + { + if (b.getCaption().equals (caption)) + { + return b; + } + } + return null; + } + + + private void addStyleNameToButtons (Button... buttons) + { + for (Button b : buttons) + { + b.addStyleName (BUTTON_STYLE_NAME); + } + } + + + private void show (String notification) + { + Notification notif = new Notification (notification); + notif.setDelayMsec (2000); + notif.show (Page.getCurrent()); + } } diff --git a/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/wizard/ProfileCreationStep.java b/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/wizard/ProfileCreationStep.java index 0ebd87f12..27b6d9b13 100644 --- a/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/wizard/ProfileCreationStep.java +++ b/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/wizard/ProfileCreationStep.java @@ -3,6 +3,7 @@ import com.google.gwt.thirdparty.guava.common.base.Strings; import com.vaadin.annotations.Theme; +import com.vaadin.server.Page; import com.vaadin.ui.Button; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Notification; @@ -11,79 +12,106 @@ import com.vaadin.ui.VerticalLayout; import io.subutai.plugin.generic.api.GenericPlugin; +import io.subutai.plugin.generic.api.model.Profile; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @Theme( "valo" ) public class ProfileCreationStep extends Panel { -// private GenericPlugin genericPlugin; - private Panel panel; - private VerticalLayout panelContent; - private TextField newProfile; - private HorizontalLayout buttonsGrid; - private Button create; - private Button back; - - public ProfileCreationStep( final Wizard wizard, final GenericPlugin genericPlugin ) - { - this.setSizeFull(); - - panel = new Panel( "

Create profile

" ); - panelContent = new VerticalLayout(); - panel.setContent( panelContent ); - panelContent.setSpacing( true ); - - newProfile = new TextField( "Profile" ); - newProfile.setInputPrompt( "New profile name" ); - newProfile.setRequired( true ); - panelContent.addComponent( newProfile ); - - buttonsGrid = new HorizontalLayout(); - buttonsGrid.setSpacing( true ); - - create = new Button( "Create" ); - create.addStyleName( "default" ); - - back = new Button( "Back" ); - back.addStyleName( "default" ); - buttonsGrid.addComponent( back ); - buttonsGrid.addComponent( create ); - panelContent.addComponent( buttonsGrid ); - - create.addClickListener( new Button.ClickListener() - { - @Override - public void buttonClick( final Button.ClickEvent clickEvent ) - { - if ( Strings.isNullOrEmpty( newProfile.getValue() ) ) - { - show( "Please enter profile name" ); - } - else - { - genericPlugin.saveProfile( newProfile.getValue() ); - wizard.changeWindow( 0 ); - wizard.putForm(); - } - } - } ); - - back.addClickListener( new Button.ClickListener() - { - @Override - public void buttonClick( final Button.ClickEvent clickEvent ) - { - wizard.changeWindow( 0 ); - wizard.putForm(); - } - } ); - - this.setContent( panel ); - } - - - private void show( String notification ) - { - Notification.show( notification ); - } + // private GenericPlugin genericPlugin; + private static final Logger LOG = LoggerFactory.getLogger (ProfileCreationStep.class.getName()); + private Panel panel; + private VerticalLayout panelContent; + private TextField newProfile; + private HorizontalLayout buttonsGrid; + private Button create; + private Button back; + + public ProfileCreationStep (final Wizard wizard, final GenericPlugin genericPlugin) + { + this.setSizeFull(); + + panel = new Panel ("

Create profile

"); + panelContent = new VerticalLayout(); + panel.setContent (panelContent); + panelContent.setSpacing (true); + + newProfile = new TextField ("Profile"); + newProfile.setInputPrompt ("New profile name"); + newProfile.setRequired (true); + panelContent.addComponent (newProfile); + + buttonsGrid = new HorizontalLayout(); + buttonsGrid.setSpacing (true); + + create = new Button ("Create"); + create.addStyleName ("default"); + + back = new Button ("Back"); + back.addStyleName ("default"); + buttonsGrid.addComponent (back); + buttonsGrid.addComponent (create); + panelContent.addComponent (buttonsGrid); + + create.addClickListener (new Button.ClickListener() + { + @Override + public void buttonClick (final Button.ClickEvent clickEvent) + { + if (Strings.isNullOrEmpty (newProfile.getValue())) + { + Notification notif = new Notification ("Please enter profile name"); + notif.setDelayMsec (2000); + notif.show (Page.getCurrent()); + } + else + { + boolean exists = false; + for (Profile p : genericPlugin.getProfiles()) + { + LOG.debug (p.getName()); + LOG.debug (newProfile.getValue()); + if (p.getName().equals (newProfile.getValue())) + { + exists = true; + break; + } + } + if (exists) + { + show ("Profile already exists"); + } + else + { + genericPlugin.saveProfile (newProfile.getValue ()); + wizard.changeWindow (0); + wizard.putForm (); + show ("Profile successfully created"); + } + } + } + }); + + back.addClickListener (new Button.ClickListener() + { + @Override + public void buttonClick (final Button.ClickEvent clickEvent) + { + wizard.changeWindow (0); + wizard.putForm(); + } + }); + + this.setContent (panel); + } + + + private void show (String notification) + { + Notification notif = new Notification (notification); + notif.setDelayMsec (2000); + notif.show (Page.getCurrent()); + } } diff --git a/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/wizard/WelcomeStep.java b/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/wizard/WelcomeStep.java index 9895ffe36..ce0ac8ed6 100644 --- a/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/wizard/WelcomeStep.java +++ b/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/wizard/WelcomeStep.java @@ -3,105 +3,129 @@ import com.vaadin.annotations.Theme; import com.vaadin.server.FileResource; +import com.vaadin.server.Page; import com.vaadin.shared.ui.label.ContentMode; -import com.vaadin.ui.Alignment; -import com.vaadin.ui.Button; -import com.vaadin.ui.GridLayout; -import com.vaadin.ui.HorizontalLayout; -import com.vaadin.ui.Label; -import com.vaadin.ui.Panel; +import com.vaadin.ui.*; import io.subutai.common.util.FileUtil; -import io.subutai.plugin.generic.api.Profile; +import io.subutai.plugin.generic.api.GenericPlugin; +import io.subutai.plugin.generic.api.model.Operation; +import io.subutai.plugin.generic.api.model.Profile; import io.subutai.plugin.generic.ui.GenericPluginPortalModule; +import java.util.List; -@Theme( "valo" ) + +@Theme ("valo") public class WelcomeStep extends Panel { - public WelcomeStep( final Wizard wizard ) - { - setSizeFull(); - - GridLayout grid = new GridLayout( 10, 6 ); - grid.setSpacing( true ); - grid.setMargin( true ); - grid.setSizeFull(); - - Label welcomeMsg = - new Label( "

Welcome to Generic Plugin, execute your custom commands on containers

" ); - welcomeMsg.setContentMode( ContentMode.HTML ); - grid.addComponent( welcomeMsg, 3, 1, 6, 2 ); - - Label logoImg = new Label(); - logoImg.setIcon( new FileResource( FileUtil.getFile( GenericPluginPortalModule.MODULE_IMAGE, this ) ) ); - logoImg.setContentMode( ContentMode.HTML ); - logoImg.setHeight( 150, Unit.PIXELS ); - logoImg.setWidth( 150, Unit.PIXELS ); - grid.addComponent( logoImg, 1, 3, 2, 5 ); - - HorizontalLayout buttonsGrid = new HorizontalLayout(); - final Button createProfile = new Button( "Create profile" ); - createProfile.addStyleName( "default" ); - final Button configureOperations = new Button( "Configure operations" ); - configureOperations.addStyleName( "default" ); - final Button manageContainers = new Button( "Manage containers" ); - manageContainers.addStyleName( "default" ); - buttonsGrid.addComponent( createProfile ); - buttonsGrid.addComponent( configureOperations ); - buttonsGrid.addComponent( manageContainers ); - grid.addComponent( buttonsGrid, 6, 4, 6, 4 ); - grid.setComponentAlignment( buttonsGrid, Alignment.BOTTOM_RIGHT ); - - createProfile.addClickListener( new Button.ClickListener() - { - @Override - public void buttonClick( final Button.ClickEvent clickEvent ) - { - wizard.changeWindow( 1 ); - wizard.putForm(); - } - } ); - - configureOperations.addClickListener( new Button.ClickListener() - { - @Override - public void buttonClick( final Button.ClickEvent clickEvent ) - { - // if (wizard.getConfig().getProfiles().isEmpty()) - // { - // Notification notif = new Notification ("Please create profiles first"); - // notif.setDelayMsec(2000); - // notif.show(Page.getCurrent()); - // } - // else - // { - wizard.changeWindow( 2 ); - wizard.putForm(); - // } - } - } ); - - manageContainers.addClickListener( new Button.ClickListener() - { - @Override - public void buttonClick( final Button.ClickEvent clickEvent ) - { - boolean exist = false; - for ( Profile p : wizard.getConfig().getProfiles() ) - { - if ( !p.getOperations().isEmpty() ) - { - exist = true; - break; - } - } - wizard.changeWindow( 3 ); - wizard.putForm(); - } - } ); - - setContent( grid ); - } -} + public WelcomeStep (final Wizard wizard, final GenericPlugin genericPlugin) + { + setSizeFull (); + + GridLayout grid = new GridLayout (10, 6); + grid.setSpacing (true); + grid.setMargin (true); + grid.setSizeFull (); + + Label welcomeMsg = + new Label ("

Welcome to Generic Plugin, execute your custom commands on containers

"); + welcomeMsg.setContentMode (ContentMode.HTML); + grid.addComponent (welcomeMsg, 3, 1, 6, 2); + + Label logoImg = new Label (); + logoImg.setIcon (new FileResource (FileUtil.getFile (GenericPluginPortalModule.MODULE_IMAGE, this))); + logoImg.setContentMode (ContentMode.HTML); + logoImg.setHeight (150, Unit.PIXELS); + logoImg.setWidth (150, Unit.PIXELS); + grid.addComponent (logoImg, 1, 3, 2, 5); + + HorizontalLayout buttonsGrid = new HorizontalLayout (); + final Button createProfile = new Button ("Create profile"); + createProfile.addStyleName ("default"); + final Button configureOperations = new Button ("Configure operations"); + configureOperations.addStyleName ("default"); + final Button manageContainers = new Button ("Manage containers"); + manageContainers.addStyleName ("default"); + buttonsGrid.addComponent (createProfile); + buttonsGrid.addComponent (configureOperations); + buttonsGrid.addComponent (manageContainers); + grid.addComponent (buttonsGrid, 6, 4, 6, 4); + grid.setComponentAlignment (buttonsGrid, Alignment.BOTTOM_RIGHT); + + createProfile.addClickListener (new Button.ClickListener () + { + @Override + public void buttonClick (final Button.ClickEvent clickEvent) + { + wizard.changeWindow (1); + wizard.putForm (); + } + }); + + configureOperations.addClickListener (new Button.ClickListener () + { + @Override + public void buttonClick (final Button.ClickEvent clickEvent) + { + List profiles = genericPlugin.getProfiles(); + if (profiles.isEmpty ()) + { + show ("Please create profiles first"); + } + else + { + wizard.changeWindow (2); + wizard.putForm (); + } + } + }); + + manageContainers.addClickListener (new Button.ClickListener () + { + @Override + public void buttonClick (final Button.ClickEvent clickEvent) + { + List profiles = genericPlugin.getProfiles(); + if (profiles.isEmpty ()) + { + show ("Please create profiles first"); + } + else if (wizard.getManager().getEnvironments().isEmpty()) + { + show ("Please create environments first"); + } + else + { + boolean exists = false; + for (Profile p : profiles) + { + List operations = genericPlugin.getProfileOperations (p.getId()); + if (!operations.isEmpty()) + { + exists = true; + break; + } + } + if (!exists) + { + show ("Please create at least one operation on one of profiles"); + } + wizard.changeWindow (3); + wizard.putForm (); + } + } + }); + + setContent (grid); + } + + + private void show (String notification) + { + Notification notif = new Notification (notification); + notif.setDelayMsec (2000); + notif.show (Page.getCurrent()); + } +} \ No newline at end of file diff --git a/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/wizard/Wizard.java b/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/wizard/Wizard.java index ae6613900..1bc72c8cc 100644 --- a/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/wizard/Wizard.java +++ b/generic-plugin-ui/src/main/java/io/subutai/plugin/generic/ui/wizard/Wizard.java @@ -7,110 +7,95 @@ import io.subutai.core.environment.api.EnvironmentManager; import io.subutai.core.registry.api.TemplateRegistry; import io.subutai.plugin.generic.api.GenericPlugin; -import io.subutai.plugin.generic.api.GenericPluginConfiguration; public class Wizard { - private GenericPluginConfiguration config = new GenericPluginConfiguration(); - private final GridLayout grid; - private int step = 0; // 0 - welcome, 1 - create profile, 2 - configure operations, 3 - manage containers - private TemplateRegistry registry; - private EnvironmentManager manager; - private GenericPlugin genericPlugin; - - - public Wizard( TemplateRegistry registry, EnvironmentManager manager, GenericPlugin genericPlugin ) - { - this.registry = registry; - this.manager = manager; - this.genericPlugin = genericPlugin; - grid = new GridLayout( 1, 20 ); - grid.setMargin( true ); - grid.setSizeFull(); - - putForm(); - } - - - public void putForm() - { - grid.removeComponent( 0, 1 ); - Component component = null; - switch ( step ) - { - case ( 0 ): - { - component = new WelcomeStep( this ); - break; - } - case ( 1 ): - { - component = new ProfileCreationStep( this, genericPlugin ); - break; - } - case ( 2 ): - { - component = new ConfigureOperationStep( this, genericPlugin ); - break; - } - case ( 3 ): - { - component = new ManageContainersStep( this, genericPlugin ); - break; - } - default: - { - break; - } - } - if ( component != null ) - { - grid.addComponent( component, 0, 1, 0, 19 ); - } - } - - - protected void init() - { - step = 1; - config = new GenericPluginConfiguration(); - putForm(); - } - - - public void changeWindow( int newStep ) - { - this.step = newStep; - } - - - public Component getContent() - { - return this.grid; - } - - - public GenericPluginConfiguration getConfig() - { - return this.config; - } - - -/* public TemplateRegistry getRegistry() - { + private final GridLayout grid; + private int step = 0; // 0 - welcome, 1 - create profile, 2 - configure operations, 3 - manage containers + private TemplateRegistry registry; + private EnvironmentManager manager; + private GenericPlugin genericPlugin; + + + public Wizard (TemplateRegistry registry, EnvironmentManager manager, GenericPlugin genericPlugin) + { + this.registry = registry; + this.manager = manager; + this.genericPlugin = genericPlugin; + grid = new GridLayout (1, 20); + grid.setMargin (true); + grid.setSizeFull(); + + putForm(); + } + + + public void putForm() + { + grid.removeComponent (0, 1); + Component component = null; + switch (step) + { + case (0): + { + component = new WelcomeStep (this, genericPlugin); + break; + } + case (1): + { + component = new ProfileCreationStep (this, genericPlugin); + break; + } + case (2): + { + component = new ConfigureOperationStep (this, genericPlugin); + break; + } + case (3): + { + component = new ManageContainersStep (this, genericPlugin); + break; + } + default: + { + break; + } + } + if (component != null) + { + grid.addComponent (component, 0, 1, 0, 19); + } + } + + + public void changeWindow (int newStep) + { + this.step = newStep; + } + + + public Component getContent() + { + return this.grid; + } + + + + /* public TemplateRegistry getRegistry() + { return this.registry; }*/ - public EnvironmentManager getManager() - { - return this.manager; - } + public EnvironmentManager getManager() + { + return this.manager; + } - public GenericPlugin getGenericPlugin() - { - return this.genericPlugin; - } + public GenericPlugin getGenericPlugin() + { + return this.genericPlugin; + } } diff --git a/pom.xml b/pom.xml index 8c4ea4fa1..99e7a59d8 100644 --- a/pom.xml +++ b/pom.xml @@ -6,14 +6,14 @@ io.subutai generic-plugin - 4.0.0-RC2 + 4.0.0-RC3 Generic Plugin Parent Generic Plugin Parent pom - 4.0.0-RC2 + 4.0.0-RC3 3.0.2 18.0 2.3.0