Search in sources :

Example 36 with Operation

use of com.google.api.services.storagetransfer.v1.model.Operation in project platinum by hartwigmedical.

the class KubernetesEngineTest method shouldCreateAndReturnInstanceWhenNoneExists.

@Test
public void shouldCreateAndReturnInstanceWhenNoneExists() throws IOException {
    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");
    mockForClusterCreation();
    victim.findOrCreate(RUN_NAME, Collections.emptyList(), JSON_KEY, BUCKET, SERVICE_ACCOUNT);
    verify(created).execute();
}
Also used : Create(com.google.api.services.container.v1beta1.Container.Projects.Locations.Clusters.Create) Get(com.google.api.services.container.v1beta1.Container.Projects.Locations.Clusters.Get) Operation(com.google.api.services.container.v1beta1.model.Operation) Test(org.junit.Test)

Example 37 with Operation

use of com.google.api.services.storagetransfer.v1.model.Operation in project FAAAST-Service by FraunhoferIOSB.

the class RequestHandlerManagerTest method testInvokeOperationSyncRequest.

@Test
public void testInvokeOperationSyncRequest() {
    CoreConfig coreConfig = CoreConfig.builder().build();
    Persistence persistence = mock(Persistence.class);
    MessageBus messageBus = mock(MessageBus.class);
    AssetConnectionManager assetConnectionManager = mock(AssetConnectionManager.class);
    when(assetConnectionManager.hasOperationProvider(any())).thenReturn(true);
    when(assetConnectionManager.getOperationProvider(any())).thenReturn(new CustomAssetOperationProvider());
    RequestHandlerManager manager = new RequestHandlerManager(coreConfig, persistence, messageBus, assetConnectionManager);
    Operation operation = getTestOperation();
    InvokeOperationSyncRequest invokeOperationSyncRequest = new InvokeOperationSyncRequest.Builder().requestId("1").inoutputArguments(operation.getInoutputVariables()).inputArguments(operation.getInputVariables()).id(new DefaultIdentifier.Builder().idType(IdentifierType.IRI).identifier("http://example.org").build()).build();
    InvokeOperationSyncResponse actual = manager.execute(invokeOperationSyncRequest);
    InvokeOperationSyncResponse expected = new InvokeOperationSyncResponse.Builder().statusCode(StatusCode.SUCCESS).payload(new OperationResult.Builder().requestId("1").inoutputArguments(List.of(new DefaultOperationVariable.Builder().value(new DefaultProperty.Builder().idShort("TestProp").value("TestOutput").build()).build())).outputArguments(operation.getInputVariables()).executionState(ExecutionState.COMPLETED).build()).build();
    Assert.assertTrue(ResponseHelper.equalsIgnoringTime(expected, actual));
}
Also used : CoreConfig(de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig) InvokeOperationSyncRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.InvokeOperationSyncRequest) OperationResult(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationResult) Operation(io.adminshell.aas.v3.model.Operation) DefaultOperation(io.adminshell.aas.v3.model.impl.DefaultOperation) DefaultOperationVariable(io.adminshell.aas.v3.model.impl.DefaultOperationVariable) Persistence(de.fraunhofer.iosb.ilt.faaast.service.persistence.Persistence) MessageBus(de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus) AssetConnectionManager(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionManager) RequestHandlerManager(de.fraunhofer.iosb.ilt.faaast.service.request.RequestHandlerManager) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) InvokeOperationSyncResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationSyncResponse) Test(org.junit.Test)

Example 38 with Operation

use of com.google.api.services.storagetransfer.v1.model.Operation in project FAAAST-Service by FraunhoferIOSB.

the class RequestHandlerManagerTest method testInvokeOperationAsyncRequest.

