Package org.rhq.core.domain.resource

Examples of org.rhq.core.domain.resource.CreateResourceHistory


        }

        abortResourceCreationIfExistingSingleton(parentResource, resourceType);

        // Persist in separate transaction so it is committed immediately, before the request is sent to the agent
        CreateResourceHistory persistedHistory = resourceFactoryManager.persistCreateHistory(user, parentResourceId,
            resourceTypeId, resourceName, resourceConfiguration);

        // Package into transfer object
        CreateResourceRequest request = new CreateResourceRequest(persistedHistory.getId(), parentResourceId,
            resourceName, resourceType.getName(), resourceType.getPlugin(), pluginConfiguration, resourceConfiguration,
            timeout);

        try {
            AgentClient agentClient = agentManager.getAgentClient(agent);
            ResourceFactoryAgentService resourceFactoryAgentService = agentClient.getResourceFactoryAgentService();
            resourceFactoryAgentService.createResource(request);

            return persistedHistory;
        } catch (Exception e) {
            LOG.error("Error while sending create resource request to agent service", e);

            // Submit the error as a failure response
            String errorMessage = ThrowableUtil.getAllMessages(e);
            CreateResourceResponse response = new CreateResourceResponse(persistedHistory.getId(), null, null,
                CreateResourceStatus.FAILURE, errorMessage, resourceConfiguration);
            resourceFactoryManager.completeCreateResource(response);

            throw new RuntimeException("Error while sending create resource request to agent service", e);
        }
View Full Code Here


                deploymentTimeConfiguration.put(new PropertySimple("userProvidedTimeoutMillis", timeout));
            }
        }

        // Persist in separate transaction so it is committed immediately, before the request is sent to the agent
        CreateResourceHistory persistedHistory = resourceFactoryManager.persistCreateHistory(subject,
            parentResource.getId(), newResourceType.getId(), newResourceName, packageVersion,
            deploymentTimeConfiguration);

        // Package into transfer object
        ResourcePackageDetails packageDetails = ContentManagerHelper.packageVersionToDetails(packageVersion);
        packageDetails.setDeploymentTimeConfiguration(deploymentTimeConfiguration);
        CreateResourceRequest request = new CreateResourceRequest(persistedHistory.getId(), parentResource.getId(),
            newResourceName, newResourceType.getName(), newResourceType.getPlugin(), pluginConfiguration,
            packageDetails, timeout);

        try {
            AgentClient agentClient = agentManager.getAgentClient(agent);
            ResourceFactoryAgentService resourceFactoryAgentService = agentClient.getResourceFactoryAgentService();
            resourceFactoryAgentService.createResource(request);

            return persistedHistory;
        } catch (NoResultException nre) {
            return null;
            //eat the exception.  Some of the queries return no results if no package yet exists which is fine.
        } catch (CannotConnectException e) {
            LOG.error("Error while sending create resource request to agent service", e);

            // Submit the error as a failure response
            String errorMessage = ThrowableUtil.getAllMessages(e);
            CreateResourceResponse response = new CreateResourceResponse(persistedHistory.getId(), null, null,
                CreateResourceStatus.FAILURE, errorMessage, null);
            resourceFactoryManager.completeCreateResource(response);

            throw new CannotConnectToAgentException("Error while sending create resource request to agent service", e);
        } catch (Exception e) {
            LOG.error("Error while sending create resource request to agent service", e);

            // Submit the error as a failure response
            String errorMessage = ThrowableUtil.getAllMessages(e);
            CreateResourceResponse response = new CreateResourceResponse(persistedHistory.getId(), null, null,
                CreateResourceStatus.FAILURE, errorMessage, null);
            resourceFactoryManager.completeCreateResource(response);

            throw new RuntimeException("Error while sending create resource request to agent service", e);
        }
