Search in sources :

Example 1 with Pair

use of io.fabric8.utils.Pair in project docker-maven-plugin by fabric8io.

the class UrlBuilderTest method listContainers.

@Test
public void listContainers() throws MalformedURLException, UnsupportedEncodingException, URISyntaxException {
    UrlBuilder builder = new UrlBuilder("", "1.0");
    assertEquals(new URI("/1.0/containers/json"), new URI(builder.listContainers()));
    assertEquals(new URI("/1.0/containers/json?filters=" + URLEncoder.encode("{\"ancestor\":[\"nginx\"]}", "UTF8")), new URI(builder.listContainers("ancestor", "nginx")));
    try {
        builder.listContainers("ancestor");
        fail();
    } catch (IllegalArgumentException exp) {
        assertTrue(exp.getMessage().contains("pair"));
    }
}
Also used : UrlBuilder(io.fabric8.maven.docker.access.UrlBuilder) Test(org.junit.Test)

Example 2 with Pair

use of io.fabric8.utils.Pair in project mudmap2 by Neop.

the class ExportImageDialog method updateImageSize.

/**
 * Updates the displayed image size
 */
void updateImageSize() {
    if (centerPosition == null) {
        centerPosition = new WorldCoordinate(worldTab.getWorldPanel().getPosition());
    }
    Pair<Integer, Integer> imageSize = new Pair<>(0, 0);
    if (rbCurrentView.isSelected()) {
        imageSize.first = worldTab.getWorldPanel().getWidth();
        imageSize.second = worldTab.getWorldPanel().getHeight();
    } else if (rbCurrentMap.isSelected()) {
        Layer layer = worldTab.getWorld().getLayer(centerPosition.getLayer());
        imageSize = getMapSize(layer);
    } else if (rbAllMaps.isSelected()) {
        for (Layer layer : worldTab.getWorld().getLayers()) {
            // get largest image by area
            Pair<Integer, Integer> imageSize2 = getMapSize(layer);
            if (imageSize.first * imageSize.second < imageSize2.first * imageSize2.second) {
                imageSize = imageSize2;
            }
        }
    } else if (rbSelection.isSelected()) {
        HashSet<Place> places = worldTab.getWorldPanel().placeGroupGetSelection();
        imageSize = getSelectionSize(places);
    }
    imageWidth = imageSize.first;
    imageHeight = imageSize.second;
    lImageSize.setText("Image size: " + imageWidth + "x" + imageHeight + "px");
}
Also used : WorldCoordinate(mudmap2.backend.WorldCoordinate) Layer(mudmap2.backend.Layer) Pair(mudmap2.utils.Pair) HashSet(java.util.HashSet)

Example 3 with Pair

use of io.fabric8.utils.Pair in project mudmap2 by Neop.

the class MapPainterDefault method getExitOffset.

/**
 * Calculates the offset of the exit visualization (dot/circle) to the
 * upper left corner of a tile
 * @param dir eit direction
 * @return false if the dot/circle doesn't have to be drawn
 */
private Pair<Integer, Integer> getExitOffset(String dir) {
    Pair<Integer, Integer> ret = new Pair<>(0, 0);
    int borderWidth = getTileBorderWidth();
    switch(dir) {
        case "n":
            // north
            ret.first = tileSize / 2;
            ret.second = borderWidth;
            break;
        case "e":
            // east
            ret.first = tileSize - borderWidth;
            ret.second = tileSize / 2;
            break;
        case "s":
            // south
            ret.first = tileSize / 2;
            ret.second = tileSize - borderWidth;
            break;
        case "w":
            // west
            ret.first = borderWidth;
            ret.second = tileSize / 2;
            break;
        case "ne":
            // north-east
            ret.first = tileSize - borderWidth;
            ret.second = borderWidth;
            break;
        case "se":
            // south-east
            ret.first = ret.second = tileSize - borderWidth;
            break;
        case "nw":
            // north-west
            ret.first = ret.second = borderWidth;
            break;
        case "sw":
            // south-west
            ret.first = borderWidth;
            ret.second = tileSize - borderWidth;
            break;
        default:
            ret.first = ret.second = tileSize / 2;
            break;
    }
    return ret;
}
Also used : GradientPaint(java.awt.GradientPaint) Pair(mudmap2.utils.Pair)

Example 4 with Pair

use of io.fabric8.utils.Pair in project mudmap2 by Neop.

the class MapPainterDefault method paint.

