Search in sources :

Example 56 with Operation

use of com.google.container.v1.Operation in project idempiere by idempiere.

the class CompositeServiceImpl method performOperations.

/**
 * Perform operation
 * @param trx
 * @param ops
 * @param modelADService
 * @param compResp
 * @param respAggregator
 * @param reqlogin
 * @return isError
 */
private boolean performOperations(Trx trx, Operation[] ops, ModelADServiceImpl modelADService, CompositeResponse compResp, ArrayList<StandardResponse> respAggregator, ADLoginRequest reqlogin) {
    for (Operation operation : ops) {
        if (operation.getPreCommit()) {
            if (!commitTrx(trx, compResp, respAggregator, "Cannot commit before Operation", true)) {
                return false;
            }
        }
        modelADService.setManageTrx(false);
        TargetPort.Enum portEnum = operation.getTargetPort();
        StandardResponseDocument respDoc = null;
        if (portEnum == TargetPort.CREATE_DATA) {
            ModelCRUDRequestDocument wrapperDoc = getWrappedCRUD(operation, reqlogin);
            if (wrapperDoc == null) {
                rollbackAndSetError(trx, compResp, respAggregator, "Operation createData must required ModelCRUD");
                return false;
            } else {
                respDoc = modelADService.createData(wrapperDoc);
            }
        } else if (portEnum == TargetPort.DELETE_DATA) {
            ModelCRUDRequestDocument wrapperDoc = getWrappedCRUD(operation, reqlogin);
            if (wrapperDoc == null) {
                rollbackAndSetError(trx, compResp, respAggregator, "Operation deleteData must required ModelCRUD");
                return false;
            } else {
                respDoc = modelADService.deleteData(wrapperDoc);
            }
        } else if (portEnum == TargetPort.CREATE_UPDATE_DATA) {
            ModelCRUDRequestDocument wrapperDoc = getWrappedCRUD(operation, reqlogin);
            if (wrapperDoc == null) {
                rollbackAndSetError(trx, compResp, respAggregator, "Operation createUpdateData must required ModelCRUD");
                return false;
            } else {
                respDoc = modelADService.createUpdateData(wrapperDoc);
            }
        } else if (portEnum == TargetPort.READ_DATA) {
            ModelCRUDRequestDocument wrapperDoc = getWrappedCRUD(operation, reqlogin);
            if (wrapperDoc == null) {
                // Do not rollback, Continue with consecutive operations
                respDoc = StandardResponseDocument.Factory.newInstance();
                StandardResponse resp = respDoc.addNewStandardResponse();
                resp.setIsError(false);
                resp.setError("Operation readData must required ModelCRUD");
            } else {
                WindowTabDataDocument dataResponse = modelADService.readData(wrapperDoc);
                if (dataResponse != null) {
                    respDoc = StandardResponseDocument.Factory.newInstance();
                    StandardResponse resp = respDoc.addNewStandardResponse();
                    // Do not fail though read is failed
                    resp.setIsError(false);
                    resp.setWindowTabData(dataResponse.getWindowTabData());
                }
            }
        } else if (portEnum == TargetPort.RUN_PROCESS) {
            if (operation.getModelRunProcess() == null) {
                rollbackAndSetError(trx, compResp, respAggregator, "Operation runProcess must required ModelRunProcess");
                return false;
            }
            ModelRunProcessRequestDocument wrapperDoc = ModelRunProcessRequestDocument.Factory.newInstance();
            ModelRunProcessRequest runProcessReq = wrapperDoc.addNewModelRunProcessRequest();
            runProcessReq.setADLoginRequest(reqlogin);
            runProcessReq.setModelRunProcess(operation.getModelRunProcess());
            RunProcessResponseDocument runResponse = modelADService.runProcess(wrapperDoc);
            if (runResponse != null) {
                respDoc = StandardResponseDocument.Factory.newInstance();
                StandardResponse resp = respDoc.addNewStandardResponse();
                resp.setIsError(runResponse.getRunProcessResponse().getIsError());
                resp.setRunProcessResponse(runResponse.getRunProcessResponse());
            }
        } else if (portEnum == TargetPort.SET_DOC_ACTION) {
            if (operation.getModelSetDocAction() == null) {
                rollbackAndSetError(trx, compResp, respAggregator, "Operation updateData must required ModelSetDocAction");
                return false;
            }
            ModelSetDocActionRequestDocument wrapperDoc = ModelSetDocActionRequestDocument.Factory.newInstance();
            ModelSetDocActionRequest actionReq = wrapperDoc.addNewModelSetDocActionRequest();
            actionReq.setADLoginRequest(reqlogin);
            actionReq.setModelSetDocAction(operation.getModelSetDocAction());
            respDoc = modelADService.setDocAction(wrapperDoc);
        } else if (portEnum == TargetPort.UPDATE_DATA) {
            ModelCRUDRequestDocument wrapperDoc = getWrappedCRUD(operation, reqlogin);
            if (wrapperDoc == null) {
                rollbackAndSetError(trx, compResp, respAggregator, "Operation updateData must required ModelCRUD");
                return false;
            } else {
                respDoc = modelADService.updateData(wrapperDoc);
            }
        }
        if (respDoc != null)
            respAggregator.add(respDoc.getStandardResponse());
        if (respDoc != null && respDoc.getStandardResponse().getIsError()) {
            rollbackAndSetError(trx, compResp, respAggregator, null);
            return false;
        }
        if (operation.getPostCommit()) {
            if (!commitTrx(trx, compResp, respAggregator, "Cannot commit after operation", false)) {
                return false;
            }
        }
    }
    return true;
}
Also used : ModelRunProcessRequestDocument(org.idempiere.adInterface.x10.ModelRunProcessRequestDocument) TargetPort(org.idempiere.adInterface.x10.Operation.TargetPort) WindowTabDataDocument(org.idempiere.adInterface.x10.WindowTabDataDocument) StandardResponse(org.idempiere.adInterface.x10.StandardResponse) ModelSetDocActionRequest(org.idempiere.adInterface.x10.ModelSetDocActionRequest) ModelSetDocActionRequestDocument(org.idempiere.adInterface.x10.ModelSetDocActionRequestDocument) ModelRunProcessRequest(org.idempiere.adInterface.x10.ModelRunProcessRequest) Operation(org.idempiere.adInterface.x10.Operation) ModelCRUDRequestDocument(org.idempiere.adInterface.x10.ModelCRUDRequestDocument) StandardResponseDocument(org.idempiere.adInterface.x10.StandardResponseDocument) RunProcessResponseDocument(org.idempiere.adInterface.x10.RunProcessResponseDocument)