View Full Code Here

        }
        for (Property p : resourceConfig.getProperties()) {
            defaultRc.put(p);
        }

        CreateResourceHistory history = resourceFactory.createResource(caller,parentId, resType.getId(),name,defaultPc,
            defaultRc, null);

        CreateResourceStatus status = history.getStatus();

        try {
            Thread.sleep(2000L); // give the agent time to do the work
        } catch (InterruptedException e) {
            ; // nothing
        }

        MediaType mediaType = headers.getAcceptableMediaTypes().get(0);

        Response.ResponseBuilder builder;

        if ( status == CreateResourceStatus.SUCCESS) {

            ResourceWithType rwt = findCreatedResource(history.getParentResource().getId(),history.getCreatedResourceName(),uriInfo);
            if (rwt!=null) {
                builder = Response.ok();
                builder.entity(rwt);
            } else {
                // History says we had success but due to internal timing
                // the resource is not yet visible, so switch to in_progress
                status = CreateResourceStatus.IN_PROGRESS;
            }
        }
        if (status==CreateResourceStatus.IN_PROGRESS) {

            try {
                Thread.sleep(2000L); // give the agent time to do the work
            } catch (InterruptedException e) {
                ; // nothing
            }

            UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
            uriBuilder.path("/resource/creationStatus/{id}");
            URI uri = uriBuilder.build(history.getId());
            builder =  Response.status(302);
            builder.entity("Creation is running - please check back later");
            builder.location(uri); // redirect to self

        }
        else  // All kinds of failures
            builder = Response.serverError();
            builder.entity(new StringValue(history.getErrorMessage()));
        }
        builder.type(mediaType);
        return builder.build();
    }
View Full Code Here

        Configuration pluginConfig = ConfigurationHelper.mapToConfiguration(request.getPluginConfig());
        Configuration deployConfig = ConfigurationHelper.mapToConfiguration(request.getResourceConfig());

        String packageName = DEFAULT_PACKAGE;

        CreateResourceHistory history = resourceFactory.createResource(caller,parentId, resType.getId(),name,pluginConfig,
            packageName, null,null,deployConfig,resourceBits);

        CreateResourceStatus status = history.getStatus();

        try {
            Thread.sleep(2000L); // give the agent time to do the work
        } catch (InterruptedException e) {
            ; // nothing
        }

        MediaType mediaType = headers.getAcceptableMediaTypes().get(0);

        Response.ResponseBuilder builder;

        if ( status == CreateResourceStatus.SUCCESS) {

            ResourceWithType rwt = findCreatedResource(history.getParentResource().getId(),history.getCreatedResourceName(),uriInfo);
            if (rwt!=null) {
                builder = Response.ok();
                builder.entity(rwt);
            } else {
                // History says we had success but due to internal timing
                // the resource is not yet visible, so switch to in_progress
                status = CreateResourceStatus.IN_PROGRESS;
            }
        }
        if (status==CreateResourceStatus.IN_PROGRESS) {

            try {
                Thread.sleep(2000L); // give the agent time to do the work
            } catch (InterruptedException e) {
                ; // nothing
            }

            UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
            uriBuilder.path("/resource/creationStatus/{id}");
            URI uri = uriBuilder.build(history.getId());
            builder =  Response.status(302);
            builder.entity("Creation is running - please check back later");
            builder.location(uri); // redirect to self

        }
        else  // All kinds of failures
            builder = Response.serverError();
            builder.entity(new StringValue(history.getErrorMessage()));
        }
        builder.type(mediaType);

        return builder.build();
