use of org.wso2.siddhi.query.api.execution.query.input.store.Store in project siddhi by wso2.
the class DefineTableTestCase method testQuery20.
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testQuery20() {
log.info("testTableDefinition20 - Table w/ ref to an undefined store");
Map<String, String> systemConfigs = new HashMap<>();
systemConfigs.put("test1.uri", "http://localhost");
InMemoryConfigManager inMemoryConfigManager = new InMemoryConfigManager(null, systemConfigs);
inMemoryConfigManager.extractSystemConfigs("test2");
SiddhiManager siddhiManager = new SiddhiManager();
siddhiManager.setConfigManager(inMemoryConfigManager);
siddhiManager.setExtension("store:test", TestStore.class);
String siddhiApp = "" + "@store(ref='test2', uri='http://localhost:8080', table.name ='Foo')" + "define table testTable (symbol string, price int, volume float); ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.execution.query.input.store.Store in project siddhi by wso2.
the class DefineTableTestCase method testQuery17.
@Test
public void testQuery17() throws InterruptedException {
log.info("testTableDefinition17 - Table w/o ref");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "define stream StockStream(symbol string, price int, volume float);" + "@store(type='test', uri='http://localhost:8080')" + "define table testStore (symbol string, price int, volume float); ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.shutdown();
Map<String, String> expectedSystemConfigs = new HashMap<>();
expectedSystemConfigs.put("type", "test");
expectedSystemConfigs.put("uri", "http://localhost:8080");
AssertJUnit.assertEquals("Test store initialization failure", expectedSystemConfigs, TestStore.systemConfigs);
}
use of org.wso2.siddhi.query.api.execution.query.input.store.Store in project siddhi by wso2.
the class DefineTableTestCase method testQuery19.
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testQuery19() {
log.info("testTableDefinition19 - Table w/ ref w/o type");
Map<String, String> systemConfigs = new HashMap<>();
systemConfigs.put("test1.uri", "http://localhost");
InMemoryConfigManager inMemoryConfigManager = new InMemoryConfigManager(null, systemConfigs);
inMemoryConfigManager.extractSystemConfigs("test1");
SiddhiManager siddhiManager = new SiddhiManager();
siddhiManager.setConfigManager(inMemoryConfigManager);
siddhiManager.setExtension("store:test", TestStore.class);
String siddhiApp = "" + "@store(ref='test1', uri='http://localhost:8080', table.name ='Foo')" + "define table testTable (symbol string, price int, volume float); ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.execution.query.input.store.Store in project siddhi by wso2.
the class LossyFrequentWindowProcessor method process.
@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
synchronized (this) {
long currentTime = siddhiAppContext.getTimestampGenerator().currentTime();
StreamEvent streamEvent = streamEventChunk.getFirst();
streamEventChunk.clear();
while (streamEvent != null) {
StreamEvent next = streamEvent.getNext();
streamEvent.setNext(null);
StreamEvent clonedEvent = streamEventCloner.copyStreamEvent(streamEvent);
clonedEvent.setType(StreamEvent.Type.EXPIRED);
totalCount++;
if (totalCount != 1) {
currentBucketId = Math.ceil(totalCount / windowWidth);
}
String currentKey = generateKey(streamEvent);
StreamEvent oldEvent = map.put(currentKey, clonedEvent);
if (oldEvent != null) {
// this event is already in the store
countMap.put(currentKey, countMap.get(currentKey).incrementCount());
} else {
// This is a new event
LossyCount lCount;
lCount = new LossyCount(1, (int) currentBucketId - 1);
countMap.put(currentKey, lCount);
}
// calculating all the events in the system which match the
// requirement provided by the user
List<String> keys = new ArrayList<String>();
keys.addAll(countMap.keySet());
for (String key : keys) {
LossyCount lossyCount = countMap.get(key);
if (lossyCount.getCount() >= ((support - error) * totalCount)) {
// among the selected events, if the newly arrive event is there we mark it as an inEvent
if (key.equals(currentKey)) {
streamEventChunk.add(streamEvent);
}
}
}
if (totalCount % windowWidth == 0) {
// its time to run the data-structure prune code
keys = new ArrayList<String>();
keys.addAll(countMap.keySet());
for (String key : keys) {
LossyCount lossyCount = countMap.get(key);
if (lossyCount.getCount() + lossyCount.getBucketId() <= currentBucketId) {
log.info("Removing the Event: " + key + " from the window");
countMap.remove(key);
StreamEvent expirtedEvent = map.remove(key);
expirtedEvent.setTimestamp(currentTime);
streamEventChunk.add(expirtedEvent);
}
}
}
streamEvent = next;
}
}
nextProcessor.process(streamEventChunk);
}
use of org.wso2.siddhi.query.api.execution.query.input.store.Store in project charon by wso2.
the class UserResourceManager method updateWithPATCH.
/**
* Update the user resource by sequence of operations.
*
* @param existingId
* @param scimObjectString
* @param userManager
* @param attributes
* @param excludeAttributes
* @return
*/
public SCIMResponse updateWithPATCH(String existingId, String scimObjectString, UserManager userManager, String attributes, String excludeAttributes) {
try {
if (userManager == null) {
String error = "Provided user manager handler is null.";
throw new InternalErrorException(error);
}
// obtain the json decoder.
JSONDecoder decoder = getDecoder();
// decode the SCIM User object, encoded in the submitted payload.
List<PatchOperation> opList = decoder.decodeRequest(scimObjectString);
SCIMResourceTypeSchema schema = SCIMResourceSchemaManager.getInstance().getUserResourceSchema();
// get the user from the user core
User oldUser = userManager.getUser(existingId, ResourceManagerUtil.getAllAttributeURIs(schema));
if (oldUser == null) {
throw new NotFoundException("No user with the id : " + existingId + " in the user store.");
}
// make a copy of the original user
User copyOfOldUser = (User) CopyUtil.deepCopy(oldUser);
// make another copy of original user.
// this will be used to restore to the original condition if failure occurs.
User originalUser = (User) CopyUtil.deepCopy(copyOfOldUser);
User newUser = null;
for (PatchOperation operation : opList) {
if (operation.getOperation().equals(SCIMConstants.OperationalConstants.ADD)) {
if (newUser == null) {
newUser = (User) PatchOperationUtil.doPatchAdd(operation, getDecoder(), oldUser, copyOfOldUser, schema);
copyOfOldUser = (User) CopyUtil.deepCopy(newUser);
} else {
newUser = (User) PatchOperationUtil.doPatchAdd(operation, getDecoder(), newUser, copyOfOldUser, schema);
copyOfOldUser = (User) CopyUtil.deepCopy(newUser);
}
} else if (operation.getOperation().equals(SCIMConstants.OperationalConstants.REMOVE)) {
if (newUser == null) {
newUser = (User) PatchOperationUtil.doPatchRemove(operation, oldUser, copyOfOldUser, schema);
copyOfOldUser = (User) CopyUtil.deepCopy(newUser);
} else {
newUser = (User) PatchOperationUtil.doPatchRemove(operation, newUser, copyOfOldUser, schema);
copyOfOldUser = (User) CopyUtil.deepCopy(newUser);
}
} else if (operation.getOperation().equals(SCIMConstants.OperationalConstants.REPLACE)) {
if (newUser == null) {
newUser = (User) PatchOperationUtil.doPatchReplace(operation, getDecoder(), oldUser, copyOfOldUser, schema);
copyOfOldUser = (User) CopyUtil.deepCopy(newUser);
} else {
newUser = (User) PatchOperationUtil.doPatchReplace(operation, getDecoder(), newUser, copyOfOldUser, schema);
copyOfOldUser = (User) CopyUtil.deepCopy(newUser);
}
} else {
throw new BadRequestException("Unknown operation.", ResponseCodeConstants.INVALID_SYNTAX);
}
}
// get the URIs of required attributes which must be given a value
Map<String, Boolean> requiredAttributes = ResourceManagerUtil.getOnlyRequiredAttributesURIs((SCIMResourceTypeSchema) CopyUtil.deepCopy(schema), attributes, excludeAttributes);
User validatedUser = (User) ServerSideValidator.validateUpdatedSCIMObject(originalUser, newUser, schema);
newUser = userManager.updateUser(validatedUser, requiredAttributes);
// encode the newly created SCIM user object and add id attribute to Location header.
String encodedUser;
Map<String, String> httpHeaders = new HashMap<String, String>();
if (newUser != null) {
// create a deep copy of the user object since we are going to change it.
User copiedUser = (User) CopyUtil.deepCopy(newUser);
// need to remove password before returning
ServerSideValidator.validateReturnedAttributes(copiedUser, attributes, excludeAttributes);
encodedUser = getEncoder().encodeSCIMObject(copiedUser);
// add location header
httpHeaders.put(SCIMConstants.LOCATION_HEADER, getResourceEndpointURL(SCIMConstants.USER_ENDPOINT) + "/" + newUser.getId());
httpHeaders.put(SCIMConstants.CONTENT_TYPE_HEADER, SCIMConstants.APPLICATION_JSON);
} else {
String error = "Updated User resource is null.";
throw new CharonException(error);
}
// put the URI of the User object in the response header parameter.
return new SCIMResponse(ResponseCodeConstants.CODE_OK, encodedUser, httpHeaders);
} catch (NotFoundException e) {
return AbstractResourceManager.encodeSCIMException(e);
} catch (BadRequestException e) {
return AbstractResourceManager.encodeSCIMException(e);
} catch (NotImplementedException e) {
return AbstractResourceManager.encodeSCIMException(e);
} catch (CharonException e) {
return AbstractResourceManager.encodeSCIMException(e);
} catch (InternalErrorException e) {
return AbstractResourceManager.encodeSCIMException(e);
} catch (RuntimeException e) {
CharonException e1 = new CharonException("Error in performing the patch operation on user resource.", e);
return AbstractResourceManager.encodeSCIMException(e1);
}
}
Aggregations