@Override
public void paint(Graphics g, int tileSize, double graphicsWidth, double graphicsHeight, Layer layer, WorldCoordinate curPos) {
    this.graphicsWidth = graphicsWidth;
    this.graphicsHeight = graphicsHeight;
    this.tileSize = tileSize;
    this.curPos = curPos;
    tileFont = g.getFont();
    final float selectionStrokeWidth = getTileSelectionStrokeWidth();
    final int tileBorderWidthScaled = getTileBorderWidth();
    // max number of text lines tht fit in a tile
    FontMetrics fm = g.getFontMetrics();
    final int maxLines = (int) Math.round((double) (tileSize - 3 * (tileBorderWidthScaled + (int) Math.ceil(getRiskLevelStrokeWidth()))) / fm.getHeight());
    final int maxLineLength = tileSize - 2 * (tileBorderWidthScaled + (int) selectionStrokeWidth + (int) Math.ceil(getRiskLevelStrokeWidth()));
    final Boolean drawText = fm.stringWidth("WW") < (tileSize - 2 * (getRiskLevelStrokeWidth() + getTileBorderWidth()));
    // screen center in world coordinates
    // note: wdtwd2
    final double screenCenterX = (graphicsWidth / tileSize) / 2.0;
    final double screenCenterY = (graphicsHeight / tileSize) / 2.0;
    final int placeXOffset = (int) (Math.round((float) curPos.getX()) - Math.round(screenCenterX));
    final int placeYOffset = (int) (Math.round((float) curPos.getY()) - Math.floor(screenCenterY));
    // more precalculation
    final double placeXpxConst = remint(screenCenterX) - remint(curPos.getX());
    final double placeYPXConst = remint(screenCenterY) + remint(curPos.getY());
    // prepare graphic for paths
    // Paths will be drawn on this graphic and later on copied to g
    // to mask out the tile positions on graphic_path
    ArrayList<Pair<Integer, Integer>> tilePositions = new ArrayList<>();
    BufferedImage imagePath = new BufferedImage((int) graphicsWidth, (int) graphicsHeight, BufferedImage.TYPE_INT_ARGB);
    Graphics graphicPath = imagePath.getGraphics();
    ((Graphics2D) graphicPath).setStroke(new BasicStroke(getPathStrokeWidth()));
    ((Graphics2D) graphicPath).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // getPlace the locations of copied places
    HashSet<Pair<Integer, Integer>> copiedPlaceLocations = mudmap2.CopyPaste.getCopyPlaceLocations();
    // clear screen
    if (backgroundColor == null) {
        g.clearRect(0, 0, (int) graphicsWidth + 1, (int) graphicsHeight + 1);
    } else {
        g.setColor(backgroundColor);
        g.fillRect(0, 0, (int) graphicsWidth + 1, (int) graphicsHeight + 1);
    }
    // ------------------ draw the grid --------------------------------
    if (isGridEnabled()) {
        g.setColor(Color.lightGray);
        for (int tileX = (g.getClipBounds().x / tileSize) - 1; tileX < graphicsWidth / tileSize + 1; ++tileX) {
            final int x = (int) Math.round((tileX + placeXpxConst) * tileSize);
            g.drawLine(x, 0, x, (int) graphicsHeight);
        }
        for (int tileY = (g.getClipBounds().y / tileSize) - 1; tileY < graphicsHeight / tileSize + 1; ++tileY) {
            final int y = (int) Math.round((tileY + placeYPXConst) * tileSize);
            g.drawLine(0, y, (int) graphicsWidth, y);
        }
    }
    // ------------------ draw the tiles / places ----------------------
    for (int tileX = (g.getClipBounds().x / tileSize) - 1; tileX < graphicsWidth / tileSize + 1; ++tileX) {
        for (int tileY = (g.getClipBounds().y / tileSize) - 1; tileY < graphicsHeight / tileSize + 1; ++tileY) {
            // place position on the map
            final int placeX = tileX + placeXOffset;
            final int placeY = (int) (graphicsHeight / tileSize) - tileY + placeYOffset;
            if (layer != null && layer.exist(placeX, placeY)) {
                Place curPlace = layer.get(placeX, placeY);
                // place position in pixel on the screen
                final int placeXpx = (int) Math.round((tileX + placeXpxConst) * tileSize);
                final int placeYpx = (int) Math.round((tileY + placeYPXConst) * tileSize);
                tilePositions.add(new Pair<>(placeXpx, placeYpx));
                // number of drawn text lines
                int lineNum = 0;
                // draw place group color
                if (curPlace.getPlaceGroup() != null) {
                    g.setColor(curPlace.getPlaceGroup().getColor());
                    g.fillRect(placeXpx, placeYpx, tileSize, tileSize);
                }
                // draw tile center color
                if (drawText) {
                    g.setColor(layer.getWorld().getTileCenterColor());
                    g.fillRect(placeXpx + tileBorderWidthScaled, placeYpx + tileBorderWidthScaled, tileSize - 2 * tileBorderWidthScaled, tileSize - 2 * tileBorderWidthScaled);
                }
                // draw risk level border
                if (curPlace.getRiskLevel() != null) {
                    g.setColor(curPlace.getRiskLevel().getColor());
                    ((Graphics2D) g).setStroke(new BasicStroke(getRiskLevelStrokeWidth()));
                    g.drawRect(placeXpx + tileBorderWidthScaled, placeYpx + tileBorderWidthScaled, tileSize - 2 * tileBorderWidthScaled - (int) (0.5 * getRiskLevelStrokeWidth()), tileSize - 2 * tileBorderWidthScaled - (int) (0.5 * getRiskLevelStrokeWidth()));
                }
                LinkedList<String> text = new LinkedList<>();
                String flags = "", exits = "";
                // draw text, if tiles are large enough
                if (drawText) {
                    g.setColor(Color.BLACK);
                    // place name
                    // gets place name if unique, else place name with ID
                    String placeName;
                    switch(layer.getWorld().getShowPlaceId()) {
                        default:
                        case UNIQUE:
                        case NONE:
                            // name only
                            placeName = curPlace.getName();
                            break;
                        case ALL:
                            // name and id
                            placeName = curPlace.toString();
                            break;
                    }
                    text.add(placeName);
                    int reclvlmin = curPlace.getRecLevelMin(), reclvlmax = curPlace.getRecLevelMax();
                    if (reclvlmin > -1 || reclvlmax > -1) {
                        String levelString = "lvl " + (reclvlmin > -1 ? reclvlmin : "?") + " - " + (reclvlmax > -1 ? reclvlmax : "?");
                        text.add(levelString);
                    }
                    // parents
                    if (lineNum < maxLines && !curPlace.getParents().isEmpty()) {
                        int parentsNum = curPlace.getParents().size();
                        String paStr = "Pa" + (parentsNum > 1 ? " (" + curPlace.getParents().size() + "): " : ": ");
                        boolean firstParent = true;
                        for (Place parent : curPlace.getParents()) {
                            paStr += (firstParent ? "" : ", ") + parent.getName();
                            firstParent = false;
                        }
                        text.add(paStr);
                    }
                    // children
                    if (lineNum < maxLines && !curPlace.getChildren().isEmpty()) {
                        int childrenNum = curPlace.getChildren().size();
                        String chStr = "Ch" + (childrenNum > 1 ? " (" + curPlace.getChildren().size() + "): " : ": ");
                        boolean firstChild = true;
                        for (Place child : curPlace.getChildren()) {
                            chStr += (firstChild ? "" : ", ") + child.getName();
                            firstChild = false;
                        }
                        text.add(chStr);
                    }
                    // flags
                    if (lineNum < maxLines) {
                        // place has comments
                        if (!curPlace.getComments().isEmpty())
                            flags += "Co";
                        if (!curPlace.getChildren().isEmpty())
                            flags += "Ch";
                        if (!curPlace.getParents().isEmpty())
                            flags += "Pa";
                        // other flags
                        for (Map.Entry<String, Boolean> flag : curPlace.getFlags().entrySet()) {
                            if (flag.getValue())
                                flags += flag.getKey().toUpperCase();
                            if (fm.stringWidth(flags) >= tileSize - 2 * tileBorderWidthScaled)
                                break;
                        }
                    }
                }
                // mark place group selection
                if (isSelected(curPlace) || (mudmap2.CopyPaste.isCut() && mudmap2.CopyPaste.isMarked(curPlace))) {
                    g.setColor(new Color(255, 255, 255, 128));
                    g.fillRect(placeXpx, placeYpx, tileSize, tileSize);
                }
                // draw path lines here
                boolean exitUp = false, exitDown = false, exitnstd = false;
                if (getShowPaths()) {
                    for (Path path : curPlace.getPaths()) {
                        Place otherPlace = path.getOtherPlace(curPlace);
                        Color colorPlace1 = layer.getWorld().getPathColor(path.getExitDirections()[0]);
                        Color colorPlace2 = layer.getWorld().getPathColor(path.getExitDirections()[1]);
                        if (path.getPlaces()[0] != curPlace) {
                            Color tmp = colorPlace1;
                            colorPlace1 = colorPlace2;
                            colorPlace2 = tmp;
                        }
                        // usually the main place (path.getPlaces()[0]) draws the path. If it isn't on screen, the other place draws it
                        if (Objects.equals(otherPlace.getLayer().getId(), layer.getId()) && (path.getPlaces()[0] == curPlace || !isOnScreen(otherPlace))) {
                            Pair<Integer, Integer> exitOffset = getExitOffset(path.getExit(curPlace));
                            Pair<Integer, Integer> exitOffsetOther = getExitOffset(path.getExit(otherPlace));
                            boolean drawCurves = getPathsCurved();
                            // exit positions on the map
                            final double exit1x = placeXpx + exitOffset.first;
                            final double exit1y = placeYpx + exitOffset.second;
                            final double exit2x = placeXpx + (otherPlace.getX() - curPlace.getX()) * tileSize + exitOffsetOther.first;
                            final double exit2y = placeYpx - (otherPlace.getY() - curPlace.getY()) * tileSize + exitOffsetOther.second;
                            if (colorPlace1.equals(colorPlace2)) {
                                // same color
                                ((Graphics2D) graphicPath).setPaint(colorPlace1);
                            } else {
                                // draw gradient
                                GradientPaint gp = new GradientPaint((float) exit1x, (float) exit1y, colorPlace1, (float) exit2x, (float) exit2y, colorPlace2);
                                ((Graphics2D) graphicPath).setPaint(gp);
                            }
                            if (drawCurves) {
                                Pair<Double, Double> normal1 = getExitNormal(path.getExit(curPlace));
                                Pair<Double, Double> normal2 = getExitNormal(path.getExit(otherPlace));
                                double dx = exit2x - exit1x;
                                double dy = exit2y - exit1y;
                                if (drawCurves = Math.sqrt(dx * dx + dy * dy) >= 1.5 * tileSize) {
                                    CubicCurve2D c = new CubicCurve2D.Double();
                                    // point 1
                                    c.setCurve(exit1x, exit1y, // point 2
                                    exit1x + normal1.first * tileSize, exit1y - normal1.second * tileSize, // point 3
                                    exit2x + normal2.first * tileSize, exit2y - normal2.second * tileSize, // point 4
                                    exit2x, exit2y);
                                    ((Graphics2D) graphicPath).draw(c);
                                }
                            }
                            if (!drawCurves) {
                                graphicPath.drawLine((int) exit1x, (int) exit1y, (int) exit2x, (int) exit2y);
                            }
                        }
                        // draw exit dots, if tiles are larger than 20
                        if (tileSize >= 20) {
                            g.setColor(colorPlace1);
                            String exit = path.getExit(curPlace);
                            switch(exit) {
                                case "u":
                                    exitUp = true;
                                    break;
                                case "d":
                                    exitDown = true;
                                    break;
                                default:
                                    Pair<Integer, Integer> exitOffset = getExitOffset(exit);
                                    if (exitOffset.first != tileSize / 2 || exitOffset.second != tileSize / 2) {
                                        int exitCircleRadius2 = getExitCircleRadius();
                                        g.fillOval(placeXpx + exitOffset.first - exitCircleRadius2, placeYpx + exitOffset.second - exitCircleRadius2, 2 * exitCircleRadius2, 2 * exitCircleRadius2);
                                    } else {
                                        // non-standard exit
                                        exitnstd = true;
                                    }
                                    break;
                            }
                        }
                    }
                }
                // draw exits
                if (tileSize >= 20 && (exitUp || exitDown) && drawText && lineNum <= maxLines) {
                    // have some arrows: ⬆⬇ ↑↓
                    exits = "" + (exitnstd ? "+" : "") + (exitUp ? "↑" : "") + (exitDown ? "↓" : "");
                }
                g.setColor(Color.BLACK);
                final int border = (int) (tileBorderWidthScaled + getRiskLevelStrokeWidth());
                drawText(g, placeXpx + border, placeYpx + border, tileSize - 2 * border, tileSize - 2 * border, text, flags, exits);
            }
            // TODO: extract from parent loop
            if (copiedPlaceLocations != null) {
                boolean locationFound = false;
                for (Pair<Integer, Integer> location : copiedPlaceLocations) {
                    if (location.first == placeX - placeSelectedX && location.second == placeY - placeSelectedY) {
                        locationFound = true;
                        break;
                    }
                }
                if (locationFound) {
                    // alternative: getScreenPosX();
                    int placeXpx = (int) ((tileX + remint(screenCenterX) - remint(curPos.getX())) * tileSize);
                    int placeYpx = (int) ((tileY + remint(screenCenterY) + remint(curPos.getY())) * tileSize);
                    drawCursor(g, Color.BLUE, placeXpx, placeYpx, selectionStrokeWidth);
                }
            }
            // draw cursor / place selection
            if (placeSelectionEnabled && placeX == placeSelectedX && placeY == placeSelectedY) {
                // alternative: getScreenPosX();
                int placeXpx = (int) ((tileX + remint(screenCenterX) - remint(curPos.getX())) * tileSize);
                int placeYpx = (int) ((tileY + remint(screenCenterY) + remint(curPos.getY())) * tileSize);
                drawCursor(g, TILE_SELECTION_COLOR, placeXpx, placeYpx, selectionStrokeWidth);
            }
        }
    }
    // mask out tile positions on graphicPath
    ((Graphics2D) graphicPath).setBackground(new Color(0, 0, 0, 0));
    int clearTileSize = tileSize - 2 * tileBorderWidthScaled;
    for (Pair<Integer, Integer> p : tilePositions) // graphicPath.clearRect(p.first, p.second, p.first + tileSize, p.second + tileSize);
    graphicPath.clearRect(p.first + tileBorderWidthScaled, p.second + tileBorderWidthScaled, clearTileSize, clearTileSize);
    // draw graphicPath to g
    if (getShowPaths())
        g.drawImage(imagePath, 0, 0, null);
    graphicPath.dispose();
}
Also used : BasicStroke(java.awt.BasicStroke) ArrayList(java.util.ArrayList) GradientPaint(java.awt.GradientPaint) BufferedImage(java.awt.image.BufferedImage) FontMetrics(java.awt.FontMetrics) CubicCurve2D(java.awt.geom.CubicCurve2D) Pair(mudmap2.utils.Pair) Path(mudmap2.backend.Path) Color(java.awt.Color) GradientPaint(java.awt.GradientPaint) LinkedList(java.util.LinkedList) Graphics2D(java.awt.Graphics2D) Graphics(java.awt.Graphics) HashMap(java.util.HashMap) Map(java.util.Map) Place(mudmap2.backend.Place)

