PageRenderTime 44ms CodeModel.GetById 16ms 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. package org.jboss.as.controller.client.helpers.domain.impl;
  23. import static org.jboss.as.controller.client.ControllerClientMessages.MESSAGES;
  24. import java.util.Collections;
  25. import java.util.HashMap;
  26. import java.util.Map;
  27. import java.util.UUID;
  28. import org.jboss.as.controller.client.helpers.domain.DeploymentActionResult;
  29. import org.jboss.as.controller.client.helpers.domain.DeploymentPlan;
  30. import org.jboss.as.controller.client.helpers.domain.DeploymentPlanResult;
  31. import org.jboss.as.controller.client.helpers.domain.InvalidDeploymentPlanException;
  32. import org.jboss.as.controller.client.helpers.domain.ServerGroupDeploymentActionResult;
  33. import org.jboss.as.controller.client.helpers.domain.ServerGroupDeploymentPlanResult;
  34. import org.jboss.as.controller.client.helpers.domain.ServerUpdateResult;
  35. /**
  36. * Default implementation of {@link DeploymentPlanResult}.
  37. *
  38. * @author Brian Stansberry
  39. */
  40. public class DeploymentPlanResultImpl implements DeploymentPlanResult {
  41. private final DeploymentPlan plan;
  42. private final InvalidDeploymentPlanException idpe;
  43. private final Map<UUID, DeploymentActionResult> results;
  44. private Map<String, ServerGroupDeploymentPlanResult> resultsByServerGroup;
  45. public DeploymentPlanResultImpl(final DeploymentPlan plan, final Map<UUID, DeploymentActionResult> results) {
  46. assert plan != null : "plan is null";
  47. assert results != null : "results is null";
  48. this.plan = plan;
  49. this.idpe = null;
  50. this.results = results;
  51. }
  52. public DeploymentPlanResultImpl(final DeploymentPlan plan, final InvalidDeploymentPlanException invalidPlanException) {
  53. if (plan == null)
  54. throw MESSAGES.nullVar("plan");
  55. if (invalidPlanException == null)
  56. throw MESSAGES.nullVar("invalidPlanException");
  57. this.plan = plan;
  58. this.results = null;
  59. this.idpe = invalidPlanException;
  60. }
  61. @Override
  62. public Map<UUID, DeploymentActionResult> getDeploymentActionResults() {
  63. return Collections.unmodifiableMap(results);
  64. }
  65. @Override
  66. public UUID getId() {
  67. return plan.getId();
  68. }
  69. @Override
  70. public DeploymentPlan getDeploymentPlan() {
  71. return plan;
  72. }
  73. @Override
  74. public InvalidDeploymentPlanException getInvalidDeploymentPlanException() {
  75. return idpe;
  76. }
  77. @Override
  78. public boolean isValid() {
  79. return idpe == null;
  80. }
  81. @Override
  82. public synchronized Map<String, ServerGroupDeploymentPlanResult> getServerGroupResults() {
  83. if (resultsByServerGroup == null) {
  84. this.resultsByServerGroup = buildServerGroupResults(results);
  85. }
  86. return Collections.unmodifiableMap(resultsByServerGroup);
  87. }
  88. // Builds the data structures that show the effects of the plan by server group
  89. private static Map<String, ServerGroupDeploymentPlanResult> buildServerGroupResults(Map<UUID, DeploymentActionResult> deploymentActionResults) {
  90. Map<String, ServerGroupDeploymentPlanResult> serverGroupResults = new HashMap<String, ServerGroupDeploymentPlanResult>();
  91. for (Map.Entry<UUID, DeploymentActionResult> entry : deploymentActionResults.entrySet()) {
  92. UUID actionId = entry.getKey();
  93. DeploymentActionResult actionResult = entry.getValue();
  94. Map<String, ServerGroupDeploymentActionResult> actionResultsByServerGroup = actionResult.getResultsByServerGroup();
  95. for (ServerGroupDeploymentActionResult serverGroupActionResult : actionResultsByServerGroup.values()) {
  96. String serverGroupName = serverGroupActionResult.getServerGroupName();
  97. ServerGroupDeploymentPlanResultImpl sgdpr = (ServerGroupDeploymentPlanResultImpl) serverGroupResults.get(serverGroupName);
  98. if (sgdpr == null) {
  99. sgdpr = new ServerGroupDeploymentPlanResultImpl(serverGroupName);
  100. serverGroupResults.put(serverGroupName, sgdpr);
  101. }
  102. for (Map.Entry<String, ServerUpdateResult> serverEntry : serverGroupActionResult.getResultByServer().entrySet()) {
  103. String serverName = serverEntry.getKey();
  104. ServerUpdateResult sud = serverEntry.getValue();
  105. ServerDeploymentPlanResultImpl sdpr = (ServerDeploymentPlanResultImpl) sgdpr.getServerResult(serverName);
  106. if (sdpr == null) {
  107. sdpr = new ServerDeploymentPlanResultImpl(serverName);
  108. sgdpr.storeServerResult(serverName, sdpr);
  109. }
  110. sdpr.storeServerUpdateResult(actionId, sud);
  111. }
  112. }
  113. }
  114. return serverGroupResults;
  115. }
  116. }