You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by SalmasCM <sa...@criticalmass.com> on 2009/04/14 05:09:44 UTC

Workspaces in a cluster

I have several websites that have one admin server. Each website and the
admin server are cluster nodes. There are two workspaces, preview and
default. Changes are made to the preview workspace in the admin server and
then merged to the default workspace. 
I have the following problem. I make changes to the preview workspace on the
admin system and I verify that the workspace for the session is "preview" I
save the session and restart the server. I go to the website and verify that
I am in the default workspace and my changes are visible even though I did
not merge the data over! 
Am I using workspaces correctly? 
I did not think that changes in one workspace would show up in the second
one unless I merged them over? 
Also, if I have both systems running I would like a publish action from the
admin to show the changes to the website without having to restart the
server.Is this expectation reasonable?
 Also, though I need a preview workspace on the admin server, I do not need
it for the website. Is it okay to have preview and default workspaces for
the admin and only default for the websites or do I have to have the same
number of workspaces for all the nodes?

Regards
-- 
View this message in context: http://www.nabble.com/Workspaces-in-a-cluster-tp23032503p23032503.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: Workspaces in a cluster

Posted by SalmasCM <sa...@criticalmass.com>.
Cloning and then merging did the trick. 

Thanks so much.


Alexander Klimetschek wrote:
> 
> On Tue, Apr 14, 2009 at 5:11 PM, SalmasCM <sa...@criticalmass.com> wrote:
>> But in this case I will not be able to administer the websites
>> dynamically
>> from the admin server right? This is a requirement for my application so
>> a
>> local PM is probably not the right choice for me?
> 
> I don't understand: If you have the preview workspace only on the
> admin server and not on the other cluster nodes, this should be
> simple.
> 
>> I am still working on the problem that the  default workspace gets
>> populated
>> whenever I save the preview workspace. I know I am saving the right
>> session
>> since I print the workspace name In my repository config I have the path
>> for
>> each workspace as and they have different names so I am assuming that the
>> indexes are being created in the right spots.
>>
>> In my code I load the data into the default workspace of the admin
>> application and then create the preview workspace and merge it over.
>> Would
>> this cause problems? Should I be doing something different? What is the
>> difference between clone and merge? Should I load the data into the
>> default
>> workspace and then clone or merge it to preview?
>>
>> Here is my code
>> [...]
> 
> Your code creates a new workspace (I guess it is the "preview"
> workspace), and then copies data from that new workspace into all
> other workspaces (mergeToWorkspace() if clone == true). This looks
> weird. Note that node.merge() copies from the workspace given as
> parameter into the node (ie. the current workspace). IIRC, before
> doing a merge, you typically do a Workspace.clone() to copy over the
> intial state and then subsequently do update or merge.
> 
> Regards,
> Alex
> 
> -- 
> Alexander Klimetschek
> alexander.klimetschek@day.com
> 
> 

-- 
View this message in context: http://www.nabble.com/Workspaces-in-a-cluster-tp23032503p23062472.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: Workspaces in a cluster

Posted by Alexander Klimetschek <ak...@day.com>.
On Tue, Apr 14, 2009 at 5:11 PM, SalmasCM <sa...@criticalmass.com> wrote:
> But in this case I will not be able to administer the websites dynamically
> from the admin server right? This is a requirement for my application so a
> local PM is probably not the right choice for me?

I don't understand: If you have the preview workspace only on the
admin server and not on the other cluster nodes, this should be
simple.

> I am still working on the problem that the  default workspace gets populated
> whenever I save the preview workspace. I know I am saving the right session
> since I print the workspace name In my repository config I have the path for
> each workspace as and they have different names so I am assuming that the
> indexes are being created in the right spots.
>
> In my code I load the data into the default workspace of the admin
> application and then create the preview workspace and merge it over. Would
> this cause problems? Should I be doing something different? What is the
> difference between clone and merge? Should I load the data into the default
> workspace and then clone or merge it to preview?
>
> Here is my code
> [...]

Your code creates a new workspace (I guess it is the "preview"
workspace), and then copies data from that new workspace into all
other workspaces (mergeToWorkspace() if clone == true). This looks
weird. Note that node.merge() copies from the workspace given as
parameter into the node (ie. the current workspace). IIRC, before
doing a merge, you typically do a Workspace.clone() to copy over the
intial state and then subsequently do update or merge.

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com

Re: Workspaces in a cluster

Posted by SalmasCM <sa...@criticalmass.com>.
But in this case I will not be able to administer the websites dynamically
from the admin server right? This is a requirement for my application so a
local PM is probably not the right choice for me?