@Test
public void testInvokeOperationAsyncRequest() {
    CoreConfig coreConfig = CoreConfig.builder().build();
    Persistence persistence = mock(Persistence.class);
    MessageBus messageBus = mock(MessageBus.class);
    AssetConnectionManager assetConnectionManager = mock(AssetConnectionManager.class);
    AssetOperationProvider assetOperationProvider = mock(AssetOperationProvider.class);
    RequestHandlerManager manager = new RequestHandlerManager(coreConfig, persistence, messageBus, assetConnectionManager);
    Operation operation = getTestOperation();
    OperationHandle expectedOperationHandle = new OperationHandle.Builder().handleId("1").requestId("1").build();
    when(persistence.putOperationContext(any(), any(), any())).thenReturn(expectedOperationHandle);
    when(persistence.getOperationResult(any())).thenReturn(new OperationResult.Builder().requestId("1").build());
    when(assetConnectionManager.hasOperationProvider(any())).thenReturn(true);
    when(assetConnectionManager.getOperationProvider(any())).thenReturn(assetOperationProvider);
    InvokeOperationAsyncRequest invokeOperationAsyncRequest = new InvokeOperationAsyncRequest.Builder().requestId("1").id(new DefaultIdentifier.Builder().idType(IdentifierType.IRI).identifier("http://example.org").build()).inoutputArguments(operation.getInoutputVariables()).inputArguments(operation.getInputVariables()).build();
    InvokeOperationAsyncResponse response = manager.execute(invokeOperationAsyncRequest);
    OperationHandle actualOperationHandle = response.getPayload();
    Assert.assertEquals(expectedOperationHandle, actualOperationHandle);
}
Also used : CoreConfig(de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig) OperationResult(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationResult) Operation(io.adminshell.aas.v3.model.Operation) DefaultOperation(io.adminshell.aas.v3.model.impl.DefaultOperation) OperationHandle(de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationHandle) Persistence(de.fraunhofer.iosb.ilt.faaast.service.persistence.Persistence) MessageBus(de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus) AssetConnectionManager(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionManager) RequestHandlerManager(de.fraunhofer.iosb.ilt.faaast.service.request.RequestHandlerManager) InvokeOperationAsyncRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.InvokeOperationAsyncRequest) AssetOperationProvider(de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetOperationProvider) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) InvokeOperationAsyncResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationAsyncResponse) Test(org.junit.Test)

Example 39 with Operation

use of com.google.api.services.storagetransfer.v1.model.Operation in project terra-cli by DataBiosphere.

the class GoogleNotebooks method start.

public void start(InstanceName instanceName) {
    try {
        Operation startOperation = notebooks.instances().start(instanceName).execute();
        pollForSuccess(startOperation, "Error starting notebook instance: ");
    } catch (InterruptedException | IOException e) {
        checkFor409BadState(e);
        throw new SystemException("Error starting notebook instance", e);
    }
}
Also used : SystemException(bio.terra.cli.exception.SystemException) Operation(com.google.api.services.notebooks.v1.model.Operation) IOException(java.io.IOException)

Example 40 with Operation

use of com.google.api.services.storagetransfer.v1.model.Operation in project terra-workspace-manager by DataBiosphere.

the class CompleteTransferOperationStep method getLatestOperationName.

// First, we poll the transfer jobs endpoint until an operation has started so that we can get
// its server-generated name. Returns the most recently started operation's name.
private String getLatestOperationName(Storagetransfer storageTransferService, String transferJobName, String projectId) throws InterruptedException, IOException {
    String operationName = null;
    for (int numAttempts = 0; numAttempts < MAX_ATTEMPTS; ++numAttempts) {
        final TransferJob getResponse = storageTransferService.transferJobs().get(transferJobName, projectId).execute();
        operationName = getResponse.getLatestOperationName();
        if (null != operationName) {
            break;
        } else {
            TimeUnit.MILLISECONDS.sleep(JOBS_POLL_INTERVAL.toMillis());
        }
    }
    if (null == operationName) {
        throw new StorageTransferServiceTimeoutException("Exceeded max attempts to get transfer operation name");
    }
    logger.debug("Latest transfer operation name is {}", operationName);
    return operationName;
}
Also used : StorageTransferServiceTimeoutException(bio.terra.workspace.service.resource.controlled.exception.StorageTransferServiceTimeoutException) TransferJob(com.google.api.services.storagetransfer.v1.model.TransferJob)

Aggregations

IOException (java.io.IOException)15 Test (org.junit.Test)9 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)7 Operation (io.adminshell.aas.v3.model.Operation)7 StepResult (bio.terra.stairway.StepResult)6 CloudHealthcare (com.google.api.services.healthcare.v1.CloudHealthcare)6 Operation (com.google.api.services.healthcare.v1.model.Operation)6 Operation (com.google.api.services.notebooks.v1.model.Operation)5 MessageBus (de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus)5 Operation (com.google.api.services.appengine.v1.model.Operation)4 Operation (com.google.api.services.container.v1beta1.model.Operation)4 AIPlatformNotebooksCow (bio.terra.cloudres.google.notebooks.AIPlatformNotebooksCow)3 InstanceName (bio.terra.cloudres.google.notebooks.InstanceName)3 StorageTransferServiceTimeoutException (bio.terra.workspace.service.resource.controlled.exception.StorageTransferServiceTimeoutException)3 GcpCloudContext (bio.terra.workspace.service.workspace.model.GcpCloudContext)3 Create (com.google.api.services.container.v1beta1.Container.Projects.Locations.Clusters.Create)3 Get (com.google.api.services.container.v1beta1.Container.Projects.Locations.Clusters.Get)3 Operation (com.google.api.services.serviceusage.v1beta1.model.Operation)3 TransferJob (com.google.api.services.storagetransfer.v1.model.TransferJob)3 AssetConnectionManager (de.fraunhofer.iosb.ilt.faaast.service.assetconnection.AssetConnectionManager)3