Skip to content

Commit

Permalink
TEIID-2196: adding validation to check the vdb name and version in al…
Browse files Browse the repository at this point in the history
…l the admin calls
  • Loading branch information
rareddy committed Oct 15, 2012
1 parent 7d21846 commit 8d91df9
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
Expand Up @@ -36,6 +36,10 @@
import org.jboss.as.controller.descriptions.DescriptionProvider;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.dmr.ModelNode;
import org.jboss.msc.service.ServiceController;
import org.teiid.adminapi.VDB;
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.deployers.VDBRepository;

public abstract class BaseOperationHandler<T> implements DescriptionProvider, OperationStepHandler {
private static final String DESCRIBE = ".describe"; //$NON-NLS-1$
Expand Down Expand Up @@ -101,4 +105,14 @@ protected String getParameterDescription(ResourceBundle bundle, String paramName

protected void describeParameters(@SuppressWarnings("unused") ModelNode operationNode, @SuppressWarnings("unused")ResourceBundle bundle) {
}

boolean isValidVDB(OperationContext context, String vdbName, int vdbVersion) {
ServiceController<?> sc = context.getServiceRegistry(false).getRequiredService(TeiidServiceNames.VDB_REPO);
VDBRepository repo = VDBRepository.class.cast(sc.getValue());
VDBMetaData vdb = repo.getLiveVDB(vdbName, vdbVersion);
if (vdb == null || (vdb.getStatus() != VDB.Status.ACTIVE)) {
return false;
}
return true;
}
}
Expand Up @@ -96,5 +96,7 @@ public static enum Event implements BundleUtil.Event {
TEIID50093,
TEIID50094,
TEIID50095,
TEIID50096,
TEIID50097
}
}
Expand Up @@ -214,6 +214,9 @@ protected void executeOperation(OperationContext context, DQPCore engine, ModelN
if (operation.hasDefined(OperationsConstants.VDB_VERSION) && operation.hasDefined(OperationsConstants.VDB_NAME)) {
vdbName = operation.get(OperationsConstants.VDB_NAME).asString();
version = operation.get(OperationsConstants.VDB_VERSION).asInt();
if (!isValidVDB(context, vdbName, version)) {
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50096, vdbName, version)));
}
filter = true;
}

Expand Down Expand Up @@ -347,7 +350,10 @@ protected void executeOperation(OperationContext context, DQPCore engine, ModelN
ModelNode result = context.getResult();
String vdbName = operation.get(OperationsConstants.VDB_NAME).asString();
int vdbVersion = operation.get(OperationsConstants.VDB_VERSION).asInt();
for (TransportService t: this.transports) {
if (!isValidVDB(context, vdbName, vdbVersion)) {
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50096, vdbName, vdbVersion)));
}
for (TransportService t: this.transports) {
List<RequestMetadata> requests = t.getRequestsUsingVDB(vdbName,vdbVersion);
for (RequestMetadata request:requests) {
if (request.sourceRequest()) {
Expand Down Expand Up @@ -563,6 +569,9 @@ protected void executeOperation(OperationContext context, SessionAwareCache cach
if (operation.hasDefined(OperationsConstants.VDB_NAME) && operation.hasDefined(OperationsConstants.VDB_VERSION)) {
String vdbName = operation.get(OperationsConstants.VDB_NAME).asString();
int vdbVersion = operation.get(OperationsConstants.VDB_VERSION).asInt();
if (!isValidVDB(context, vdbName, vdbVersion)) {
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50096, vdbName, vdbVersion)));
}
LogManager.logInfo(LogConstants.CTX_DQP, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50005, cacheType, vdbName, vdbVersion));
cache.clearForVDB(vdbName, vdbVersion);
}
Expand Down Expand Up @@ -746,6 +755,10 @@ protected void executeOperation(OperationContext context, DQPCore engine, ModelN
String sql = operation.get(OperationsConstants.SQL_QUERY).asString();
int timeout = operation.get(OperationsConstants.TIMEOUT_IN_MILLI).asInt();

if (!isValidVDB(context, vdbName, vdbVersion)) {
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50096, vdbName, vdbVersion)));
}

result.set(executeQuery(vdbName, vdbVersion, sql, timeout, new ModelNode()));
}

