Skip to content

Commit

Permalink
#338 Store ModuleChanges outcome for Server Item and Module Items
Browse files Browse the repository at this point in the history
  • Loading branch information
kovax committed Feb 26, 2020
1 parent a9426ba commit 5b9c53e
Show file tree
Hide file tree
Showing 19 changed files with 392 additions and 99 deletions.
13 changes: 13 additions & 0 deletions dsl/src/main/kernel-module/Schema.groovy
Expand Up @@ -51,3 +51,16 @@ Schema('LoggerConfig', 0) {
}
}
}

Schema('ModuleChanges', 0) {
struct(name: 'ModuleChanges', useSequence: true) {
struct(name: 'ResourceChangeDetails', useSequence: true, multiplicity: '0..*') {
field(name:'ResourceName', type: 'string')
field(name:'ResourceVersion', type: 'string')
struct(name: 'ResourceChange', useSequence: true, multiplicity: '0..*') {
field(name:'SchemaName', type: 'string')
field(name:'ChangeType', type: 'string', values: ['IDENTICAL', 'NEW', 'UPDATED', 'OVERWRITTEN', 'SKIPPED', 'REMOVED'])
}
}
}
}
36 changes: 36 additions & 0 deletions dsl/src/main/kernel-module/resources/boot/OD/ModuleChanges_0.xsd
@@ -0,0 +1,36 @@
<?xml version='1.0' encoding='utf-8'?>
<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
<xs:element name='ModuleChanges'>
<xs:complexType>
<xs:sequence>
<xs:element name='ResourceChangeDetails' minOccurs='0' maxOccurs='unbounded'>
<xs:complexType>
<xs:sequence>
<xs:element name='ResourceName' type='xs:string' minOccurs='1' maxOccurs='1' />
<xs:element name='ResourceVersion' type='xs:string' minOccurs='1' maxOccurs='1' />
<xs:element name='ResourceChange' minOccurs='0' maxOccurs='unbounded'>
<xs:complexType>
<xs:sequence>
<xs:element name='SchemaName' type='xs:string' minOccurs='1' maxOccurs='1' />
<xs:element name='ChangeType' minOccurs='1' maxOccurs='1'>
<xs:simpleType>
<xs:restriction base='xs:string'>
<xs:enumeration value='IDENTICAL' />
<xs:enumeration value='NEW' />
<xs:enumeration value='UPDATED' />
<xs:enumeration value='OVERWRITTEN' />
<xs:enumeration value='SKIPPED' />
<xs:enumeration value='REMOVED' />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
1 change: 1 addition & 0 deletions dsl/src/main/kernel-module/resources/module.xml
Expand Up @@ -6,5 +6,6 @@
<SchemaResource name="SimpleElectonicSignature" version="0"/>
<SchemaResource name="SystemProperties" version="0"/>
<SchemaResource name="LoggerConfig" version="0"/>
<SchemaResource name="ModuleChanges" version="0"/>
</Imports>
</CristalModule>
Expand Up @@ -169,10 +169,10 @@ public Path create(AgentPath agentPath, boolean reset)
throws InvalidDataException, ObjectCannotBeUpdated, ObjectNotFoundException,
CannotManageException, ObjectAlreadyExistsException, InvalidCollectionModification, PersistencyException
{
log.info("create() - name:{}", name);

domainPath = new DomainPath(new DomainPath(initialPath), name);

log.info("create() - path:{}", domainPath);

if (domainPath.exists()) {
ItemPath domItem = domainPath.getItemPath();
if (!getItemPath().equals(domItem)) {
Expand Down
Expand Up @@ -244,12 +244,12 @@ protected DescriptionObject[] getBuiltInCollectionResource(BuiltInCollections co
ArrayList<DescriptionObject> retArr = new ArrayList<DescriptionObject>();

if (itemPath == null) {
log.warn("getBuiltInCollectionResource(actName:"+getName()+", collection:"+collection+") - itemPath is null! CANNOT resolve data in ClusterStorage");
log.debug("getBuiltInCollectionResource(actName:{}, collection:{}) - itemPath is null! CANNOT resolve data in ClusterStorage", getName(), collection);
return retArr.toArray(new DescriptionObject[0]);
//throw new InvalidDataException("actName:"+getName()+", collection:"+collection+" - itemPath is null! CANNOT resolve data in ClusterStorage");
}

log.info("getBuiltInCollectionResource(actName:"+getName()+") - Loading from collection:"+collection);
log.info("getBuiltInCollectionResource(actName:{}) - Loading from collection:{}", getName(), collection);

Dependency resColl;

Expand Down
Expand Up @@ -80,8 +80,7 @@ public class Activity extends WfVertex {
protected static final String XPATH_TOKEN = "xpath:";

/**
* vector of errors (Strings) that is constructed each time verify() is
* launched
* vector of errors (Strings) that is constructed each time verify() was launched
*/
protected Vector<String> mErrors;
/**
Expand Down Expand Up @@ -182,6 +181,30 @@ public String request(AgentPath agent,
byte[] attachment,
Object locker
)
throws AccessRightsException,
InvalidTransitionException,
InvalidDataException,
ObjectNotFoundException,
PersistencyException,
ObjectAlreadyExistsException,
ObjectCannotBeUpdated,
CannotManageException,
InvalidCollectionModification
{
boolean validateOutcome = Gateway.getProperties().getBoolean("Activity.validateOutcome", false);
return request(agent, delegate, itemPath, transitionID, requestData, attachmentType, attachment, validateOutcome, locker);
}

public String request(AgentPath agent,
AgentPath delegate,
ItemPath itemPath,
int transitionID,
String requestData,
String attachmentType,
byte[] attachment,
boolean validateOutcome,
Object locker
)
throws AccessRightsException,
InvalidTransitionException,
InvalidDataException,
Expand Down Expand Up @@ -218,42 +241,41 @@ else if (transition.getOutcome().isRequired())
setState(newState.getId());
setBuiltInProperty(AGENT_NAME, transition.getReservation(this, agent));

try {
History hist = getWf().getHistory(locker);
History hist = null;

if (storeOutcome) {
Schema schema = transition.getSchema(getProperties());
Outcome newOutcome = new Outcome(-1, outcome, schema);
// TODO: if we were ever going to validate outcomes on storage, it would be here.
//newOutcome.validateAndCheck();
// Enables PredefinedSteps instances to call Activity.request() during bootstrap
if (getParent() != null) hist = getWf().getHistory(locker);
else hist = new History(itemPath, locker);

String viewpoint = resolveViewpointName(newOutcome);
if (storeOutcome) {
Schema schema = transition.getSchema(getProperties());
Outcome newOutcome = new Outcome(-1, outcome, schema);

int eventID = hist.addEvent(agent, delegate, usedRole, getName(), getPath(), getType(),
schema, getStateMachine(), transitionID, viewpoint).getID();
newOutcome.setID(eventID);
// This is used by PredefinedStep executed during bootstrap
if (validateOutcome) newOutcome.validateAndCheck();

Gateway.getStorage().put(itemPath, newOutcome, locker);
if (attachment.length > 0) Gateway.getStorage().put(itemPath, new OutcomeAttachment(itemPath, newOutcome, attachmentType, attachment), locker);
String viewpoint = resolveViewpointName(newOutcome);

// update specific view if defined
if (!viewpoint.equals("last")) {
Gateway.getStorage().put(itemPath, new Viewpoint(itemPath, schema, viewpoint, eventID), locker);
}
int eventID = hist.addEvent(agent, delegate, usedRole, getName(), getPath(), getType(),
schema, getStateMachine(), transitionID, viewpoint).getID();
newOutcome.setID(eventID);

// update the default "last" view
Gateway.getStorage().put(itemPath, new Viewpoint(itemPath, schema, "last", eventID), locker);
Gateway.getStorage().put(itemPath, newOutcome, locker);
if (attachment.length > 0) Gateway.getStorage().put(itemPath, new OutcomeAttachment(itemPath, newOutcome, attachmentType, attachment), locker);

updateItemProperties(itemPath, newOutcome, locker);
}
else {
updateItemProperties(itemPath, null, locker);
hist.addEvent(agent, delegate, usedRole, getName(), getPath(), getType(), getStateMachine(), transitionID);
// update specific view if defined
if (!viewpoint.equals("last")) {
Gateway.getStorage().put(itemPath, new Viewpoint(itemPath, schema, viewpoint, eventID), locker);
}

// update the default "last" view
Gateway.getStorage().put(itemPath, new Viewpoint(itemPath, schema, "last", eventID), locker);

updateItemProperties(itemPath, newOutcome, locker);
}
catch (PersistencyException ex) {
log.error("", ex);
throw ex;
else {
updateItemProperties(itemPath, null, locker);
hist.addEvent(agent, delegate, usedRole, getName(), getPath(), getType(), getStateMachine(), transitionID);
}

if (newState.isFinished() && !(getBuiltInProperty(BREAKPOINT).equals(Boolean.TRUE) && !oldState.isFinished())) {
Expand Down
Expand Up @@ -37,6 +37,7 @@
import org.cristalise.kernel.common.CannotManageException;
import org.cristalise.kernel.common.InvalidCollectionModification;
import org.cristalise.kernel.common.InvalidDataException;
import org.cristalise.kernel.common.InvalidTransitionException;
import org.cristalise.kernel.common.ObjectAlreadyExistsException;
import org.cristalise.kernel.common.ObjectCannotBeUpdated;
import org.cristalise.kernel.common.ObjectNotFoundException;
Expand Down Expand Up @@ -127,7 +128,12 @@ public void setIsPredefined(boolean isPredefined) {

@Override
public String getType() {
return getName();
return this.getClass().getSimpleName();
}

@Override
public String getName() {
return this.getClass().getSimpleName();
}

static public String getPredefStepSchemaName(String stepName) {
Expand Down Expand Up @@ -285,4 +291,37 @@ public static void storeOutcomeEventAndViews(ItemPath itemPath, Outcome newOutco
Gateway.getStorage().put(itemPath, newNumberView, null);
}
}

/**
* Use this method to run a Predefined step during bootstrap
*
* @param agent
* @param itemPath
* @param requestData
* @return
* @throws AccessRightsException
* @throws InvalidTransitionException
* @throws InvalidDataException
* @throws ObjectNotFoundException
* @throws PersistencyException
* @throws ObjectAlreadyExistsException
* @throws ObjectCannotBeUpdated
* @throws CannotManageException
* @throws InvalidCollectionModification
*/
public String request(AgentPath agent, ItemPath itemPath, String requestData)
throws AccessRightsException,
InvalidTransitionException,
InvalidDataException,
ObjectNotFoundException,
PersistencyException,
ObjectAlreadyExistsException,
ObjectCannotBeUpdated,
CannotManageException,
InvalidCollectionModification
{
log.info("request({}) - Type:{}", itemPath, getType());
this.setActive(true);
return request(agent, agent, itemPath, PredefinedStep.DONE, requestData, null, new byte[0], true, null);
}
}
Expand Up @@ -34,7 +34,7 @@ public PredefinedStepContainer() {
createChildren();
}

//TODO make this complete configure from the given class
//TODO make this complete configure from the given classes
public void createChildren() {
predInit("AddDomainPath", "Adds a new path to this item in the LDAP domain tree", new AddDomainPath());
predInit("RemoveDomainPath", "Removes an existing path to this item from the LDAP domain tree", new RemoveDomainPath());
Expand All @@ -59,6 +59,8 @@ public void createChildren() {

predInit(UpdateCollectionsFromDescription.class.getSimpleName(), UpdateCollectionsFromDescription.description, new UpdateCollectionsFromDescription());
predInit(UpdateProperitesFromDescription.class.getSimpleName(), UpdateProperitesFromDescription.description, new UpdateProperitesFromDescription());

//UpdateImportReport class is not added to the container because it can only be used during bootstrap
}

public void predInit(Class<?> clazz, String description, PredefinedStep act) {
Expand Down
@@ -0,0 +1,65 @@
/**
* This file is part of the CRISTAL-iSE kernel.
* Copyright (c) 2001-2015 The CRISTAL Consortium. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*
* http://www.fsf.org/licensing/licenses/lgpl.html
*/
package org.cristalise.kernel.lifecycle.instance.predefined;

import static org.cristalise.kernel.graph.model.BuiltInVertexProperties.SCHEMA_NAME;

import org.cristalise.kernel.common.AccessRightsException;
import org.cristalise.kernel.common.CannotManageException;
import org.cristalise.kernel.common.InvalidCollectionModification;
import org.cristalise.kernel.common.InvalidDataException;
import org.cristalise.kernel.common.ObjectAlreadyExistsException;
import org.cristalise.kernel.common.ObjectCannotBeUpdated;
import org.cristalise.kernel.common.ObjectNotFoundException;
import org.cristalise.kernel.common.PersistencyException;
import org.cristalise.kernel.lookup.AgentPath;
import org.cristalise.kernel.lookup.ItemPath;

import lombok.extern.slf4j.Slf4j;

/**
* {@value #description}
*/
@Slf4j
public class UpdateImportReport extends PredefinedStep {

public static final String description = "Store the ModuleChanges report in Server Item and Modules. Can only be used during bootstrap.";

public UpdateImportReport() {
super();
setBuiltInProperty(SCHEMA_NAME, "ModuleChanges");
}

protected String runActivityLogic(AgentPath agent, ItemPath itemPath, int transitionID, String requestData, Object locker)
throws InvalidDataException,
InvalidCollectionModification,
ObjectAlreadyExistsException,
ObjectCannotBeUpdated,
ObjectNotFoundException,
PersistencyException,
CannotManageException,
AccessRightsException
{
log.debug("Called by {} on {}", agent.getAgentName(), itemPath);
// not much to do here
return requestData;
}
}

0 comments on commit 5b9c53e

Please sign in to comment.