Example 5 with Pair

use of io.fabric8.utils.Pair in project fabric8 by fabric8io.

the class YamlTest method testParseYaml.

@Test
public void testParseYaml() throws Exception {
    String basedir = System.getProperty("basedir", ".");
    File file = new File(basedir, "src/test/resources/fabric8.yml");
    assertThat(file).exists();
    ProjectConfig config = ProjectConfigs.parseProjectConfig(file);
    System.out.println("Parsed: " + config);
    assertThat(config.getChatRoom()).isEqualTo("myroom");
    assertThat(config.getIssueProjectName()).isEqualTo("foo");
    assertThat(config.getPipeline()).isEqualTo("maven/CanaryReleaseThenStage.groovy");
    LinkedHashMap<String, String> environments = config.getEnvironments();
    // lets assert that things are in the correct order...
    List<Pair<String, String>> expectedEnvironents = Arrays.asList(new Pair<String, String>("Testing", "gogsadmin-james4-testing"), new Pair<String, String>("Staging", "gogsadmin-james4-staging"), new Pair<String, String>("Production", "gogsadmin-james4-prod"));
    int idx = 0;
    Set<Map.Entry<String, String>> entries = environments.entrySet();
    for (Map.Entry<String, String> entry : entries) {
        String key = entry.getKey();
        String value = entry.getValue();
        System.out.println("Found environment " + key + " = " + value);
        Pair<String, String> actual = new Pair<>(key, value);
        assertTrue("Too many entries - found unexpected value: " + actual, expectedEnvironents.size() > idx);
        Pair<String, String> expected = expectedEnvironents.get(idx++);
        assertEquals("environment " + idx, expected, actual);
    }
}
Also used : File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Pair(io.fabric8.utils.Pair) Test(org.junit.Test)

Aggregations

Pair (mudmap2.utils.Pair)7 Map (java.util.Map)5 Place (mudmap2.backend.Place)4 File (java.io.File)3 HashMap (java.util.HashMap)3 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)2 Volume (io.fabric8.kubernetes.api.model.Volume)2 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)2 GradientPaint (java.awt.GradientPaint)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Test (org.junit.Test)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Deployment (com.liveperson.ephemerals.deploy.Deployment)1 com.liveperson.ephemerals.deploy.probe (com.liveperson.ephemerals.deploy.probe)1 ContainerizedDeploymentUnit (com.liveperson.ephemerals.deploy.unit.ContainerizedDeploymentUnit)1 com.liveperson.ephemerals.deploy.volume (com.liveperson.ephemerals.deploy.volume)1 DEPLOYMENT_LABEL_KEY (com.liveperson.ephemerals.provider.kubernetes.KubernetesDeploymentHandler.DEPLOYMENT_LABEL_KEY)1 Names (com.netflix.frigga.Names)1