Expand Down Expand Up @@ -924,7 +937,12 @@ protected void executeOperation(OperationContext context, VDBRepository repo, Mo
int vdbVersion = operation.get(OperationsConstants.VDB_VERSION).asInt();

VDBMetaData vdb = repo.getVDB(vdbName, vdbVersion);
VDBMetadataMapper.INSTANCE.wrap(vdb, result);
if (vdb != null) {
VDBMetadataMapper.INSTANCE.wrap(vdb, result);
}
else {
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50096, vdbName, vdbVersion)));
}
}

protected void describeParameters(ModelNode operationNode, ResourceBundle bundle) {
Expand Down Expand Up @@ -970,15 +988,15 @@ protected void executeOperation(OperationContext context, VDBRepository repo, Mo
String vdbName = operation.get(OperationsConstants.VDB_NAME).asString();
int vdbVersion = operation.get(OperationsConstants.VDB_VERSION).asInt();
String modelName = operation.get(OperationsConstants.MODEL_NAME).asString();

VDBMetaData vdb = repo.getLiveVDB(vdbName, vdbVersion);
if (vdb == null || (vdb.getStatus() != VDB.Status.ACTIVE)) {
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString("no_vdb_found", vdbName, vdbVersion))); //$NON-NLS-1$
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50096, vdbName, vdbVersion)));
}

EnumSet<SchemaObjectType> schemaTypes = null;
if (vdb.getModel(modelName) == null){
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.getString("no_model_found", vdbName, vdbVersion, modelName))); //$NON-NLS-1$
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50097, vdbName, vdbVersion, modelName)));
}

if (operation.hasDefined(OperationsConstants.ENTITY_TYPE)) {
Expand Down Expand Up @@ -1129,6 +1147,10 @@ public RuntimeVDB getService(OperationContext context, PathAddress pathAddress,

String vdbName = operation.get(OperationsConstants.VDB_NAME).asString();
int vdbVersion = operation.get(OperationsConstants.VDB_VERSION).asInt();

if (!isValidVDB(context, vdbName, vdbVersion)) {
throw new OperationFailedException(new ModelNode().set(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50096, vdbName, vdbVersion)));
}

ServiceController<?> sc = context.getServiceRegistry(false).getRequiredService(TeiidServiceNames.vdbServiceName(vdbName, vdbVersion));
return RuntimeVDB.class.cast(sc.getValue());
Expand Down Expand Up @@ -1520,5 +1542,5 @@ protected void describeParameters(ModelNode operationNode, ResourceBundle bundle
reply.get(TYPE).set(ModelType.LIST);
// this is incomplete
reply.get(VALUE_TYPE).set(ModelType.STRING);
}
}
}
Expand Up @@ -73,6 +73,7 @@ TEIID50093=Cache factory not found; Make sure the Infinispan based cache factory
TEIID50094=Resultset cache configured without the Infinispan's Cache Container name. Check and provide <resultset-cache infinispan-container="{name}"/> in configuration.
TEIID50095=PreparedPlan cache configured without the Infinispan's Cache Container name. Check and provide <preparedplan-cache infinispan-container="{name}"/> in configuration.
wrong_vdb= Wrong VDB name and/or version supplied, or VDB is not active, or not available.
TEIID50096=No VDB found with name {0}.{1} or VDB not in ACTIVE status. Please check the supplied values for errors. Use "list-vdbs" to see all the valid deployed VDBs.

# subsystem description
teiid.add = Add the Teiid Subsystem
Expand Down Expand Up @@ -189,8 +190,7 @@ TEIID50005=Clearing cache {0} for vdb {1}.{2}
TEIID50021=VDB {0}.{1} deployed in inactive state due to unavailability of data sources {2}
TEIID50016=Invalid VDB file deployment failed {0}
TEIID50078=Translator not found {0}
no_vdb_found=VDB {0}.{1} not found or VDB is not in ACTIVE status
no_model_found= VDB {0}.{1} does not have model with name {2}.
TEIID50097= VDB {0}.{1} does not have model with name {2}.

remove.reply.describe=remove service
remove.describe=remove service
Expand Down

0 comments on commit 8d91df9

Please sign in to comment.