Github user adriannieto commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/924#discussion_r42094254
  
    --- Diff: 
software/webapp/src/main/java/org/apache/brooklyn/entity/webapp/JavaWebAppSoftwareProcessImpl.java
 ---
    @@ -202,4 +208,75 @@ public String getHttpsSslKeystorePassword() {
             return (config == null) ? "" : config.getKeystorePassword();
         }
     
    +    @Override
    +    public void migrate(@EffectorParam(name = "locationSpec", description 
= "Location Spec", nullable = false) String locationSpec) {
    +
    +        if (ServiceStateLogic.getExpectedState(this) != Lifecycle.RUNNING) 
{
    +            // Is it necessary to check if the whole application is 
healthy?
    +            throw new RuntimeException("The entity needs to be healthy 
before the migration starts");
    +        }
    +
    +        if (getParent() != null && !getParent().equals(getApplication())) {
    +            /*
    +             * TODO: Allow nested entites to be migrated
    +             * If the entity has a parent different to the application 
root the migration cannot be done right now,
    +             * as it could lead into problems to deal with hierarchies 
like SameServerEntity -> Entity
    +             */
    +
    +            throw new RuntimeException("Nested entities cannot be migrated 
right now");
    +        }
    +
    +        // Retrieving the location from the catalog.
    +        Location newLocation = 
getManagementContext().getLocationRegistry().resolve(locationSpec);
    +
    +        // TODO: Find a better way to check if you're migrating an entity 
to the exactly same VM. This not always works.
    +        for(Location oldLocation : getLocations()){
    +            if(oldLocation.containsLocation(newLocation))
    +                throw new RuntimeException("You cannot migrate an entity 
to the same location");
    +        }
    +
    +        /*
    +         *   BUG: Currently the status is not propagated to the parent it 
should retrieve it from the children,
    +         *   but it seems that the descendant children status is not 
propagated properly
    +         */
    +        LOG.info("Migration process of " + this.getId() + " started.");
    +
    +        // When we have the new location, we free the resources of the 
current instance
    +        stop();
    +
    +        // Clearing old locations to remove the relationship with the 
previous instance
    +        clearLocations();
    +        addLocations(Lists.newArrayList(newLocation));
    +
    +        // Starting the new instance
    +        start(getLocations());
    +
    +        // Refresh all the dependant entities
    +        refreshDependantEntities();
    +
    +        LOG.info("Migration process of " + this.getId() + " finished.");
    +
    +    }
    +
    +    /*
    +     * TODO: Find a better way to refresh the application configuration.
    +     */
    +    private void refreshDependantEntities() {
    +
    +        // TODO: Refresh nested entities or find a way to propagate the 
restart properly.
    +        for (Entity entity : getApplication().getChildren()) {
    +
    +            // Restart any entity but the migrated one.
    +            if (entity instanceof Startable) {
    +                if(this.equals(entity)){
    +                    //The entity is sensors should rewired automatically 
on stop() + restart()
    +                }else{
    +                    // Restart the entity to fetch again all the 
dependencies (ie. attributeWhenReady ones)
    +                    ((Startable) entity).restart();
    --- End diff --
    
    Lets figure that there are some dependencies  (for example, some 
attributeWhenReady value) between the migrated entity and another one. 
    
    As Brooklyn doesn't have a dependency graph in the internal model, I have 
to just stop and start every Entity to refresh the sensors.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to