View Full Code Here

    @Path("/creationStatus/{id}")
    @ApiOperation("Get the status of a resource creation for content based resources.")
    @ApiError(code = 302, reason = "Creation is still going on. Check back later with the same URL.")
    public Response getHistoryItem(@PathParam("id") int historyId, @Context HttpHeaders headers, @Context UriInfo uriInfo) {

        CreateResourceHistory history;
        try {
            history = resourceFactory.getCreateHistoryItem(historyId);
        } catch (EJBTransactionRolledbackException e) {
            if (e.getCause() instanceof NoResultException)
                throw new StuffNotFoundException("Resource creation status with id " + historyId);
            else
                return Response.serverError().entity(e.getMessage()).build();
        }

        CreateResourceStatus status = history.getStatus();

        Response.ResponseBuilder builder;
        try {
            Thread.sleep(2000L); // give the agent time to do the work
        } catch (InterruptedException e) {
            ; // nothing
        }
        if (status== CreateResourceStatus.SUCCESS) {

            ResourceWithType rwt = findCreatedResource(history.getParentResource().getId(),history.getCreatedResourceName(),uriInfo);
            if (rwt!=null) {
                builder = Response.ok();
                setCachingHeader(builder, 600);
                builder.entity(rwt);
            } else {
                // History says we had success but due to internal timing
                // the resource is not yet visible, so switch to in_progress
                UriBuilder uriBuilder = uriInfo.getRequestUriBuilder();
                URI uri = uriBuilder.build();
                builder =  Response.status(302);
                builder.entity("Creation is still running - please check back later");
                builder.location(uri); // redirect to self
            }
        }
        else if (status==CreateResourceStatus.IN_PROGRESS) {
            // Creation is still running, so let the user know to check back later
            UriBuilder uriBuilder = uriInfo.getRequestUriBuilder();
            URI uri = uriBuilder.build();
            builder =  Response.status(302);
            builder.entity("Creation is still running - please check back later");
            builder.location(uri); // redirect to self
        }
        else {
            builder = Response.serverError();
            StringValue errorMessage = new StringValue(status + ": " + history.getErrorMessage());
            builder.entity(errorMessage);
        }

        MediaType mediaType = headers.getAcceptableMediaTypes().get(0);
        builder.type(mediaType);
View Full Code Here

                ListGridRecord[] selectedRows = listGrid.getSelectedRecords();
                if (selectedRows != null && selectedRows.length == 1) {
                    String typeString = selectedRows[0].getAttribute(DataSource.Field.TYPE);
                    ChildHistoryDetails detailsView = null;
                    if (DataSource.TYPE_CREATE.equals(typeString)) {
                        CreateResourceHistory history = (CreateResourceHistory) selectedRows[0]
                            .getAttributeAsObject(DataSource.Field.OBJECT);
                        detailsView = new ChildHistoryDetails(history);
                    } else if (DataSource.TYPE_DELETE.equals(typeString)) {
                        DeleteResourceHistory history = (DeleteResourceHistory) selectedRows[0]
                            .getAttributeAsObject(DataSource.Field.OBJECT);
View Full Code Here

        public ListGridRecord copyValues(Object from) {
            ListGridRecord record = new ListGridRecord();
            record.setAttribute(Field.OBJECT, from);

            if (from instanceof CreateResourceHistory) {
                CreateResourceHistory history = (CreateResourceHistory) from;
                record.setAttribute(Field.TYPE, TYPE_CREATE);
                record.setAttribute(Field.ID, history.getId());
                record.setAttribute(Field.SUBJECT_NAME, history.getSubjectName());
                record.setAttribute(Field.CREATED_DATE, history.getCreatedDate());
                record.setAttribute(Field.LAST_MODIFIED_TIME, history.getLastModifiedDate());
                record.setAttribute(Field.STATUS, history.getStatus().name());
            } else if (from instanceof DeleteResourceHistory) {
                DeleteResourceHistory history = (DeleteResourceHistory) from;
                record.setAttribute(Field.TYPE, TYPE_DELETE);
                record.setAttribute(Field.ID, history.getId());
                record.setAttribute(Field.SUBJECT_NAME, history.getSubjectName());
                record.setAttribute(Field.CREATED_DATE, history.getCreatedDate());
                record.setAttribute(Field.LAST_MODIFIED_TIME, history.getLastModifiedDate());
                record.setAttribute(Field.STATUS, history.getStatus().name());
            } else {
                CoreGUI.getErrorHandler().handleError("invalid child history type: " + from.getClass()); // should never occur
            }

            return record;
View Full Code Here

            List<CreateResourceHistory> historyList = parent.getCreateChildResourceRequests();

            assert historyList.size() == 1 : "Incorrect number of children found. Expected: 1, Found: "
                + historyList.size();

            CreateResourceHistory historyItem = historyList.get(0);

            assert historyItem.getStatus() == CreateResourceStatus.SUCCESS : "Incorrect status for history item. Expected: Success, Found: "
                + historyItem.getStatus();
            assert historyItem.getNewResourceKey().equals("mockResourceKey") : "Incorrect resource key for history item. Expected: mockResourceKey, Found: "
                + historyItem.getNewResourceKey();
            assert historyItem.getErrorMessage() == null : "Error message found for successful call";
            assert historyItem.getConfiguration() != null : "Null configuration found for history item";
        } finally {
            getTransactionManager().rollback();
        }
    }
View Full Code Here

            List<CreateResourceHistory> historyList = parent.getCreateChildResourceRequests();

            assert historyList.size() == 1 : "Incorrect number of children found. Expected: 1, Found: "
                + historyList.size();

            CreateResourceHistory historyItem = historyList.get(0);

            assert historyItem.getStatus() == CreateResourceStatus.FAILURE : "Incorrect status for history item. Expected: Failure, Found: "
                + historyItem.getStatus();
            assert historyItem.getErrorMessage().equals("errorMessage") : "Incorrect error message for history item. Expected: errorMessage, Found: "
                + historyItem.getErrorMessage();
        } finally {
            getTransactionManager().rollback();
        }
    }