Example 57 with Operation

use of com.google.container.v1.Operation in project java-container by googleapis.

the class ClusterManagerClientTest method setAddonsConfigTest2.

@Test
public void setAddonsConfigTest2() throws Exception {
    Operation expectedResponse = Operation.newBuilder().setName("name3373707").setZone("zone3744684").setDetail("detail-1335224239").setStatusMessage("statusMessage-958704715").setSelfLink("selfLink1191800166").setTargetLink("targetLink486368555").setLocation("location1901043637").setStartTime("startTime-2129294769").setEndTime("endTime-1607243192").setProgress(OperationProgress.newBuilder().build()).addAllClusterConditions(new ArrayList<StatusCondition>()).addAllNodepoolConditions(new ArrayList<StatusCondition>()).setError(Status.newBuilder().build()).build();
    mockClusterManager.addResponse(expectedResponse);
    String projectId = "projectId-894832108";
    String zone = "zone3744684";
    String clusterId = "clusterId561939637";
    AddonsConfig addonsConfig = AddonsConfig.newBuilder().build();
    Operation actualResponse = client.setAddonsConfig(projectId, zone, clusterId, addonsConfig);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockClusterManager.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    SetAddonsConfigRequest actualRequest = ((SetAddonsConfigRequest) actualRequests.get(0));
    Assert.assertEquals(projectId, actualRequest.getProjectId());
    Assert.assertEquals(zone, actualRequest.getZone());
    Assert.assertEquals(clusterId, actualRequest.getClusterId());
    Assert.assertEquals(addonsConfig, actualRequest.getAddonsConfig());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) AddonsConfig(com.google.container.v1.AddonsConfig) Operation(com.google.container.v1.Operation) StatusCondition(com.google.container.v1.StatusCondition) SetAddonsConfigRequest(com.google.container.v1.SetAddonsConfigRequest) Test(org.junit.Test)

Example 58 with Operation

use of com.google.container.v1.Operation in project java-container by googleapis.

the class ClusterManagerClientTest method setLegacyAbacTest.

@Test
public void setLegacyAbacTest() throws Exception {
    Operation expectedResponse = Operation.newBuilder().setName("name3373707").setZone("zone3744684").setDetail("detail-1335224239").setStatusMessage("statusMessage-958704715").setSelfLink("selfLink1191800166").setTargetLink("targetLink486368555").setLocation("location1901043637").setStartTime("startTime-2129294769").setEndTime("endTime-1607243192").setProgress(OperationProgress.newBuilder().build()).addAllClusterConditions(new ArrayList<StatusCondition>()).addAllNodepoolConditions(new ArrayList<StatusCondition>()).setError(Status.newBuilder().build()).build();
    mockClusterManager.addResponse(expectedResponse);
    String name = "name3373707";
    boolean enabled = true;
    Operation actualResponse = client.setLegacyAbac(name, enabled);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockClusterManager.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    SetLegacyAbacRequest actualRequest = ((SetLegacyAbacRequest) actualRequests.get(0));
    Assert.assertEquals(name, actualRequest.getName());
    Assert.assertEquals(enabled, actualRequest.getEnabled());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) SetLegacyAbacRequest(com.google.container.v1.SetLegacyAbacRequest) ArrayList(java.util.ArrayList) Operation(com.google.container.v1.Operation) StatusCondition(com.google.container.v1.StatusCondition) Test(org.junit.Test)

