Package com.streamreduce.core.model

Examples of com.streamreduce.core.model.InventoryItem


        assertEquals(1, inventoryItems.size());
    }

    @Test
    public void testGetByExternalIdNotDeleted() throws Exception {
        InventoryItem deletedItem = inventoryService.createInventoryItem(testConnection,
                new JSONObjectBuilder().add("inventoryItemId",SAMPLE_EXTERNAL_ID).build());
        inventoryService.markInventoryItemDeleted(deletedItem);

        List<InventoryItem> inventoryItems = inventoryItemDAO.getByExternalId(SAMPLE_EXTERNAL_ID);
        assertEquals(2, inventoryItems.size());
View Full Code Here


                Account tAccount = (Account) target;
                extraMetadata.put("targetFuid", tAccount.getFuid());
                extraMetadata.put("targetName", tAccount.getName());

            } else if (target instanceof InventoryItem) {
                InventoryItem inventoryItem = (InventoryItem)target;
                Connection connection = inventoryItem.getConnection();
                ConnectionProvider tConnectionProvider = connectionProviderFactory.connectionProviderFromId(
                        connection.getProviderId());

                extraMetadata.put("targetExternalId", inventoryItem.getExternalId());
                extraMetadata.put("targetExternalType", inventoryItem.getType());

                extraMetadata.put("targetConnectionId", connection.getId());
                extraMetadata.put("targetConnectionAlias", connection.getAlias());
                extraMetadata.put("targetConnectionHashtags", connection.getHashtags());
                extraMetadata.put("targetConnectionVersion", connection.getVersion());
View Full Code Here

            }

            // See if the user specified an inventory item to associate the message and/or metrics to
            String inventoryItemId = getJSON(entry, "inventoryItemId");
            String message = getJSON(entry, "message");
            InventoryItem inventoryItem = null;

            if (inventoryItemId != null) {
                try {
                    inventoryItem = inventoryService.getInventoryItemForExternalId(connection, inventoryItemId);
                } catch (InventoryItemNotFoundException e) {
View Full Code Here

                Account tAccount = (Account) expectedTarget;

                expectedObjectMetadata.put("targetFuid", tAccount.getFuid());
                expectedObjectMetadata.put("targetName", tAccount.getName());
            } else if (expectedTarget instanceof InventoryItem) {
                InventoryItem tInventoryItem = (InventoryItem) expectedTarget;
                Connection tConnection = tInventoryItem.getConnection();
                ConnectionProvider tConnectionProvider =
                        applicationManager.getConnectionProviderFactory()
                                .connectionProviderFromId(tConnection.getProviderId());
                Map<String, Object> expectedInventoryItemMetadata = new HashMap<>();
                InventoryService inventoryService = applicationManager.getInventoryService();

                expectedObjectMetadata.put("targetExternalId", tInventoryItem.getExternalId());

                expectedInventoryItemMetadata.put("targetConnectionId", tConnection.getId());
                expectedInventoryItemMetadata.put("targetConnectionAlias", tConnection.getAlias());
                expectedInventoryItemMetadata.put("targetConnectionHashtags", tConnection.getHashtags());
                expectedInventoryItemMetadata.put("targetConnectionVersion", tConnection.getVersion());
                expectedInventoryItemMetadata.put("targetProviderId", tConnectionProvider.getId());
                expectedInventoryItemMetadata.put("targetProviderDisplayName", tConnectionProvider.getDisplayName());
                expectedInventoryItemMetadata.put("targetProviderType", tConnectionProvider.getType());

                if (tInventoryItem.getConnection().getProviderId().equals(ProviderIdConstants.AWS_PROVIDER_ID)) {
                    Location zone = inventoryService.getLocationByScope(tInventoryItem, LocationScope.ZONE);
                    Location region = inventoryService.getLocationByScope(tInventoryItem, LocationScope.REGION);
                    Set<String> iso3166Codes = zone != null ? zone.getIso3166Codes() : null;
                    String iso3166Code = iso3166Codes != null && iso3166Codes.size() >= 1 ?
                            iso3166Codes.iterator().next() :
                            null;

                    if (tInventoryItem.getType().equals(Constants.COMPUTE_INSTANCE_TYPE)) {
                        expectedObjectMetadata.put("targetIP",
                                inventoryService.getComputeInstanceIPAddress(tInventoryItem));
                        expectedObjectMetadata.put("targetOS",
                                inventoryService.getComputeInstanceOSName(tInventoryItem));
                    }
View Full Code Here

     * @response.representation.404.doc Returned when the client attempts to retrieve an inventory item that does not exist
     */
    @GET
    @Path("{itemId}")
    public Response getInventoryItem(@PathParam("itemId") ObjectId itemId) {
        InventoryItem inventoryItem;

        try {
            inventoryItem = applicationManager.getInventoryService().getInventoryItem(itemId);
        } catch (InventoryItemNotFoundException e) {
            return error(e.getMessage(), Response.status(Response.Status.NOT_FOUND));
View Full Code Here

     */
    @PUT
    @Path("{itemId}")
    @Consumes(MediaType.APPLICATION_JSON)
    public Response updateInventoryItem(@PathParam("itemId") ObjectId itemId, JSONObject json) {
        InventoryItem inventoryItem;

        try {
            inventoryItem = applicationManager.getInventoryService().getInventoryItem(itemId);
        } catch (InventoryItemNotFoundException e) {
            return error(e.getMessage(), Response.status(Response.Status.NOT_FOUND));
        }

        // only the owner can do this...
        if (!isOwner(inventoryItem.getConnection().getUser())) {
            return error(ErrorMessages.APPLICATION_ACCESS_DENIED, Response.status(Response.Status.BAD_REQUEST));
        }

        inventoryItem.mergeWithJSON(json);

        try {
            applicationManager.getInventoryService().updateInventoryItem(inventoryItem, json);
        } catch (ConnectionNotFoundException e) {
            return error("Unable to find the connection for the inventory item requested.",
View Full Code Here

        if (isEmpty(hashtag)) {
            return error("Hashtag payload is empty", Response.status(Response.Status.BAD_REQUEST));
        }

        InventoryItem inventoryItem;

        try {
            inventoryItem = applicationManager.getInventoryService().getInventoryItem(new ObjectId(itemId));
        } catch (InventoryItemNotFoundException e) {
            return error(e.getMessage(), Response.status(Response.Status.NOT_FOUND));
        }

        // limit to same account
        if (!isInAccount(inventoryItem.getConnection().getAccount())) {
            return error(ErrorMessages.APPLICATION_ACCESS_DENIED, Response.status(Response.Status.BAD_REQUEST));
        }

        applicationManager.getInventoryService().addHashtag(inventoryItem,
                                                            applicationManager.getSecurityService().getCurrentUser(),
View Full Code Here

     */
    @GET
    @Path("{itemId}/hashtag")
    @Override
    public Response getTags(@PathParam("itemId") String itemId) {
        InventoryItem inventoryItem;

        try {
            inventoryItem = applicationManager.getInventoryService().getInventoryItem(new ObjectId(itemId));
        } catch (InventoryItemNotFoundException e) {
            return error(e.getMessage(), Response.status(Response.Status.NOT_FOUND));
        }

        // limit to same account
        if (!isInAccount(inventoryItem.getConnection().getAccount())) {
            return error(ErrorMessages.APPLICATION_ACCESS_DENIED, Response.status(Response.Status.BAD_REQUEST));
        }

        return Response
                .ok(inventoryItem.getHashtags())
                .build();

    }
View Full Code Here

    public Response removeTag(@PathParam("itemId") String itemId, @PathParam("tagname") String hashtag) {
        if (isEmpty(hashtag)) {
            return error("Hashtag payload is empty", Response.status(Response.Status.BAD_REQUEST));
        }

        InventoryItem inventoryItem;

        try {
            inventoryItem = applicationManager.getInventoryService().getInventoryItem(new ObjectId(itemId));
        } catch (InventoryItemNotFoundException e) {
            return error(e.getMessage(), Response.status(Response.Status.NOT_FOUND));
        }

        // limit to same account
        if (!isInAccount(inventoryItem.getConnection().getAccount())) {
            return error(ErrorMessages.APPLICATION_ACCESS_DENIED, Response.status(Response.Status.BAD_REQUEST));
        }

        applicationManager.getInventoryService().removeHashtag(inventoryItem, applicationManager.getSecurityService().getCurrentUser(), hashtag);
        return Response.ok().build();
View Full Code Here

     */
    @PUT
    @Path("{itemId}/reboot")
    public Response reboot(@PathParam("itemId") ObjectId itemId) {
        InventoryService inventoryService = applicationManager.getInventoryService();
        InventoryItem inventoryItem;

        try {
            inventoryItem = inventoryService.getInventoryItem(itemId);
        } catch (InventoryItemNotFoundException e) {
            return error(e.getMessage(), Response.status(Response.Status.NOT_FOUND));
        }

        if (!(inventoryItem.getType().equals(Constants.COMPUTE_INSTANCE_TYPE))) {
            return error("You can only reboot cloud inventory items.", Response.status(Response.Status.BAD_REQUEST));
        }

        try {
            // only the owner can do this...
            if (!isOwner(inventoryItem.getConnection().getUser())) {
                return error(ErrorMessages.APPLICATION_ACCESS_DENIED, Response.status(Response.Status.BAD_REQUEST));
            }

            inventoryService.rebootComputeInstance(inventoryItem);
        } catch (CommandNotAllowedException cnae) {
View Full Code Here

TOP

Related Classes of com.streamreduce.core.model.InventoryItem

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.