I am still working on the problem that the  default workspace gets populated
whenever I save the preview workspace. I know I am saving the right session
since I print the workspace name In my repository config I have the path for
each workspace as and they have different names so I am assuming that the
indexes are being created in the right spots.

In my code I load the data into the default workspace of the admin
application and then create the preview workspace and merge it over. Would
this cause problems? Should I be doing something different? What is the
difference between clone and merge? Should I load the data into the default
workspace and then clone or merge it to preview?

Here is my code

public static void createWorkspace(String name,boolean
clone,ConnectionManager manager) {
      Workspace workspace = getSession().getWorkspace();

      JackrabbitWorkspace jws = (JackrabbitWorkspace) workspace;
      try {
          Node currentRoot = JCRUtil.getSession().getRootNode();
          //String srcAbsPath = currentRoot.getCorrespondingNodePath(srcWS);
         String[] workspaces = jws.getAccessibleWorkspaceNames();
         boolean hasWS = false;

         for (int i = 0; i < workspaces.length; i++) {
            if (workspaces[i].equals(name)) {
               hasWS = true;
               break;
            }
         }
         if (!hasWS) {
                if (jws != null && currentRoot != null) {
                    synchronized (jws) {
            jws.createWorkspace(name);
            if (clone) {
                NodeIterator nodes = currentRoot.getNodes();

                while (nodes.hasNext()) {
                    Node next = nodes.nextNode();
                    String nodeName = next.getName();
                    if (nodeName.indexOf("jcr:")==-1) {
                        getInstance().logger.info("merging " + nodeName);
                        JCRUtil.mergeToWorkspace(next, name);
                    } else {
                        getInstance().logger.info("skipping " + nodeName);
                    }
                }
            }
         }
                }
            }
         JCRUtil.saveSession();
      } catch (AccessDeniedException e) {
            getInstance().logger.error("RepositoryException
JCRUtil:createWorkspace ", e);
      } catch (NoSuchWorkspaceException e) {
            getInstance().logger.error("NoSuchWorkspaceException
JCRUtil:createWorkspace ", e);
      } catch (ConstraintViolationException e) {
            getInstance().logger.error("ConstraintViolationException
JCRUtil:createWorkspace ", e);
      } catch (VersionException e) {
            getInstance().logger.error("VersionException
JCRUtil:createWorkspace ", e);
      } catch (PathNotFoundException e) {
            getInstance().logger.error("PathNotFoundException
JCRUtil:createWorkspace ", e);
      } catch (ItemExistsException e) {
            getInstance().logger.error("ItemExistsException
JCRUtil:createWorkspace ", e);
      } catch (LockException e) {
            getInstance().logger.error("LockException
JCRUtil:createWorkspace ", e);
      } catch (RepositoryException e) {
            getInstance().logger.error("RepositoryException
JCRUtil:createWorkspace ", e);
      }
   }

   public static void mergeToWorkspace(Node node,String wsName) {
       try {
           if (node!=null) {
               synchronized(node) {
               NodeIterator failedNodes = node.merge(wsName, true);
               while (failedNodes.hasNext()) {
                   getInstance().logger.error("" +
failedNodes.nextNode().getName());
               }
               }
        }
    } catch (NoSuchWorkspaceException e) {
        getInstance().logger.error("mergeToProduction
:NoSuchWorkspaceException",e);
    } catch (AccessDeniedException e) {
        getInstance().logger.error("mergeToProduction
:AccessDeniedException",e);
    } catch (MergeException e) {
        getInstance().logger.error("mergeToProduction :MergeException",e);
    } catch (LockException e) {
        getInstance().logger.error("mergeToProduction :LockException",e);
    } catch (InvalidItemStateException e) {
        getInstance().logger.error("mergeToProduction
:InvalidItemStateException",e);
    } catch (RepositoryException e) {
        getInstance().logger.error("mergeToProduction
:RepositoryException",e);
    }
   }

Alexander Klimetschek wrote:
> 
> On Tue, Apr 14, 2009 at 3:54 PM, SalmasCM <sa...@criticalmass.com> wrote:
>> Thanks Alexander. I think its a bug in my code too. It helps to get
>> validation that I have the right approach.
>> What do you mean by a 'local' PM? I have a bundle PM for my websites and
>> don't say anything about it being local or not.
> 
> "Local" means that it is not part of the cluster. This typically means
> not to use the shared database for the clustering, but rather an
> embedded db like derby. This will also be faster.
> 
> Regards,
> Alex
> 
> -- 
> Alexander Klimetschek
> alexander.klimetschek@day.com
> 
> 

-- 
View this message in context: http://www.nabble.com/Workspaces-in-a-cluster-tp23032503p23041379.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: Workspaces in a cluster

Posted by Alexander Klimetschek <ak...@day.com>.
On Tue, Apr 14, 2009 at 3:54 PM, SalmasCM <sa...@criticalmass.com> wrote:
> Thanks Alexander. I think its a bug in my code too. It helps to get
> validation that I have the right approach.
> What do you mean by a 'local' PM? I have a bundle PM for my websites and
> don't say anything about it being local or not.

"Local" means that it is not part of the cluster. This typically means
not to use the shared database for the clustering, but rather an
embedded db like derby. This will also be faster.

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com

Re: Workspaces in a cluster

Posted by SalmasCM <sa...@criticalmass.com>.
Thanks Alexander. I think its a bug in my code too. It helps to get
validation that I have the right approach. 
What do you mean by a 'local' PM? I have a bundle PM for my websites and
don't say anything about it being local or not. 

Regards


Alexander Klimetschek wrote:
> 
> On Tue, Apr 14, 2009 at 5:09 AM, SalmasCM <sa...@criticalmass.com> wrote:
>> I have several websites that have one admin server. Each website and the
>> admin server are cluster nodes. There are two workspaces, preview and
>> default. Changes are made to the preview workspace in the admin server
>> and
>> then merged to the default workspace.
>> I have the following problem. I make changes to the preview workspace on
>> the
>> admin system and I verify that the workspace for the session is "preview"
>> I
>> save the session and restart the server. I go to the website and verify
>> that
>> I am in the default workspace and my changes are visible even though I
>> did
>> not merge the data over!
>> Am I using workspaces correctly?
> 
> This behaviour is not expected, there is no automatic merging unless
> you call merge. It looks like there is some error with the cluster
> setup or your application code.
> 
> Btw, you don't have to restart your server to see the new data on
> another workspace or cluster node.
> 
>> I did not think that changes in one workspace would show up in the second
>> one unless I merged them over?
> 
> Right.
> 
>> Also, if I have both systems running I would like a publish action from
>> the
>> admin to show the changes to the website without having to restart the
>> server.Is this expectation reasonable?
> 
> Yes.
> 
>>  Also, though I need a preview workspace on the admin server, I do not
>> need
>> it for the website. Is it okay to have preview and default workspaces for
>> the admin and only default for the websites or do I have to have the same
>> number of workspaces for all the nodes?
> 
> Not 100% sure, but if you only use a "local" PM for the preview
> workspace, which should not get replicated in the cluster, and if on
> the live system no one reads from the preview workspace, this should
> work.
> 
> Regards,
> Alex
> 
> -- 
> Alexander Klimetschek
> alexander.klimetschek@day.com
> 
> 

-- 
View this message in context: http://www.nabble.com/Workspaces-in-a-cluster-tp23032503p23039867.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: Workspaces in a cluster

Posted by Alexander Klimetschek <ak...@day.com>.
On Tue, Apr 14, 2009 at 5:09 AM, SalmasCM <sa...@criticalmass.com> wrote:
> I have several websites that have one admin server. Each website and the
> admin server are cluster nodes. There are two workspaces, preview and
> default. Changes are made to the preview workspace in the admin server and
> then merged to the default workspace.
> I have the following problem. I make changes to the preview workspace on the
> admin system and I verify that the workspace for the session is "preview" I
> save the session and restart the server. I go to the website and verify that
> I am in the default workspace and my changes are visible even though I did
> not merge the data over!
> Am I using workspaces correctly?

This behaviour is not expected, there is no automatic merging unless
you call merge. It looks like there is some error with the cluster
setup or your application code.

Btw, you don't have to restart your server to see the new data on
another workspace or cluster node.

> I did not think that changes in one workspace would show up in the second
> one unless I merged them over?

Right.

> Also, if I have both systems running I would like a publish action from the
> admin to show the changes to the website without having to restart the
> server.Is this expectation reasonable?

Yes.

>  Also, though I need a preview workspace on the admin server, I do not need
> it for the website. Is it okay to have preview and default workspaces for
> the admin and only default for the websites or do I have to have the same
> number of workspaces for all the nodes?

Not 100% sure, but if you only use a "local" PM for the preview
workspace, which should not get replicated in the cluster, and if on
the live system no one reads from the preview workspace, this should
work.

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com