PageRenderTime 33ms CodeModel.GetById 18ms app.highlight 14ms RepoModel.GetById 0ms app.codeStats 0ms

/jboss-as-7.1.1.Final/controller-client/src/main/java/org/jboss/as/controller/client/helpers/domain/impl/DeploymentPlanResultImpl.java

#
Java | 139 lines | 89 code | 23 blank | 27 comment | 16 complexity | 5b4ed6d03b6709b2834ed9268dad5fd2 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1/*
  2 * JBoss, Home of Professional Open Source.
  3 * Copyright 2010, Red Hat, Inc., and individual contributors
  4 * as indicated by the @author tags. See the copyright.txt file in the
  5 * distribution for a full listing of individual contributors.
  6 *
  7 * This is free software; you can redistribute it and/or modify it
  8 * under the terms of the GNU Lesser General Public License as
  9 * published by the Free Software Foundation; either version 2.1 of
 10 * the License, or (at your option) any later version.
 11 *
 12 * This software is distributed in the hope that it will be useful,
 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 15 * Lesser General Public License for more details.
 16 *
 17 * You should have received a copy of the GNU Lesser General Public
 18 * License along with this software; if not, write to the Free
 19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 21 */
 22
 23package org.jboss.as.controller.client.helpers.domain.impl;
 24
 25import static org.jboss.as.controller.client.ControllerClientMessages.MESSAGES;
 26
 27import java.util.Collections;
 28import java.util.HashMap;
 29import java.util.Map;
 30import java.util.UUID;
 31
 32import org.jboss.as.controller.client.helpers.domain.DeploymentActionResult;
 33import org.jboss.as.controller.client.helpers.domain.DeploymentPlan;
 34import org.jboss.as.controller.client.helpers.domain.DeploymentPlanResult;
 35import org.jboss.as.controller.client.helpers.domain.InvalidDeploymentPlanException;
 36import org.jboss.as.controller.client.helpers.domain.ServerGroupDeploymentActionResult;
 37import org.jboss.as.controller.client.helpers.domain.ServerGroupDeploymentPlanResult;
 38import org.jboss.as.controller.client.helpers.domain.ServerUpdateResult;
 39
 40
 41/**
 42 * Default implementation of {@link DeploymentPlanResult}.
 43 *
 44 * @author Brian Stansberry
 45 */
 46public class DeploymentPlanResultImpl implements DeploymentPlanResult {
 47
 48    private final DeploymentPlan plan;
 49    private final InvalidDeploymentPlanException idpe;
 50    private final Map<UUID, DeploymentActionResult> results;
 51    private Map<String, ServerGroupDeploymentPlanResult> resultsByServerGroup;
 52
 53    public DeploymentPlanResultImpl(final DeploymentPlan plan, final Map<UUID, DeploymentActionResult> results) {
 54        assert plan != null : "plan is null";
 55        assert results != null : "results is null";
 56        this.plan = plan;
 57        this.idpe = null;
 58        this.results = results;
 59    }
 60
 61    public DeploymentPlanResultImpl(final DeploymentPlan plan, final InvalidDeploymentPlanException invalidPlanException) {
 62        if (plan == null)
 63            throw MESSAGES.nullVar("plan");
 64        if (invalidPlanException == null)
 65            throw MESSAGES.nullVar("invalidPlanException");
 66        this.plan = plan;
 67        this.results = null;
 68        this.idpe = invalidPlanException;
 69    }
 70
 71    @Override
 72    public Map<UUID, DeploymentActionResult> getDeploymentActionResults() {
 73        return Collections.unmodifiableMap(results);
 74    }
 75
 76    @Override
 77    public UUID getId() {
 78        return plan.getId();
 79    }
 80
 81    @Override
 82    public DeploymentPlan getDeploymentPlan() {
 83        return plan;
 84    }
 85
 86    @Override
 87    public InvalidDeploymentPlanException getInvalidDeploymentPlanException() {
 88        return idpe;
 89    }
 90
 91    @Override
 92    public boolean isValid() {
 93        return idpe == null;
 94    }
 95
 96    @Override
 97    public synchronized Map<String, ServerGroupDeploymentPlanResult> getServerGroupResults() {
 98        if (resultsByServerGroup == null) {
 99            this.resultsByServerGroup = buildServerGroupResults(results);
100        }
101        return Collections.unmodifiableMap(resultsByServerGroup);
102    }
103
104    // Builds the data structures that show the effects of the plan by server group
105    private static Map<String, ServerGroupDeploymentPlanResult> buildServerGroupResults(Map<UUID, DeploymentActionResult> deploymentActionResults) {
106        Map<String, ServerGroupDeploymentPlanResult> serverGroupResults = new HashMap<String, ServerGroupDeploymentPlanResult>();
107
108        for (Map.Entry<UUID, DeploymentActionResult> entry : deploymentActionResults.entrySet()) {
109
110            UUID actionId = entry.getKey();
111            DeploymentActionResult actionResult = entry.getValue();
112
113            Map<String, ServerGroupDeploymentActionResult> actionResultsByServerGroup = actionResult.getResultsByServerGroup();
114            for (ServerGroupDeploymentActionResult serverGroupActionResult : actionResultsByServerGroup.values()) {
115                String serverGroupName = serverGroupActionResult.getServerGroupName();
116
117                ServerGroupDeploymentPlanResultImpl sgdpr = (ServerGroupDeploymentPlanResultImpl) serverGroupResults.get(serverGroupName);
118                if (sgdpr == null) {
119                    sgdpr = new ServerGroupDeploymentPlanResultImpl(serverGroupName);
120                    serverGroupResults.put(serverGroupName, sgdpr);
121                }
122
123                for (Map.Entry<String, ServerUpdateResult> serverEntry : serverGroupActionResult.getResultByServer().entrySet()) {
124                    String serverName = serverEntry.getKey();
125                    ServerUpdateResult sud = serverEntry.getValue();
126                    ServerDeploymentPlanResultImpl sdpr = (ServerDeploymentPlanResultImpl) sgdpr.getServerResult(serverName);
127                    if (sdpr == null) {
128                        sdpr = new ServerDeploymentPlanResultImpl(serverName);
129                        sgdpr.storeServerResult(serverName, sdpr);
130                    }
131                    sdpr.storeServerUpdateResult(actionId, sud);
132                }
133            }
134        }
135        return serverGroupResults;
136    }
137
138
139}