Example 59 with Operation

use of com.google.container.v1.Operation in project java-container by googleapis.

the class ClusterManagerClientTest method setLocationsTest2.

@Test
public void setLocationsTest2() throws Exception {
    Operation expectedResponse = Operation.newBuilder().setName("name3373707").setZone("zone3744684").setDetail("detail-1335224239").setStatusMessage("statusMessage-958704715").setSelfLink("selfLink1191800166").setTargetLink("targetLink486368555").setLocation("location1901043637").setStartTime("startTime-2129294769").setEndTime("endTime-1607243192").setProgress(OperationProgress.newBuilder().build()).addAllClusterConditions(new ArrayList<StatusCondition>()).addAllNodepoolConditions(new ArrayList<StatusCondition>()).setError(Status.newBuilder().build()).build();
    mockClusterManager.addResponse(expectedResponse);
    String projectId = "projectId-894832108";
    String zone = "zone3744684";
    String clusterId = "clusterId561939637";
    List<String> locations = new ArrayList<>();
    Operation actualResponse = client.setLocations(projectId, zone, clusterId, locations);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockClusterManager.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    SetLocationsRequest actualRequest = ((SetLocationsRequest) actualRequests.get(0));
    Assert.assertEquals(projectId, actualRequest.getProjectId());
    Assert.assertEquals(zone, actualRequest.getZone());
    Assert.assertEquals(clusterId, actualRequest.getClusterId());
    Assert.assertEquals(locations, actualRequest.getLocationsList());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ArrayList(java.util.ArrayList) SetLocationsRequest(com.google.container.v1.SetLocationsRequest) Operation(com.google.container.v1.Operation) StatusCondition(com.google.container.v1.StatusCondition) Test(org.junit.Test)

Example 60 with Operation

use of com.google.container.v1.Operation in project java-container by googleapis.

the class ClusterManagerClientTest method listOperationsTest.

@Test
public void listOperationsTest() throws Exception {
    ListOperationsResponse expectedResponse = ListOperationsResponse.newBuilder().addAllOperations(new ArrayList<Operation>()).addAllMissingZones(new ArrayList<String>()).build();
    mockClusterManager.addResponse(expectedResponse);
    String projectId = "projectId-894832108";
    String zone = "zone3744684";
    ListOperationsResponse actualResponse = client.listOperations(projectId, zone);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockClusterManager.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListOperationsRequest actualRequest = ((ListOperationsRequest) actualRequests.get(0));
    Assert.assertEquals(projectId, actualRequest.getProjectId());
    Assert.assertEquals(zone, actualRequest.getZone());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListOperationsResponse(com.google.container.v1.ListOperationsResponse) ArrayList(java.util.ArrayList) ListOperationsRequest(com.google.container.v1.ListOperationsRequest) Operation(com.google.container.v1.Operation) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)81 Test (org.junit.Test)75 AbstractMessage (com.google.protobuf.AbstractMessage)65 Operation (com.google.cloud.compute.v1.Operation)49 Operation (com.google.container.v1.Operation)43 StatusCondition (com.google.container.v1.StatusCondition)40 Operation (com.google.container.v1beta1.Operation)24 StatusCondition (com.google.container.v1beta1.StatusCondition)23 InstancesClient (com.google.cloud.compute.v1.InstancesClient)20 Operation (com.reprezen.kaizen.oasparser.model3.Operation)16 Path (com.reprezen.kaizen.oasparser.model3.Path)15 Operation (net.opengis.ows.v_1_0_0.Operation)15 Instance (com.google.cloud.compute.v1.Instance)13 Parameter (com.reprezen.kaizen.oasparser.model3.Parameter)13 DomainType (net.opengis.ows.v_1_0_0.DomainType)13 AttachedDisk (com.google.cloud.compute.v1.AttachedDisk)12 InsertInstanceRequest (com.google.cloud.compute.v1.InsertInstanceRequest)11 Operation (org.osate.aadl2.Operation)8 NetworkInterface (com.google.cloud.compute.v1.NetworkInterface)7 BooleanLiteral (org.osate.aadl2.BooleanLiteral)7