Examples of InventoryItem


Examples of com.streamreduce.core.model.InventoryItem

     */
    @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

Examples of com.streamreduce.core.model.InventoryItem

     */
    @DELETE
    @Path("{itemId}")
    public Response deleteInventoryItem(@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));
        }

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

        inventoryService.deleteInventoryItem(inventoryItem);

View Full Code Here

Examples of com.streamreduce.core.model.InventoryItem

                .build();

        connectionDAO.save(stubConnection);

        for (int i = 0; i < 100; i++) { // create 100 inventory items
            InventoryItem item = new InventoryItem.Builder()
                    .connection(stubConnection)
                    .hashtags(Sets.newHashSet("#foo", "#bar", "#baz", "#github"))
                    .alias("stubItem" + Integer.toString(i))
                    .description("stubItem:  " + Integer.toString(i))
                    .user(testUser)
View Full Code Here

Examples of com.streamreduce.core.model.InventoryItem

            throws ConnectionNotFoundException, InvalidCredentialsException, IOException {
        Preconditions.checkNotNull(connection, "connection cannot be null.");
        Preconditions.checkNotNull(json, "json cannot be null.");

        String providerId = connection.getProviderId();
        InventoryItem inventoryItem = new InventoryItem();

        inventoryItem.setAccount(connection.getAccount());
        inventoryItem.setUser(connection.getUser());
        inventoryItem.setConnection(connection);
        inventoryItem.addHashtag(connection.getProviderId());
        inventoryItem.setDeleted(false);

        // Default to visibility of the connection (Should be overridden below if required)
        inventoryItem.setVisibility(connection.getVisibility());

        // No other way...  polymorphism is Hard...
        if (providerId.equals(ProviderIdConstants.AWS_PROVIDER_ID)) {
            extendAWSInventoryItem(inventoryItem, json);
        } else if (providerId.equals(ProviderIdConstants.GITHUB_PROVIDER_ID)) {
            extendGitHubInventoryItem(inventoryItem, json);
        } else if (providerId.equals(ProviderIdConstants.GOOGLE_ANALYTICS_PROVIDER_ID)) {
            extendGoogleAnalyticsInventoryItem(inventoryItem, json);
        } else if (providerId.equals(ProviderIdConstants.JIRA_PROVIDER_ID)) {
            extendJiraInventoryItem(inventoryItem, json);
        } else if (providerId.equals(ProviderIdConstants.PINGDOM_PROVIDER_ID)) {
            extendPingdomInventoryItem(inventoryItem, json);
        } else if (providerId.equals(ProviderIdConstants.CUSTOM_PROVIDER_ID)) {
            extendGenericInventoryItem(inventoryItem, json);
        } else if (providerId.equals(ProviderIdConstants.NAGIOS_PROVIDER_ID)) {
            extendGenericInventoryItem(inventoryItem, json);
        } else {
            throw new IllegalArgumentException(providerId + " does not support creating inventory items.");
        }

        // Create metadata
        DBObject metadataEntry =
                genericCollectionDAO.createCollectionEntry(DAODatasourceType.BUSINESS,
                                                           Constants.INVENTORY_ITEM_METADATA_COLLECTION_NAME,
                                                           json.toString());

        inventoryItem.setMetadataId((ObjectId)metadataEntry.get("_id"));

        // Persist the inventory item
        inventoryItemDAO.save(inventoryItem);

        // Create the event
View Full Code Here

Examples of com.streamreduce.core.model.InventoryItem

            logger.error("Error updating project hosting inventory item cache: " + inventoryItem.getId(), e);
        }

        // Send a silent update if none of our internal properties have changed
        boolean silentUpdate = false;
        InventoryItem oldInventoryItem;

        try {
            oldInventoryItem = getInventoryItem(inventoryItem.getId());
        } catch (InventoryItemNotFoundException e) {
            // Should never happen but just in case
            oldInventoryItem = null;
        }

        // Be silent unless alias, description, hashtags or visibility are different.  (None of the other properties
        // should be changeable externally or via our exposed APIs.)
        if (oldInventoryItem != null) {
            silentUpdate = (Objects.equal(oldInventoryItem.getAlias(), inventoryItem.getAlias()) &&
                    Objects.equal(oldInventoryItem.getDescription(), inventoryItem.getDescription()) &&
                    Objects.equal(oldInventoryItem.getHashtags(), inventoryItem.getHashtags()) &&
                    Objects.equal(oldInventoryItem.getVisibility(), inventoryItem.getVisibility()));
        }

        // Persist the inventory item
        return updateInventoryItem(inventoryItem, silentUpdate);
    }
View Full Code Here

