Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SWITCHYARD-2580] Make it possible to don't startup service bindings automatically #678

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
public interface BindingModel extends TypedModel {

/** The "binding" name. */
public static final String BINDING = "binding";
public static final String BINDING = "binding";

/** The "autoStartup" name. */
public static final String AUTO_STARTUP = "autoStartup";

/** The "disableAutoStartupBindings" domain property */
public static final String DISABLE_AUTO_STARTUP_BINDINGS = "disableAutoStartupBindings";

/**
* Gets the name <b>attribute</b> of this Model (<i>not</i> the name of the wrapped Configuration).
Expand Down Expand Up @@ -106,4 +112,19 @@ public interface BindingModel extends TypedModel {
* @return this BindingModel (useful for chaining)
*/
public BindingModel setMessageComposer(MessageComposerModel model);

/**
* Should this binding startup automatically after deployment?
* @return true if should, false in other case
*/
public boolean isAutoStartup();

/**
* Sets the autoStartup attribute
*
* @param autoStartup the autoStartup attribute
* @return this BindingModel (useful for chaining)
*/
public BindingModel setAutoStartup(boolean autoStartup);

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package org.switchyard.config.model.composite;

import org.switchyard.config.model.Model;
import org.switchyard.config.model.switchyard.ManagementModel;
import org.switchyard.config.model.switchyard.ThrottlingModel;

/**
Expand All @@ -38,4 +39,20 @@ public interface ExtensionsModel extends Model {
* @return this ExtensionsModel (useful for chaining)
*/
public ExtensionsModel setThrottling(ThrottlingModel throttling);

/**
* Gets the child management model.
*
* @return the child management model.
*/
public ManagementModel getManagement();

/**
* Sets the child management model.
*
* @param management child management model
* @return this ExtensionModel (useful for chaining)
*/
public ExtensionsModel setManagement(ManagementModel management);

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
import org.switchyard.config.model.Model;
import org.switchyard.config.model.composer.ContextMapperModel;
import org.switchyard.config.model.composer.MessageComposerModel;
import org.switchyard.config.model.composite.BindingModel;
import org.switchyard.config.model.composite.CompositeReferenceModel;
import org.switchyard.config.model.composite.CompositeServiceModel;
import org.switchyard.config.model.composite.SCANamespace;
import org.switchyard.config.model.composite.*;
import org.switchyard.config.model.selector.OperationSelectorModel;

/**
Expand Down Expand Up @@ -178,6 +175,57 @@ public BindingModel setMessageComposer(MessageComposerModel model) {
return this;
}

/**
* {@inheritDoc}
*/
@Override
public boolean isAutoStartup() {
// In case of reference binding this attribute does not make sense
if (isReferenceBinding())
return true;

//First retrieve disableAutoStartupBindings domain property
boolean disableAutoStartupBindings = false;
try {
String domainProperty = ((CompositeServiceModel) getModelParent())
.getComposite()
.getSwitchYard()
.getDomain()
.getProperties()
.getProperty(DISABLE_AUTO_STARTUP_BINDINGS)
.getValue();

disableAutoStartupBindings = Boolean.valueOf(domainProperty);
} catch (NullPointerException ignored) { } // In case when some of models or domain property are not defined.

if (disableAutoStartupBindings)
return false;

// Next retrieve autoStartupBindings attribute from Management extension
boolean autoStartupBindings = true;
try {
autoStartupBindings = ((CompositeServiceModel) getModelParent())
.getExtensions()
.getManagement()
.isAutoStartupBindings();
} catch (NullPointerException ignored) { } // In case when some of Extensions/Management models are not defined.

if (!autoStartupBindings)
return false;

String autoStartup = getModelAttribute(AUTO_STARTUP);
return autoStartup == null || "true".equals(autoStartup);
}

/**
* {@inheritDoc}
*/
@Override
public BindingModel setAutoStartup(boolean autoStartup) {
setModelAttribute(AUTO_STARTUP, String.valueOf(autoStartup));
return this;
}

@Override
public boolean isServiceBinding() {
return (getModelParent() instanceof CompositeServiceModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.switchyard.config.model.Descriptor;
import org.switchyard.config.model.composite.ExtensionsModel;
import org.switchyard.config.model.composite.SCANamespace;
import org.switchyard.config.model.switchyard.ManagementModel;
import org.switchyard.config.model.switchyard.ThrottlingModel;

/**
Expand All @@ -29,6 +30,7 @@
public class V1ExtensionsModel extends BaseModel implements ExtensionsModel {

private ThrottlingModel _throttling;
private ManagementModel _management;

/**
* Constructs a new V1ExtensionsModel.
Expand Down Expand Up @@ -61,4 +63,19 @@ public ExtensionsModel setThrottling(ThrottlingModel throttling) {
return this;
}

@Override
public ManagementModel getManagement() {
if (_management == null) {
_management = (ManagementModel) getFirstChildModel(ManagementModel.MANAGEMENT);
}
return _management;
}

@Override
public ExtensionsModel setManagement(ManagementModel management) {
setChildModel(management);
_management = management;
return this;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.switchyard.config.model.switchyard;

import org.switchyard.config.model.Model;

/**
* Additional service management configuration model
*/
public interface ManagementModel extends Model {

/** The "management" name. */
public static final String MANAGEMENT = "management";

/** The "autoStartupBindings" attribute. */
public static final String AUTO_STARTUP_BINDINGS = "autoStartupBindings";

/**
* Should service bindings startup automatically after deployment
*
* @return true if should, false in other case
*/
public boolean isAutoStartupBindings();

/**
* Sets the autoStartupBindings attribute
*
* @param autoStartupBindings the autoStartupBindings attribute
* @return this ManagementModel (useful for chaining)
*/
public ManagementModel setAutoStartupBindings(boolean autoStartupBindings);

}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public interface ThrottlingModel extends Model {

/**
* Sets the maxRequests attribute.
* @param maxRequests the timePeriod attribute
* @param maxRequests the maxRequests attribute
* @return this ThrottlingModel (useful for chaining)
*/
public ThrottlingModel setMaxRequests(int maxRequests);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.switchyard.config.model.switchyard.v1;

import org.switchyard.config.Configuration;
import org.switchyard.config.model.BaseModel;
import org.switchyard.config.model.Descriptor;
import org.switchyard.config.model.composite.CompositeServiceModel;
import org.switchyard.config.model.composite.ExtensionsModel;
import org.switchyard.config.model.switchyard.ManagementModel;

/**
* A version 1 ManagementModel
*/
public class V1ManagementModel extends BaseModel implements ManagementModel {

/**
* Constructs a new V1ManagementModel.
* @param namespace namespace
*/
protected V1ManagementModel(String namespace, String name) {
super(namespace, name);
}

/**
* Constructs a new V1ManagementModel with the specified Configuration and Descriptor.
* @param config the Configuration
* @param desc the Descriptor
*/
protected V1ManagementModel(Configuration config, Descriptor desc) {
super(config, desc);
}

/**
* {@inheritDoc}
*/
@Override
public boolean isAutoStartupBindings() {
String autoStartupBindings = getModelAttribute(AUTO_STARTUP_BINDINGS);
return autoStartupBindings == null || "true".equals(autoStartupBindings);
}

/**
* {@inheritDoc}
*/
@Override
public ManagementModel setAutoStartupBindings(boolean autoStartupBindings) {
setModelAttribute(AUTO_STARTUP_BINDINGS, String.valueOf(autoStartupBindings));
return this;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@
import org.switchyard.config.model.selector.v1.V1RegexOperationSelectorModel;
import org.switchyard.config.model.selector.v1.V1StaticOperationSelectorModel;
import org.switchyard.config.model.selector.v1.V1XPathOperationSelectorModel;
import org.switchyard.config.model.switchyard.ArtifactModel;
import org.switchyard.config.model.switchyard.ArtifactsModel;
import org.switchyard.config.model.switchyard.EsbInterfaceModel;
import org.switchyard.config.model.switchyard.SwitchYardModel;
import org.switchyard.config.model.switchyard.ThrottlingModel;
import org.switchyard.config.model.switchyard.*;
import org.switchyard.config.model.transform.TransformsModel;
import org.switchyard.config.model.transform.v1.V1TransformsModel;
import org.switchyard.config.model.validate.ValidatesModel;
Expand Down Expand Up @@ -107,6 +103,8 @@ public Model read(Configuration config) {
return new V1ResourceDetailModel(config, desc);
} else if (name.equals(ThrottlingModel.THROTTLING)) {
return new V1ThrottlingModel(config, desc);
} else if (name.equals(ManagementModel.MANAGEMENT)) {
return new V1ManagementModel(config, desc);
} else if (name.equals(INTERFACE_ESB)) {
return new V1EsbInterfaceModel(config, desc);
} else if (name.startsWith(OperationSelectorModel.OPERATION_SELECTOR)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
- See the License for the specific language governing permissions and
- limitations under the License.
-->
<schema xmlns="http://www.w3.org/2001/XMLSchema"
<schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="urn:switchyard-config:switchyard:1.0"
xmlns:swyd="urn:switchyard-config:switchyard:1.0"
xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912"
Expand All @@ -36,7 +36,9 @@
<element name="binding.switchyard" type="swyd:SwitchYardBindingType" substitutionGroup="sca:binding" abstract="true"/>
<complexType name="SwitchYardBindingType" abstract="true">
<complexContent>
<extension base="sca:Binding"/>
<extension base="sca:Binding">
<attribute name="autoStartup" type="boolean" default="true" use="optional"/>
</extension>
</complexContent>
</complexType>

Expand Down Expand Up @@ -259,7 +261,13 @@
</annotation>
</attribute>
</complexType>


<!-- additional service management extension -->
<element name="management" type="swyd:ManagementType"/>
<complexType name="ManagementType">
<attribute name="autoStartupBindings" type="boolean" default="true"/>
</complexType>

<!-- binding.sca extensions -->
<attribute name="target" type="string"/>
<attribute name="targetNamespace" type="string"/>
Expand All @@ -268,7 +276,7 @@

<!-- service and reference extensions -->
<attribute name="security" type="string"/>

<!-- Support for using ${property} values in non-string content -->
<simpleType name="propInteger">
<union memberTypes="integer swyd:propertyValue"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
<element name="binding.switchyard" type="swyd:SwitchYardBindingType" substitutionGroup="sca:binding" abstract="true"/>
<complexType name="SwitchYardBindingType" abstract="true">
<complexContent>
<extension base="sca:Binding"/>
<extension base="sca:Binding">
<attribute name="autoStartup" type="boolean" default="true" use="optional"/>
</extension>
</complexContent>
</complexType>

Expand Down Expand Up @@ -259,7 +261,13 @@
</annotation>
</attribute>
</complexType>


<!-- additional service management extension -->
<element name="management" type="swyd:ManagementType"/>
<complexType name="ManagementType">
<attribute name="autoStartupBindings" type="boolean" default="true"/>
</complexType>

<!-- binding.sca extensions -->
<attribute name="target" type="string"/>
<attribute name="targetNamespace" type="string"/>
Expand All @@ -268,7 +276,7 @@

<!-- service and reference extensions -->
<attribute name="security" type="string"/>

<!-- Support for using ${property} values in non-string content -->
<simpleType name="propInteger">
<union memberTypes="integer swyd:propertyValue"/>
Expand Down
Loading