use of com.google.api.services.serviceusage.v1beta1.model.Operation in project google-cloud-intellij by GoogleCloudPlatform.
the class GoogleApiClientAppEngineAdminServiceTest method testCreateApplication_operationFailed.
@Test
public void testCreateApplication_operationFailed() throws IOException, GoogleApiException {
String operationName = "apps/-/operations/12345";
Operation inProgressOperation = buildInProgressOperation(operationName);
when(appengineClientMock.getAppsCreateQuery().execute()).thenReturn(inProgressOperation);
String errorMessage = "The operation failed.";
int errorCode = 400;
Status status = new Status();
status.setMessage(errorMessage);
status.setCode(errorCode);
Operation failedOperation = new Operation();
failedOperation.setError(status);
failedOperation.setDone(true);
failedOperation.setName(operationName);
when(appengineClientMock.getAppsCreateQuery().execute()).thenReturn(inProgressOperation);
when(appengineClientMock.getAppsOperationsGetQuery().execute()).thenReturn(failedOperation);
try {
service.createApplication("us-east", "my-project-id", mock(Credential.class));
} catch (GoogleApiException expected) {
assertEquals(errorCode, expected.getStatusCode());
assertEquals(errorMessage, expected.getMessage());
return;
}
fail();
}
use of com.google.api.services.serviceusage.v1beta1.model.Operation in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method setAasReferenceData.
/**
* Sets the data in the given Reference node.
*
* @param ref The desired UA reference object
* @param refNode The AAS Reference object with the source data
* @param readOnly True if the value should be read-only
* @throws StatusException If the operation fails
*/
private void setAasReferenceData(Reference ref, AASReferenceType refNode, boolean readOnly) throws StatusException {
if (refNode == null) {
throw new IllegalArgumentException("refNode is null");
} else if (ref == null) {
throw new IllegalArgumentException("ref is null");
}
try {
List<AASKeyDataType> keyList = new ArrayList<>();
ref.getKeys().stream().map(k -> {
AASKeyDataType keyValue = new AASKeyDataType();
keyValue.setIdType(ValueConverter.getAasKeyType(k.getIdType()));
keyValue.setType(ValueConverter.getAasKeyElementsDataType(k.getType()));
keyValue.setValue(k.getValue());
return keyValue;
}).forEachOrdered(keyList::add);
refNode.getKeysNode().setArrayDimensions(new UnsignedInteger[] { UnsignedInteger.valueOf(keyList.size()) });
if (readOnly) {
refNode.getKeysNode().setAccessLevel(AccessLevelType.CurrentRead);
}
refNode.setKeys(keyList.toArray(AASKeyDataType[]::new));
} catch (Exception ex) {
LOG.error("setAasReferenceData Exception", ex);
throw ex;
}
}
use of com.google.api.services.serviceusage.v1beta1.model.Operation in project FAAAST-Service by FraunhoferIOSB.
the class ReferenceHelper method completeReferenceWithProperKeyElements.
/**
* Browse the keys of a reference and try to find the referenced element in the
* asset administration shell environment to set the right {@link io.adminshell.aas.v3.model.KeyElements}
* of the key.
* All key types must be null or SUBMODEL_ELEMENT.
*
* @param reference with keys which should be completed
* @param env the asset administration shell environment which contains the referenced elements
* @throws ResourceNotFoundException if an element referenced by a key could not be found
*/
public static void completeReferenceWithProperKeyElements(Reference reference, AssetAdministrationShellEnvironment env) throws ResourceNotFoundException {
if (reference == null) {
return;
}
List<Key> keys = reference.getKeys();
if (keys.stream().allMatch(x -> x.getType() != null && x.getType() != KeyElements.SUBMODEL_ELEMENT)) {
return;
}
final Referable[] parent = { null };
for (Key k : keys) {
if (env.getAssetAdministrationShells().stream().anyMatch(x -> x.getIdentification().getIdentifier().equalsIgnoreCase(k.getValue()) || x.getIdShort().equalsIgnoreCase(k.getValue()))) {
k.setType(KeyElements.ASSET_ADMINISTRATION_SHELL);
continue;
}
env.getSubmodels().forEach(x -> {
if (x.getIdentification().getIdentifier().equalsIgnoreCase(k.getValue()) || x.getIdShort().equalsIgnoreCase(k.getValue())) {
k.setType(KeyElements.SUBMODEL);
parent[0] = x;
}
});
if (k.getType() != null && k.getType() != KeyElements.SUBMODEL_ELEMENT) {
continue;
}
if (env.getConceptDescriptions().stream().anyMatch(x -> x.getIdentification().getIdentifier().equalsIgnoreCase(k.getValue()) || x.getIdShort().equalsIgnoreCase(k.getValue()))) {
k.setType(KeyElements.CONCEPT_DESCRIPTION);
continue;
}
if (env.getAssets().stream().anyMatch(x -> x.getIdentification().getIdentifier().equalsIgnoreCase(k.getValue()) || x.getIdShort().equalsIgnoreCase(k.getValue()))) {
k.setType(KeyElements.ASSET);
continue;
}
if (parent[0] != null && Submodel.class.isAssignableFrom(parent[0].getClass())) {
Submodel submodel = (Submodel) parent[0];
submodel.getSubmodelElements().forEach(y -> {
if (y.getIdShort().equalsIgnoreCase(k.getValue())) {
k.setType(AasUtils.referableToKeyType(y));
parent[0] = y;
}
});
} else if (SubmodelElementCollection.class.isAssignableFrom(parent[0].getClass())) {
((SubmodelElementCollection) parent[0]).getValues().forEach(x -> {
if (x.getIdShort().equalsIgnoreCase(k.getValue())) {
k.setType(AasUtils.referableToKeyType(x));
parent[0] = x;
}
});
} else if (Operation.class.isAssignableFrom(parent[0].getClass())) {
Operation operation = (Operation) parent[0];
Stream.concat(Stream.concat(operation.getInoutputVariables().stream(), operation.getInputVariables().stream()), operation.getOutputVariables().stream()).forEach(x -> {
if (x.getValue().getIdShort().equalsIgnoreCase(k.getValue())) {
k.setType(AasUtils.referableToKeyType(x.getValue()));
parent[0] = x.getValue();
}
});
}
if (k.getType() == null) {
throw new ResourceNotFoundException("Resource with ID " + k.getValue() + " was not found!");
}
}
}
use of com.google.api.services.serviceusage.v1beta1.model.Operation in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceMethodManagerListener method onCall.
/**
* Callback method when a method was called
*
* @param serviceContext the current service context
* @param objectId the ID of the node whose method is being called
* @param object the object node whose method is being called, if available
* @param methodId the ID of the method being called
* @param method the method node being called, if available
* @param inputArguments input argument values
* @param inputArgumentResults argument errors. If errors in the values are
* encountered.
* @param inputArgumentDiagnosticInfos diagnostic info, in case of errors.
* @param outputs output values. The array is pre-created, just fill in the
* values.
* @return true if you handle the call, which prevents any other handler
* being called.
* @throws StatusException if there are errors in the method handling. For
* example, if you set inputArgumentResults, you should throw a
* StatusException with StatusCodes.Bad_InvalidArgument
*/
@Override
public boolean onCall(ServiceContext serviceContext, NodeId objectId, UaNode object, NodeId methodId, UaMethod method, Variant[] inputArguments, StatusCode[] inputArgumentResults, DiagnosticInfo[] inputArgumentDiagnosticInfos, Variant[] outputs) throws StatusException {
boolean retval = false;
// Handle method calls
// Note that the outputs array is already allocated
LOGGER.info("onCall: method {}: called. InputArguments: {}", methodId, inputArguments);
try {
if (endpoint == null) {
LOGGER.warn("onCall: no Endpoint available");
} else {
SubmodelElementData data = nodeManager.getAasData(objectId);
Operation aasOper = (Operation) data.getSubmodelElement();
if (aasOper != null) {
List<OperationVariable> inputVariables = aasOper.getInputVariables();
ValueConverter.setOperationValues(inputVariables, inputArguments);
List<OperationVariable> outputVariables = endpoint.callOperation(aasOper, inputVariables, data.getSubmodel(), data.getReference());
ValueConverter.setOutputArguments(outputVariables, outputs);
retval = true;
} else {
LOGGER.info("onCall: Property for {} not found", objectId);
}
}
} catch (StatusException se) {
LOGGER.error("onCall StatusException", se);
throw se;
} catch (Exception ex) {
LOGGER.error("onCall Exception", ex);
throw new StatusException(ex.getMessage(), StatusCodes.Bad_UnexpectedError);
}
return retval;
}
use of com.google.api.services.serviceusage.v1beta1.model.Operation in project platinum by hartwigmedical.
the class KubernetesEngineTest method shouldPollUntilCreateClusterOperationHasCompleted.
@Test
public void shouldPollUntilCreateClusterOperationHasCompleted() throws Exception {
Get foundOperation = mock(Get.class);
Create created = mock(Create.class);
Operation executedCreate = mock(Operation.class);
when(clusters.get(anyString())).thenReturn(foundOperation);
when(foundOperation.execute()).thenThrow(GoogleJsonResponseException.class);
when(clusters.create(eq(format("projects/%s/locations/%s", PROJECT, REGION)), any())).thenReturn(created);
when(created.execute()).thenReturn(executedCreate);
when(executedCreate.getName()).thenReturn("created");
Operations operations = mock(Operations.class);
Operations.Get operationsGet = mock(Operations.Get.class);
Operation executedOperationsGet = mock(Operation.class);
when(locations.operations()).thenReturn(operations);
when(operations.get(anyString())).thenReturn(operationsGet);
when(operationsGet.execute()).thenReturn(executedOperationsGet);
when(executedOperationsGet.getStatus()).thenReturn(null).thenReturn("RUNNING").thenReturn("DONE");
victim.findOrCreate(RUN_NAME, Collections.emptyList(), JSON_KEY, BUCKET, SERVICE_ACCOUNT);
// noinspection ResultOfMethodCallIgnored
verify(executedOperationsGet, times(3)).getStatus();
}
Aggregations