Examples of com.streamreduce.core.model.InventoryItem

    /**
     * {@inheritDoc}
     */
    @Override
    public InventoryItem getInventoryItem(ObjectId objectId) throws InventoryItemNotFoundException {
        InventoryItem inventoryItem = inventoryItemDAO.get(objectId);

        if (inventoryItem == null) {
            throw new InventoryItemNotFoundException(objectId.toString());
        }

View Full Code Here

Examples of com.streamreduce.core.model.InventoryItem

    public InventoryItem getInventoryItemForExternalId(Connection connection, String externalId)
            throws InventoryItemNotFoundException {
        Preconditions.checkNotNull(connection, "connection cannot be null.");
        Preconditions.checkNotNull(externalId, "externalId cannot be null.");

        InventoryItem inventoryItem = inventoryItemDAO.getInventoryItem(connection, externalId);

        if (inventoryItem == null) {
            throw new InventoryItemNotFoundException("No inventory item for connection [" + connection.getId() + "] " +
                    "with the given externalId of " + externalId);
        }
View Full Code Here

Examples of com.streamreduce.core.model.InventoryItem

        logger.debug("  Provider id: " + connection.getProviderId());
        logger.debug("  Inventory items found: " + externalInventoryItems.size());

        for (JSONObject json : externalInventoryItems) {
            InventoryItem inventoryItem = null;
            JSONObject externalInventoryItemAsJSON;
            String externalId;

            if (client instanceof AWSClient) {
                String type = json.getString("type");

                if (type.equals(ComputeType.NODE.toString())) {
                    externalId = json.getString("providerId");
                } else {
                    externalId = json.getString("name");
                }
                externalInventoryItemAsJSON = json;
            } else if (client instanceof GitHubClient) {
                externalId = json.getJSONObject("owner").getString("login") + "/" + json.getString("name");
                externalInventoryItemAsJSON = json;
            } else if (client instanceof PingdomClient) {
                externalId = json.getString("id");
                externalInventoryItemAsJSON = json;
            } else if (client instanceof GoogleAnalyticsClient) {
                externalId = json.getString("id");
                externalInventoryItemAsJSON = json;
            } else {
                externalId = json.getString("key");
                try {
                    externalInventoryItemAsJSON = ((JiraClient)client).getProjectDetails(externalId);
                } catch (InvalidCredentialsException | IOException e) {
                    // This should never happen as we've already validated the connection by this point
                    logger.warn("Unable to get the Jira project details for " + externalId + ": " + e.getMessage());
                    return;
                }
            }

            try {
                inventoryItem = getInventoryItemForExternalId(connection, externalId);
            } catch (InventoryItemNotFoundException e) {
                // This is more than possible and is handled below
            }

            if (inventoryItem == null || inventoryItem.isDeleted()) {
                if (inventoryItem != null && inventoryItem.isDeleted()) {
                    // Permanently remove the current inventory item marked as deleted.  This can happen if you mark
                    // an inventory item as deleted (due to external deletion) and then recreate the same inventory
                    // item externally before the clean process (ran after refresh) could occur.
                    deleteInventoryItem(inventoryItem);
                }

                createInventoryItem(connection, externalInventoryItemAsJSON);
            } else if (!processedKeys.contains(externalId)) {
                updateInventoryItem(inventoryItem, externalInventoryItemAsJSON);
            }

            processedKeys.add(externalId);
        }

        // Handle inventory items deleted externally
        List<InventoryItem> inventoryItems = getInventoryItems(connection);

        for (InventoryItem inventoryItem : inventoryItems) {
            if (processedKeys.contains(inventoryItem.getExternalId())) {
                continue;
            }

            // Just mark the item as deleted.  Future polling jobs will remove the inventory item marked as deleted
            // when appropriate.
            if (!inventoryItem.isDeleted()) {
                markInventoryItemDeleted(inventoryItem);
            }
        }
    }
View Full Code Here

Examples of com.streamreduce.core.model.InventoryItem

        Date lastActivity = lastActivityPoll;

        try {
            for (JSONObject entry : feedEntries) {
                String projectKey = entry.getJSONObject("repo").getString("name");
                InventoryItem inventoryItem = inventoryItemMap.get(projectKey);

                if (inventoryItem == null) {
                    continue;
                }
View Full Code Here

Examples of com.streamreduce.core.model.InventoryItem

    public void testSuccessfulInventoryItemMessages() throws Exception {
        List<InventoryItem> inventoryItems = inventoryService.getInventoryItems(connection.getId());
        int connectionEventCount = getEventsForTarget(connection.getId()).size();
        JSONObject json = new JSONObject();
        List<Event> events;
        InventoryItem inventoryItem;
        int originalEventCount;

        assertEquals(0, inventoryItems.size());

        json.put("message", "Creating a new IMG inventory item.");
        json.put("inventoryItemId", "testNodeId");

        assertEquals("201", makeRequest(imgBaseUrl, "POST", json, apiKey, AuthTokenType.GATEWAY));

        inventoryItems = inventoryService.getInventoryItems(connection.getId());

        // Make sure the connection isn't receiving the event
        assertEquals(connectionEventCount, getEventsForTarget(connection.getId()).size());
        // Make sure the inventory item was created
        assertEquals(1, inventoryItems.size());

        inventoryItem = inventoryItems.get(0);
        events = getEventsForTarget(inventoryItem.getId());
        originalEventCount = events.size();

        validateEvent(events.get(events.size() - 1), json);

        json = new JSONObject();

        json.put("inventoryItemId", "testNodeId");
        json.put("hashtags", ImmutableSet.of("#testing", "#test"));
        json.put("superfluous", "This is a superfluous property.");

        JSONArray metrics = new JSONArray();

        for (int i = 0; i < 2; i++) {
            JSONObject metric = new JSONObject();

            metric.put("name", "Test Metric" + (i + 1));
            metric.put("type", "DELTA");
            metric.put("value", (i + 1));

            metrics.add(metric);
        }

        json.put("metrics", metrics);

        assertEquals("201", makeRequest(imgBaseUrl, "POST", json, apiKey, AuthTokenType.GATEWAY));

        events = getEventsForTarget(inventoryItem.getId());

        validateEvent(events.get(events.size() - 1), json);

        // Make sure the connection isn't receiving the event
        assertEquals(connectionEventCount, getEventsForTarget(connection.getId()).size());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.