View Full Code Here

        Configuration resourceConfiguration = new Configuration();
        resourceConfiguration.put(new PropertySimple("property1", "value1"));

        // Test
        CreateResourceHistory history1 = resourceFactoryManager.createResource(overlord, parentResource.getId(),
            configBackedChildResourceType2.getId(), "newResource", null, resourceConfiguration);

        // Verify
        try {
            getTransactionManager().begin();

            Resource parent = em.find(Resource.class, parentResource.getId());
            List<CreateResourceHistory> historyList = parent.getCreateChildResourceRequests();

            assert historyList.size() == 1 : "Incorrect number of children found. Expected: 1, Found: "
                + historyList.size();

            CreateResourceHistory historyItem = historyList.get(0);

            assert historyItem.getStatus() == CreateResourceStatus.SUCCESS : "Incorrect status for history item. Expected: Success, Found: "
                + historyItem.getStatus();
            assert historyItem.getNewResourceKey().equals("mockResourceKey") : "Incorrect resource key for history item. Expected: mockResourceKey, Found: "
                + historyItem.getNewResourceKey();
            assert historyItem.getErrorMessage() == null : "Error message found for successful call";
            assert historyItem.getConfiguration() != null : "Null configuration found for history item";
        } finally {
            getTransactionManager().rollback();
        }

        // Invoke the same callbacks the plugin container would to actually commit the new Resource to inventory.
        resourceFactoryManager.completeCreateResource(new CreateResourceResponse(history1.getId(), "newResource",
            "key", CreateResourceStatus.SUCCESS, null, new Configuration()));
        Resource resource = new Resource(1000000);
        resource.setUuid(UUID.randomUUID().toString());
        resource.setResourceType(configBackedChildResourceType2);
        long randomLong = UUID.randomUUID().getLeastSignificantBits();
        resource.setResourceKey(String.valueOf("key-" + randomLong));
        resource.setName("name-" + randomLong);
        resource.setParentResource(parentResource);
        discoveryBoss.addResource(resource, overlord.getId());

        // Now try to create another Resource of the same singleton type - this should fail.
        try {
            CreateResourceHistory history2 = resourceFactoryManager.createResource(overlord, parentResource.getId(),
                configBackedChildResourceType2.getId(), "newResource2", null, resourceConfiguration);
            fail("Creating a singleton that already existed succeeded: " + history2);
        } catch (EJBException e) {
            assertEquals(String.valueOf(e.getCause()), RuntimeException.class, e.getCause().getClass());
            assertTrue(String.valueOf(e.getCause()), e.getCause().getMessage().contains("singleton"));
View Full Code Here

TOP

Related Classes of org.rhq.core.domain.resource.CreateResourceHistory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.