use of org.ovirt.engine.core.compat.RefObject in project ovirt-engine by oVirt.
the class SyntaxChecker method analyzeSyntaxState.
@Override
public SyntaxContainer analyzeSyntaxState(final String searchText, boolean final2) {
final SyntaxContainer syntaxContainer = new SyntaxContainer(searchText);
IConditionFieldAutoCompleter curConditionFieldAC = null;
IAutoCompleter curConditionRelationAC = null;
final List<String> freeTextObjSearched = new ArrayList<>();
char[] searchCharArr = searchText.toCharArray();
int curStartPos = 0;
String tryNextObj = "";
boolean keepValid;
for (int idx = 0; idx < searchCharArr.length; idx++) {
final SyntaxObjectType curState = syntaxContainer.getState();
final char curChar = searchCharArr[idx];
if (DISALLOWED_CHARS.contains(curChar)) {
syntaxContainer.setErr(SyntaxError.INVALID_CHARECTER, curStartPos, idx + 1);
return syntaxContainer;
}
if ((curChar == ' ') && (curState != SyntaxObjectType.CONDITION_RELATION) && (curState != SyntaxObjectType.COLON) && (curState != SyntaxObjectType.CONDITION_VALUE) && (curState != SyntaxObjectType.OR) && (curState != SyntaxObjectType.AND)) {
curStartPos += 1;
continue;
}
String strRealObj = searchText.substring(curStartPos, idx + 1);
String nextObject = strRealObj.toUpperCase();
switch(curState) {
case BEGIN:
// we have found a search-object
if (!searchObjectAC.validate(nextObject)) {
if (!searchObjectAC.validateCompletion(nextObject)) {
syntaxContainer.setErr(SyntaxError.INVALID_SEARCH_OBJECT, curStartPos, idx - curStartPos + 1);
return syntaxContainer;
}
} else {
if (searchCharArr.length >= idx + 2) {
// Validate that the next character is an 's'
if (pluralAC.validate(searchText.substring(idx + 1, idx + 1 + 1))) {
// Then just move things along.
idx++;
StringBuilder sb = new StringBuilder(nextObject);
sb.append('S');
nextObject = sb.toString();
}
}
syntaxContainer.addSyntaxObject(SyntaxObjectType.SEARCH_OBJECT, nextObject, curStartPos, idx + 1);
syntaxContainer.setvalid(true);
curStartPos = idx + 1;
}
break;
case SEARCH_OBJECT:
if (!colonAC.validate(nextObject)) {
if (!colonAC.validateCompletion(nextObject)) {
syntaxContainer.setErr(SyntaxError.COLON_NOT_NEXT_TO_SEARCH_OBJECT, curStartPos, idx + 1);
return syntaxContainer;
}
} else {
syntaxContainer.addSyntaxObject(SyntaxObjectType.COLON, nextObject, idx, idx + 1);
curStartPos = idx + 1;
syntaxContainer.setvalid(true);
}
break;
case CROSS_REF_OBJ:
String curRefObj = syntaxContainer.getPreviousSyntaxObject(0, SyntaxObjectType.CROSS_REF_OBJ);
curConditionRelationAC = searchObjectAC.getObjectRelationshipAutoCompleter();
if (idx + 1 < searchCharArr.length) {
tryNextObj = searchText.substring(curStartPos, idx + 2).toUpperCase();
}
if (curConditionRelationAC == null) {
syntaxContainer.setErr(SyntaxError.CONDITION_CANT_CREATE_RRELATIONS_AC, curStartPos, idx + 1);
return syntaxContainer;
}
if (dotAC.validate(nextObject)) {
syntaxContainer.addSyntaxObject(SyntaxObjectType.DOT, nextObject, curStartPos, idx + 1);
curStartPos = idx + 1;
} else if (!"".equals(tryNextObj) && curConditionRelationAC.validate(tryNextObj)) {
// i.e. the relation object has another charecter
break;
} else if (curConditionRelationAC.validate(nextObject)) {
syntaxContainer.addSyntaxObject(SyntaxObjectType.CONDITION_RELATION, nextObject, curStartPos, idx + 1);
curStartPos = idx + 1;
} else if (!curConditionRelationAC.validateCompletion(nextObject) && !dotAC.validateCompletion(nextObject)) {
syntaxContainer.setErr(SyntaxError.INVALID_POST_CROSS_REF_OBJ, curStartPos, idx + 1);
return syntaxContainer;
}
tryNextObj = "";
break;
case DOT:
curRefObj = syntaxContainer.getPreviousSyntaxObject(1, SyntaxObjectType.CROSS_REF_OBJ);
curConditionFieldAC = searchObjectAC.getFieldAutoCompleter(curRefObj);
if (curConditionFieldAC == null) {
syntaxContainer.setErr(SyntaxError.CANT_GET_CONDITION_FIELD_AC, curStartPos, idx);
return syntaxContainer;
}
if (!curConditionFieldAC.validate(nextObject)) {
if (!curConditionFieldAC.validateCompletion(nextObject)) {
syntaxContainer.setErr(SyntaxError.INVALID_CONDITION_FILED, curStartPos, idx + 1);
return syntaxContainer;
}
} else {
syntaxContainer.addSyntaxObject(SyntaxObjectType.CONDITION_FIELD, nextObject, curStartPos, idx + 1);
curStartPos = idx + 1;
}
break;
case AND:
case OR:
keepValid = false;
curConditionFieldAC = searchObjectAC.getFieldAutoCompleter(syntaxContainer.getSearchObjectStr());
if (curConditionFieldAC.validate(nextObject)) {
syntaxContainer.addSyntaxObject(SyntaxObjectType.CONDITION_FIELD, nextObject, curStartPos, idx + 1);
curStartPos = idx + 1;
} else if (searchObjectAC.isCrossReference(nextObject, syntaxContainer.getFirst().getBody())) {
if (searchCharArr.length >= idx + 2) {
// Validate that the next character is an 's'
if (pluralAC.validate(searchText.substring(idx + 1, idx + 1 + 1))) {
// Then just move things along.
idx++;
StringBuilder sb = new StringBuilder(nextObject);
sb.append('S');
nextObject = sb.toString();
}
}
syntaxContainer.addSyntaxObject(SyntaxObjectType.CROSS_REF_OBJ, nextObject, curStartPos, idx + 1);
curStartPos = idx + 1;
} else {
RefObject<Integer> tempRefObject = new RefObject<>(curStartPos);
ValueParseResult ans = handleValuePhrase(final2, searchText, idx, tempRefObject, syntaxContainer);
curStartPos = tempRefObject.argvalue;
if (ans != ValueParseResult.Err) {
if (ans == ValueParseResult.FreeText) {
curRefObj = syntaxContainer.getSearchObjectStr();
if (freeTextObjSearched.contains(curRefObj)) {
syntaxContainer.setErr(SyntaxError.FREE_TEXT_ALLOWED_ONCE_PER_OBJ, curStartPos, idx + 1);
return syntaxContainer;
}
freeTextObjSearched.add(curRefObj);
syntaxContainer.setvalid(true);
keepValid = true;
}
} else if (!curConditionFieldAC.validateCompletion(nextObject) && !searchObjectAC.validateCompletion(nextObject)) {
syntaxContainer.setErr(SyntaxError.INVALID_POST_OR_AND_PHRASE, curStartPos, idx + 1);
return syntaxContainer;
}
}
if (!keepValid) {
syntaxContainer.setvalid(false);
}
break;
case COLON:
keepValid = false;
curConditionFieldAC = searchObjectAC.getFieldAutoCompleter(syntaxContainer.getSearchObjectStr());
if (curConditionFieldAC.validate(nextObject)) {
syntaxContainer.addSyntaxObject(SyntaxObjectType.CONDITION_FIELD, nextObject, curStartPos, idx + 1);
curStartPos = idx + 1;
} else if (sortbyAC.validate(nextObject)) {
syntaxContainer.addSyntaxObject(SyntaxObjectType.SORTBY, nextObject, curStartPos, idx + 1);
curStartPos = idx + 1;
} else if (pageAC.validate(nextObject)) {
syntaxContainer.addSyntaxObject(SyntaxObjectType.PAGE, nextObject, curStartPos, idx + 1);
curStartPos = idx + 1;
} else if (searchObjectAC.isCrossReference(nextObject, syntaxContainer.getFirst().getBody())) {
if (searchCharArr.length >= idx + 2) {
// Validate that the next character is an 's'
if (pluralAC.validate(searchText.substring(idx + 1, idx + 1 + 1))) {
// Then just move things along.
idx++;
StringBuilder sb = new StringBuilder(nextObject);
sb.append('S');
nextObject = sb.toString();
}
}
syntaxContainer.addSyntaxObject(SyntaxObjectType.CROSS_REF_OBJ, nextObject, curStartPos, idx + 1);
curStartPos = idx + 1;
} else {
RefObject<Integer> tempRefObject2 = new RefObject<>(curStartPos);
ValueParseResult ans = handleValuePhrase(final2, searchText, idx, tempRefObject2, syntaxContainer);
curStartPos = tempRefObject2.argvalue;
if (ans != ValueParseResult.Err) {
if (ans == ValueParseResult.FreeText) {
freeTextObjSearched.add(syntaxContainer.getSearchObjectStr());
}
keepValid = true;
} else if (!curConditionFieldAC.validateCompletion(nextObject) && !sortbyAC.validateCompletion(nextObject) && !searchObjectAC.validateCompletion(nextObject)) {
syntaxContainer.setErr(SyntaxError.INVALID_POST_COLON_PHRASE, curStartPos, idx + 1);
return syntaxContainer;
}
}
if (!keepValid) {
syntaxContainer.setvalid(false);
}
break;
case CONDITION_VALUE:
nextObject = nextObject.trim();
if (nextObject.length() > 0) {
keepValid = false;
curRefObj = syntaxContainer.getSearchObjectStr();
curConditionFieldAC = searchObjectAC.getFieldAutoCompleter(curRefObj);
if (curConditionFieldAC.validate(nextObject)) {
syntaxContainer.addSyntaxObject(SyntaxObjectType.CONDITION_FIELD, nextObject, curStartPos, idx + 1);
curStartPos = idx + 1;
} else if (sortbyAC.validate(nextObject)) {
syntaxContainer.addSyntaxObject(SyntaxObjectType.SORTBY, nextObject, curStartPos, idx + 1);
curStartPos = idx + 1;
} else if (pageAC.validate(nextObject)) {
syntaxContainer.addSyntaxObject(SyntaxObjectType.PAGE, nextObject, curStartPos, idx + 1);
curStartPos = idx + 1;
} else if (searchObjectAC.isCrossReference(nextObject, syntaxContainer.getFirst().getBody())) {
if (searchCharArr.length >= idx + 2) {
// Validate that the next character is an 's'
if (pluralAC.validate(searchText.substring(idx + 1, idx + 1 + 1))) {
// Then just move things along.
idx++;
StringBuilder sb = new StringBuilder(nextObject);
sb.append('S');
nextObject = sb.toString();
}
}
syntaxContainer.addSyntaxObject(SyntaxObjectType.CROSS_REF_OBJ, nextObject, curStartPos, idx + 1);
curStartPos = idx + 1;
} else if (andAC.validate(nextObject)) {
syntaxContainer.addSyntaxObject(SyntaxObjectType.AND, nextObject, curStartPos, idx + 1);
curStartPos = idx + 1;
} else if (orAC.validate(nextObject)) {
syntaxContainer.addSyntaxObject(SyntaxObjectType.OR, nextObject, curStartPos, idx + 1);
curStartPos = idx + 1;
} else if (!curConditionFieldAC.validateCompletion(nextObject) && !sortbyAC.validateCompletion(nextObject) && !searchObjectAC.validateCompletion(nextObject) && !andAC.validateCompletion(nextObject) && !orAC.validateCompletion(nextObject)) {
RefObject<Integer> tempRefObject3 = new RefObject<>(curStartPos);
ValueParseResult ans = handleValuePhrase(final2, searchText, idx, tempRefObject3, syntaxContainer);
curStartPos = tempRefObject3.argvalue;
if (ans != ValueParseResult.Err) {
if (ans == ValueParseResult.FreeText) {
if (freeTextObjSearched.contains(curRefObj)) {
syntaxContainer.setErr(SyntaxError.FREE_TEXT_ALLOWED_ONCE_PER_OBJ, curStartPos, idx + 1);
return syntaxContainer;
}
freeTextObjSearched.add(curRefObj);
syntaxContainer.setvalid(true);
keepValid = true;
}
} else {
syntaxContainer.setErr(SyntaxError.INVALID_POST_CONDITION_VALUE_PHRASE, curStartPos, idx + 1);
return syntaxContainer;
}
}
if (!keepValid) {
syntaxContainer.setvalid(false);
}
}
break;
case CONDITION_FIELD:
curRefObj = syntaxContainer.getPreviousSyntaxObject(2, SyntaxObjectType.CROSS_REF_OBJ);
String curConditionField = syntaxContainer.getPreviousSyntaxObject(0, SyntaxObjectType.CONDITION_FIELD);
curConditionRelationAC = searchObjectAC.getFieldRelationshipAutoCompleter(curRefObj, curConditionField);
if (curConditionRelationAC == null) {
syntaxContainer.setErr(SyntaxError.CONDITION_CANT_CREATE_RRELATIONS_AC, curStartPos, idx + 1);
return syntaxContainer;
}
if (idx + 1 < searchCharArr.length) {
tryNextObj = searchText.substring(curStartPos, idx + 2).toUpperCase();
if (curConditionRelationAC.validate(tryNextObj)) {
break;
}
}
if (!curConditionRelationAC.validate(nextObject)) {
if (!curConditionRelationAC.validateCompletion(nextObject)) {
syntaxContainer.setErr(SyntaxError.INVALID_CONDITION_RELATION, curStartPos, idx + 1);
return syntaxContainer;
}
} else {
syntaxContainer.addSyntaxObject(SyntaxObjectType.CONDITION_RELATION, nextObject, curStartPos, idx + 1);
}
curStartPos = idx + 1;
syntaxContainer.setvalid(false);
tryNextObj = "";
break;
case CONDITION_RELATION:
RefObject<Integer> tempRefObject4 = new RefObject<>(curStartPos);
ValueParseResult ans = handleValuePhrase(final2, searchText, idx, tempRefObject4, syntaxContainer);
curStartPos = tempRefObject4.argvalue;
if (ans == ValueParseResult.Err) {
return syntaxContainer;
}
if (ans == ValueParseResult.FreeText) {
if (syntaxContainer.getPreviousSyntaxObjectType(2) == SyntaxObjectType.CROSS_REF_OBJ) {
curRefObj = syntaxContainer.getObjSingularName(syntaxContainer.getPreviousSyntaxObject(2, SyntaxObjectType.CROSS_REF_OBJ));
if (freeTextObjSearched.contains(curRefObj)) {
syntaxContainer.setErr(SyntaxError.FREE_TEXT_ALLOWED_ONCE_PER_OBJ, curStartPos, idx + 1);
return syntaxContainer;
}
freeTextObjSearched.add(curRefObj);
}
}
break;
case SORTBY:
curConditionFieldAC = searchObjectAC.getFieldAutoCompleter(syntaxContainer.getSearchObjectStr());
if (!curConditionFieldAC.validate(nextObject)) {
if (!curConditionFieldAC.validateCompletion(nextObject)) {
syntaxContainer.setErr(SyntaxError.INVALID_SORT_FIELD, curStartPos, idx + 1);
return syntaxContainer;
}
} else {
syntaxContainer.addSyntaxObject(SyntaxObjectType.SORT_FIELD, nextObject, curStartPos, idx + 1);
curStartPos = idx + 1;
syntaxContainer.setvalid(true);
}
break;
case PAGE:
Integer pageNumber = IntegerCompat.tryParse(nextObject);
if (pageNumber == null) {
syntaxContainer.setErr(SyntaxError.INVALID_CHARECTER, curStartPos, idx + 1);
return syntaxContainer;
} else {
final StringBuilder buff = new StringBuilder();
int pos = idx;
// parsing the whole page number (can be more than one char)
while (pos < searchText.length() - 1 && Character.isDigit(nextObject.charAt(0))) {
buff.append(nextObject);
pos++;
strRealObj = searchText.substring(pos, pos + 1);
nextObject = strRealObj.toUpperCase();
}
buff.append(nextObject);
syntaxContainer.addSyntaxObject(SyntaxObjectType.PAGE_VALUE, buff.toString(), curStartPos, idx + buff.length());
// update index position
idx = pos + 1;
syntaxContainer.setvalid(true);
}
break;
case SORT_FIELD:
if (!sortDirectionAC.validate(nextObject)) {
if (!sortDirectionAC.validateCompletion(nextObject)) {
syntaxContainer.setErr(SyntaxError.INVALID_SORT_DIRECTION, curStartPos, idx + 1);
return syntaxContainer;
}
} else {
syntaxContainer.addSyntaxObject(SyntaxObjectType.SORT_DIRECTION, nextObject, curStartPos, idx + 1);
curStartPos = idx + 1;
syntaxContainer.setvalid(true);
}
break;
case PAGE_VALUE:
if (curChar != ' ') {
syntaxContainer.setErr(SyntaxError.NOTHING_COMES_AFTER_PAGE_VALUE, curStartPos, idx + 1);
return syntaxContainer;
}
break;
case SORT_DIRECTION:
if (!pageAC.validate(nextObject)) {
if (!pageAC.validateCompletion(nextObject)) {
syntaxContainer.setErr(SyntaxError.INVALID_PAGE_FEILD, curStartPos, idx);
return syntaxContainer;
}
} else {
syntaxContainer.addSyntaxObject(SyntaxObjectType.PAGE, nextObject, curStartPos, idx + 1);
curStartPos = idx + 1;
syntaxContainer.setvalid(true);
}
break;
default:
syntaxContainer.setErr(SyntaxError.UNIDENTIFIED_STATE, curStartPos, idx);
return syntaxContainer;
}
}
return syntaxContainer;
}
use of org.ovirt.engine.core.compat.RefObject in project ovirt-engine by oVirt.
the class IrsProxy method getHostFromVds.
private String getHostFromVds() {
String returnValue = null;
Guid curVdsId = (currentVdsId != null) ? currentVdsId : Guid.Empty;
StoragePool storagePool = storagePoolDao.get(storagePoolId);
if (storagePool == null) {
log.info("hostFromVds::Finished elect spm, storage pool '{}' was removed", storagePoolId);
return null;
}
List<VDS> prioritizedVdsInPool = getPrioritizedVdsInPool();
currentVdsId = null;
// If VDS is in initialize status, wait for it to be up (or until
// configurable timeout is reached)
waitForVdsIfIsInitializing(curVdsId);
// update pool status to problematic while selecting spm
StoragePoolStatus prevStatus = storagePool.getStatus();
if (prevStatus != StoragePoolStatus.NonResponsive) {
try {
getEventListener().storagePoolStatusChange(storagePoolId, StoragePoolStatus.NonResponsive, AuditLogType.SYSTEM_CHANGE_STORAGE_POOL_STATUS_PROBLEMATIC_SEARCHING_NEW_SPM, EngineError.ENGINE, TransactionScopeOption.RequiresNew);
} catch (RuntimeException ex) {
throw new IRSStoragePoolStatusException(ex);
}
}
VDS selectedVds = null;
SpmStatusResult spmStatus = null;
if (prioritizedVdsInPool != null && prioritizedVdsInPool.size() > 0) {
selectedVds = prioritizedVdsInPool.get(0);
} else if (!Guid.Empty.equals(curVdsId) && !getTriedVdssList().contains(curVdsId)) {
selectedVds = vdsDao.get(curVdsId);
if (selectedVds.getStatus() != VDSStatus.Up || selectedVds.getVdsSpmPriority() == BusinessEntitiesDefinitions.HOST_MIN_SPM_PRIORITY) {
selectedVds = null;
}
}
if (selectedVds != null) {
// Stores origin host id in case and will be needed to disconnect from storage pool
Guid selectedVdsId = selectedVds.getId();
Integer selectedVdsSpmId = selectedVds.getVdsSpmId();
triedVdssList.add(selectedVdsId);
currentVdsId = selectedVds.getId();
connectStoragePool(selectedVds, storagePool);
VDSReturnValue returnValueFromVds = resourceManager.runVdsCommand(VDSCommandType.SpmStatus, new SpmStatusVDSCommandParameters(selectedVds.getId(), storagePoolId));
spmStatus = (SpmStatusResult) returnValueFromVds.getReturnValue();
boolean ignoreSpmStatusResult = returnValueFromVds.getVdsError() != null && returnValueFromVds.getVdsError().getCode() == EngineError.InquireNotSupportedError;
if (spmStatus != null || ignoreSpmStatusResult) {
boolean performedPoolConnect = false;
log.info("hostFromVds::selectedVds - '{}', spmStatus '{}', storage pool '{}', storage pool version '{}'", selectedVds.getName(), spmStatus != null ? spmStatus.getSpmStatus() : "unknown", storagePool.getName(), storagePool.getCompatibilityVersion());
if (ignoreSpmStatusResult) {
spmStatus = startSpm(storagePool, selectedVds, DEFAULT_PREV_ID, DEFAULT_LVER, DEFAULT_PREV_ID);
} else {
if (spmStatus.getSpmStatus() == SpmStatus.Unknown_Pool) {
connectStoragePool(selectedVds, storagePool);
performedPoolConnect = true;
// refresh spmStatus result
spmStatus = (SpmStatusResult) resourceManager.runVdsCommand(VDSCommandType.SpmStatus, new SpmStatusVDSCommandParameters(selectedVds.getId(), storagePoolId)).getReturnValue();
log.info("hostFromVds::Connected host to pool - selectedVds - {}, spmStatus {}, storage pool {}", selectedVds.getName(), spmStatus.getSpmStatus(), storagePool.getName());
}
RefObject<VDS> tempRefObject = new RefObject<>(selectedVds);
spmStatus = handleSpmStatusResult(curVdsId, prioritizedVdsInPool, storagePool, tempRefObject, spmStatus);
selectedVds = tempRefObject.argvalue;
}
if (selectedVds != null) {
RefObject<VDS> tempRefObject2 = new RefObject<>(selectedVds);
RefObject<SpmStatusResult> tempRefObject3 = new RefObject<>(spmStatus);
returnValue = handleSelectedVdsForSPM(storagePool, tempRefObject2, tempRefObject3, prevStatus);
selectedVds = tempRefObject2.argvalue;
spmStatus = tempRefObject3.argvalue;
} else {
currentVdsId = null;
}
if (performedPoolConnect && selectedVds == null) {
// if could not start spm on this host and connected to
// pool here
// then disconnect
resourceManager.runVdsCommand(VDSCommandType.DisconnectStoragePool, new DisconnectStoragePoolVDSCommandParameters(selectedVdsId, storagePoolId, selectedVdsSpmId));
}
} else {
log.info("hostFromVds::selectedVds - '{}', spmStatus returned null!", selectedVds.getName());
if (returnValueFromVds.getExceptionObject() instanceof IRSNoMasterDomainException) {
throw returnValueFromVds.getExceptionObject();
}
}
}
return returnValue;
}
Aggregations